• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

lib/CatalystX/H03-May-2022-424313

t/H03-May-2022-42

Build.PLH A D26-Feb-2016301 134

ChangesH A D26-Feb-20161.3 KiB4431

LICENSEH A D26-Feb-201618 KiB379292

MANIFESTH A D26-Feb-2016121 1111

META.jsonH A D26-Feb-20162 KiB8180

META.ymlH A D26-Feb-20161.1 KiB4443

MakefileH A D26-Feb-201624 KiB832508

README.mdH A D26-Feb-20165.9 KiB227150

cpanfileH A D26-Feb-2016172 97

README.md

1# NAME
2
3CatalystX::AppBuilder - Build Your Application Instance Programatically
4
5# SYNOPSIS
6
7    # In MyApp.pm
8    my $builder = CatalystX::AppBuilder->new(
9        appname => 'MyApp',
10        plugins => [ ... ],
11    )
12    $builder->bootstrap();
13
14# DESCRIPTION
15
16WARNING: YMMV regarding this module.
17
18This module gives you a programatic interface to _configuring_ Catalyst
19applications.
20
21The main motivation to write this module is: to write reusable Catalyst
22appllications. For instance, if you build your MyApp::Base and you wanted to
23create a new application afterwards that is _mostly_ like MyApp::Base,
24but slightly tweaked. Perhaps you want to add or remove a plugin or two.
25Perhaps you want to tweak just a single parameter.
26
27Traditionally, your option then was to use catalyst.pl and create another
28scaffold, and copy/paste the necessary bits, and tweak what you need.
29
30After testing several approaches, it proved that the current Catalyst
31architecture (which is Moose based, but does not allow us to use Moose-ish
32initialization, since the Catalyst app instance does not materialize until
33dispatch time) did not allow the type of inheritance behavior we wanted, so
34we decided to create a builder module around Catalyst to overcome this.
35Therefore, if/when these obstacles (to us) are gone, this module may
36simply dissappear from CPAN. You've been warned.
37
38# HOW TO USE
39
40## DEFINING A CATALYST APP
41
42This module is NOT a "just-execute-this-command-and-you-get-catalyst-running"
43module. For the simple applications, please just follow what the Catalyst
44manual gives you.
45
46However, if you _really_ wanted to, you can define a simple Catalyst
47app like so:
48
49    # in MyApp.pm
50    use strict;
51    use CatalystX::AppBuilder;
52
53    my $builder = CatalystX::AppBuilder->new(
54        debug  => 1, # if you want
55        appname => "MyApp",
56        plugins => [ qw(
57            Authentication
58            Session
59            # and others...
60        ) ],
61        config  => { ... }
62    );
63
64    $builder->bootstrap();
65
66## DEFINING YOUR CatalystX::AppBuilder SUBCLASS
67
68The originally intended approach to using this module is to create a
69subclass of CatalystX::AppBuilder and configure it to your own needs,
70and then keep reusing it.
71
72To build your own MyApp::Builder, you just need to subclass it:
73
74    package MyApp::Builder;
75    use Moose;
76
77    extends 'CatalystX::AppBuilder';
78
79Then you will be able to give it defaults to the various configuration
80parameters:
81
82    override _build_config => sub {
83        my $config = super(); # Get what CatalystX::AppBuilder gives you
84        $config->{ SomeComponent } = { ... };
85        return $config;
86    };
87
88    override _build_plugins => sub {
89        my $plugins = super(); # Get what CatalystX::AppBuilder gives you
90
91        push @$plugins, qw(
92            Unicode
93            Authentication
94            Session
95            Session::Store::File
96            Session::State::Cookie
97        );
98
99        return $plugins;
100    };
101
102Then you can simply do this instead of giving parameters to
103CatalystX::AppBuilder every time:
104
105    # in MyApp.pm
106    use MyApp::Builder;
107    MyApp::Builder->new()->bootstrap();
108
109## EXTENDING A CATALYST APP USING CatalystX::AppBuilder
110
111Once you created your own MyApp::Builder, you can keep inheriting it to
112create custom Builders which in turn create more custom Catalyst applications:
113
114    package MyAnotherApp::Builder;
115    use Moose;
116
117    extends 'MyApp::Builder';
118
119    override _build_superclasses => sub {
120        return [ 'MyApp' ]
121    }
122
123    ... do your tweaking ...
124
125    # in MyAnotherApp.pm
126    use MyAnotherApp::Builder;
127
128    MyAnotherApp::Builder->new()->bootstrap();
129
130Voila, you just reused every inch of Catalyst app that you created via
131inheritance!
132
133## INCLUDING EVERY PATH FROM YOUR INHERITANCE HIERARCHY
134
135Components like Catalyst::View::TT, which in turn uses Template Toolkit
136inside, allows you to include multiple directories to look for the
137template files.
138
139This can be used to recycle the templates that you used in a base application.
140
141CatalystX::AppBuilder gives you a couple of tools to easily include
142paths that are associated with all of the Catalyst applications that are
143inherited. For example, if you have MyApp::Base and MyApp::Extended,
144and MyApp::Extended is built using MyApp::Extended::Builder, you can do
145something like this:
146
147    package MyApp::Extended::Builder;
148    use Moose;
149
150    extends 'CatalystX::AppBuilder';
151
152    override _build_superclasses => sub {
153        return [ 'MyApp::Base' ]
154    };
155
156    override _build_config => sub {
157        my $self = shift;
158        my $config = super();
159
160        $config->{'View::TT'}->{INCLUDE_PATH} =
161            [ $self->inherited_path_to('root') ];
162        # Above is equivalent to
163        #    [ MyApp::Extended->path_to('root'), MyApp::Base->path_to('root') ]
164    };
165
166So now you can refer to some template, and it will first look under the
167first app, then the base app, thus allowing you to reuse the templates.
168
169# ATTRIBUTES
170
171## appname
172
173The module name of the Catalyst application. Required.
174
175## appmeta
176
177The metaclass object of the Catalyst application. Users cannot set this.
178
179## debug
180
181Boolean flag to enable debug output in the application
182
183## version
184
185The version string to use (probably meaningless...)
186
187## superclasses
188
189The list of superclasses of the Catalyst application.
190
191## config
192
193The config hash to give to the Catalyst application.
194
195## plugins
196
197The list of plugins to give to the Catalyst application.
198
199# METHODS
200
201## bootstrap($runsetup)
202
203Bootstraps the Catalyst app.
204
205## inherited\_path\_to(@pathspec)
206
207Calls path\_to() on all Catalyst applications in the inheritance tree.
208
209## app\_path\_to(@pathspec);
210
211Calls path\_to() on the curent Catalyst application.
212
213# TODO
214
215Documentation. Samples. Tests.
216
217# AUTHOR
218
219Daisuke Maki `<daisuke@endeworks.jp>`
220
221# LICENSE
222
223This program is free software; you can redistribute it and/or modify it
224under the same terms as Perl itself.
225
226See http://www.perl.com/perl/misc/Artistic.html
227