Commit | Line | Data |
68ccb5e5 |
1 | package Catalyst::Helper; |
068587bd |
2 | #use Moose; |
68ccb5e5 |
3 | use Config; |
4 | use File::Spec; |
5 | use File::Path; |
68ccb5e5 |
6 | use FindBin; |
2415f774 |
7 | use IO::File; |
8 | use POSIX 'strftime'; |
68ccb5e5 |
9 | use Template; |
9ffb6b83 |
10 | use Catalyst::Devel; |
68ccb5e5 |
11 | use Catalyst::Utils; |
12 | use Catalyst::Exception; |
afd739f1 |
13 | use Path::Class qw/dir file/; |
14 | use File::ShareDir qw/dist_dir/; |
068587bd |
15 | #use namespace::autoclean; |
68ccb5e5 |
16 | |
17 | my %cache; |
18 | |
19 | =head1 NAME |
20 | |
21 | Catalyst::Helper - Bootstrap a Catalyst application |
22 | |
23 | =head1 SYNOPSIS |
24 | |
fab70e0a |
25 | catalyst.pl <myappname> |
68ccb5e5 |
26 | |
27 | =cut |
28 | |
afd739f1 |
29 | sub get_sharedir_file { |
30 | my ($self, @filename) = @_; |
76b106bc |
31 | my $dist_dir; |
d7ebca0f |
32 | if (-d "inc/.author" && -f "lib/Catalyst/Helper.pm" |
33 | ) { # Can't use sharedir if we're in a checkout |
34 | # this feels horrible, better ideas? |
76b106bc |
35 | $dist_dir = 'share'; |
36 | } |
37 | else { |
38 | $dist_dir = dist_dir('Catalyst-Devel'); |
39 | } |
40 | my $file = file( $dist_dir, @filename); |
f8d3d4e0 |
41 | Carp::confess("Cannot find $file") unless -r $file; |
afd739f1 |
42 | my $contents = $file->slurp; |
43 | return $contents; |
44 | } |
45 | |
faae88e5 |
46 | # Do not touch this method, *EVER*, it is needed for back compat. |
68ccb5e5 |
47 | sub get_file { |
03082a71 |
48 | my ( $self, $class, $file ) = @_; |
49 | unless ( $cache{$class} ) { |
50 | local $/; |
51 | $cache{$class} = eval "package $class; <DATA>"; |
52 | } |
53 | my $data = $cache{$class}; |
0acedf59 |
54 | Carp::confess("Could not get data from __DATA__ segment for $class") |
55 | unless $data; |
03082a71 |
56 | my @files = split /^__(.+)__\r?\n/m, $data; |
57 | shift @files; |
58 | while (@files) { |
59 | my ( $name, $content ) = splice @files, 0, 2; |
60 | return $content if $name eq $file; |
61 | } |
62 | return 0; |
68ccb5e5 |
63 | } |
64 | |
03082a71 |
65 | |
68ccb5e5 |
66 | sub mk_app { |
67 | my ( $self, $name ) = @_; |
68 | |
69 | # Needs to be here for PAR |
70 | require Catalyst; |
71 | |
555cab18 |
72 | if ( $name =~ /[^\w:]/ || $name =~ /^\d/ || $name =~ /\b:\b|:{3,}/) { |
68ccb5e5 |
73 | warn "Error: Invalid application name.\n"; |
74 | return 0; |
75 | } |
902763f2 |
76 | $self->{name } = $name; |
77 | $self->{dir } = $name; |
78 | $self->{dir } =~ s/\:\:/-/g; |
068587bd |
79 | $self->{script } = dir( $self->{dir}, 'script' ); |
902763f2 |
80 | $self->{appprefix } = Catalyst::Utils::appprefix($name); |
e9345225 |
81 | $self->{appenv } = Catalyst::Utils::class2env($name); |
675fef06 |
82 | $self->{startperl } = -r '/usr/bin/env' |
83 | ? '#!/usr/bin/env perl' |
9bc8b354 |
84 | : "#!$Config{perlpath} -w"; |
9ffb6b83 |
85 | $self->{scriptgen } = $Catalyst::Devel::CATALYST_SCRIPT_GEN || 4; |
902763f2 |
86 | $self->{catalyst_version} = $Catalyst::VERSION; |
87 | $self->{author } = $self->{author} = $ENV{'AUTHOR'} |
68ccb5e5 |
88 | || eval { @{ [ getpwuid($<) ] }[6] } |
89 | || 'Catalyst developer'; |
90 | |
91 | my $gen_scripts = ( $self->{makefile} ) ? 0 : 1; |
92 | my $gen_makefile = ( $self->{scripts} ) ? 0 : 1; |
93 | my $gen_app = ( $self->{scripts} || $self->{makefile} ) ? 0 : 1; |
94 | |
95 | if ($gen_app) { |
068587bd |
96 | |
97 | |
68ccb5e5 |
98 | $self->_mk_dirs; |
99 | $self->_mk_config; |
100 | $self->_mk_appclass; |
101 | $self->_mk_rootclass; |
102 | $self->_mk_readme; |
103 | $self->_mk_changes; |
104 | $self->_mk_apptest; |
105 | $self->_mk_images; |
106 | $self->_mk_favicon; |
107 | } |
108 | if ($gen_makefile) { |
109 | $self->_mk_makefile; |
110 | } |
111 | if ($gen_scripts) { |
112 | $self->_mk_cgi; |
113 | $self->_mk_fastcgi; |
114 | $self->_mk_server; |
23f9f145 |
115 | # probably want to only do this if a DBIC schema is specified, or move it |
116 | # to C::H::Model::DBIC::Schema |
117 | # $self->_mk_dbic_deploy; |
68ccb5e5 |
118 | $self->_mk_test; |
119 | $self->_mk_create; |
45d74601 |
120 | $self->_mk_information; |
68ccb5e5 |
121 | } |
122 | return $self->{dir}; |
123 | } |
124 | |
23f9f145 |
125 | |
126 | ## not much of this can really be changed, mk_compclass must be left for |
127 | ## backcompat |
68ccb5e5 |
128 | sub mk_component { |
129 | my $self = shift; |
130 | my $app = shift; |
131 | $self->{app} = $app; |
132 | $self->{author} = $self->{author} = $ENV{'AUTHOR'} |
133 | || eval { @{ [ getpwuid($<) ] }[6] } |
134 | || 'A clever guy'; |
068587bd |
135 | $self->{base} ||= dir( $FindBin::Bin, '..' ); |
68ccb5e5 |
136 | unless ( $_[0] =~ /^(?:model|view|controller)$/i ) { |
137 | my $helper = shift; |
138 | my @args = @_; |
139 | my $class = "Catalyst::Helper::$helper"; |
140 | eval "require $class"; |
141 | |
142 | if ($@) { |
143 | Catalyst::Exception->throw( |
144 | message => qq/Couldn't load helper "$class", "$@"/ ); |
145 | } |
146 | |
147 | if ( $class->can('mk_stuff') ) { |
148 | return 1 unless $class->mk_stuff( $self, @args ); |
149 | } |
150 | } |
151 | else { |
152 | my $type = shift; |
153 | my $name = shift || "Missing name for model/view/controller"; |
154 | my $helper = shift; |
155 | my @args = @_; |
fab70e0a |
156 | return 0 if $name =~ /[^\w\:]/; |
68ccb5e5 |
157 | $type = lc $type; |
158 | $self->{long_type} = ucfirst $type; |
159 | $type = 'M' if $type =~ /model/i; |
160 | $type = 'V' if $type =~ /view/i; |
161 | $type = 'C' if $type =~ /controller/i; |
068587bd |
162 | my $appdir = dir( split /\:\:/, $app ); |
68ccb5e5 |
163 | my $test_path = |
068587bd |
164 | dir( $self->{base}, 'lib', $appdir, 'C' ); |
68ccb5e5 |
165 | $type = $self->{long_type} unless -d $test_path; |
166 | $self->{type} = $type; |
167 | $self->{name} = $name; |
168 | $self->{class} = "$app\::$type\::$name"; |
169 | |
170 | # Class |
171 | my $path = |
068587bd |
172 | dir( $self->{base}, 'lib', $appdir, $type ); |
68ccb5e5 |
173 | my $file = $name; |
174 | if ( $name =~ /\:/ ) { |
175 | my @path = split /\:\:/, $name; |
176 | $file = pop @path; |
068587bd |
177 | $path = dir( $path, @path ); |
68ccb5e5 |
178 | } |
179 | $self->mk_dir($path); |
068587bd |
180 | $file = file( $path, "$file.pm" ); |
68ccb5e5 |
181 | $self->{file} = $file; |
182 | |
183 | # Test |
068587bd |
184 | $self->{test_dir} = dir( $self->{base}, 't' ); |
68ccb5e5 |
185 | $self->{test} = $self->next_test; |
186 | |
187 | # Helper |
188 | if ($helper) { |
189 | my $comp = $self->{long_type}; |
190 | my $class = "Catalyst::Helper::$comp\::$helper"; |
191 | eval "require $class"; |
192 | |
193 | if ($@) { |
194 | Catalyst::Exception->throw( |
195 | message => qq/Couldn't load helper "$class", "$@"/ ); |
196 | } |
197 | |
23f9f145 |
198 | ## must be left for back compat! ################################### |
68ccb5e5 |
199 | if ( $class->can('mk_compclass') ) { |
200 | return 1 unless $class->mk_compclass( $self, @args ); |
201 | } |
202 | else { return 1 unless $self->_mk_compclass } |
203 | |
204 | if ( $class->can('mk_comptest') ) { |
205 | $class->mk_comptest( $self, @args ); |
206 | } |
207 | else { $self->_mk_comptest } |
23f9f145 |
208 | #################################################################### |
68ccb5e5 |
209 | } |
210 | |
211 | # Fallback |
212 | else { |
213 | return 1 unless $self->_mk_compclass; |
214 | $self->_mk_comptest; |
215 | } |
216 | } |
217 | return 1; |
218 | } |
219 | |
68ccb5e5 |
220 | sub mk_dir { |
221 | my ( $self, $dir ) = @_; |
222 | if ( -d $dir ) { |
223 | print qq/ exists "$dir"\n/; |
224 | return 0; |
225 | } |
226 | if ( mkpath [$dir] ) { |
227 | print qq/created "$dir"\n/; |
228 | return 1; |
229 | } |
230 | |
231 | Catalyst::Exception->throw( message => qq/Couldn't create "$dir", "$!"/ ); |
232 | } |
233 | |
68ccb5e5 |
234 | sub mk_file { |
235 | my ( $self, $file, $content ) = @_; |
06f62452 |
236 | if ( -e $file && -s _ ) { |
68ccb5e5 |
237 | print qq/ exists "$file"\n/; |
238 | return 0 |
239 | unless ( $self->{'.newfiles'} |
240 | || $self->{scripts} |
241 | || $self->{makefile} ); |
242 | if ( $self->{'.newfiles'} ) { |
243 | if ( my $f = IO::File->new("< $file") ) { |
244 | my $oldcontent = join( '', (<$f>) ); |
245 | return 0 if $content eq $oldcontent; |
246 | } |
247 | $file .= '.new'; |
248 | } |
249 | } |
620dd287 |
250 | |
68ccb5e5 |
251 | if ( my $f = IO::File->new("> $file") ) { |
252 | binmode $f; |
253 | print $f $content; |
254 | print qq/created "$file"\n/; |
255 | return 1; |
256 | } |
257 | |
258 | Catalyst::Exception->throw( message => qq/Couldn't create "$file", "$!"/ ); |
259 | } |
260 | |
68ccb5e5 |
261 | sub next_test { |
262 | my ( $self, $tname ) = @_; |
263 | if ($tname) { $tname = "$tname.t" } |
264 | else { |
265 | my $name = $self->{name}; |
266 | my $prefix = $name; |
267 | $prefix =~ s/::/-/g; |
268 | $prefix = $prefix; |
269 | $tname = $prefix . '.t'; |
270 | $self->{prefix} = $prefix; |
271 | $prefix = lc $prefix; |
272 | $prefix =~ s/-/\//g; |
273 | $self->{uri} = "/$prefix"; |
274 | } |
275 | my $dir = $self->{test_dir}; |
276 | my $type = lc $self->{type}; |
277 | $self->mk_dir($dir); |
068587bd |
278 | return file( $dir, "$type\_$tname" ); |
68ccb5e5 |
279 | } |
280 | |
faae88e5 |
281 | # Do not touch this method, *EVER*, it is needed for back compat. |
7025ed89 |
282 | ## addendum: we had to split this method so we could have backwards |
19fecc42 |
283 | ## compatability. otherwise, we'd have no way to pass stuff from __DATA__ |
faae88e5 |
284 | |
68ccb5e5 |
285 | sub render_file { |
286 | my ( $self, $file, $path, $vars ) = @_; |
7025ed89 |
287 | my $template = $self->get_file( ( caller(0) )[0], $file ); |
06f62452 |
288 | $self->render_file_contents($template, $path, $vars); |
7025ed89 |
289 | } |
290 | |
291 | sub render_sharedir_file { |
292 | my ( $self, $file, $path, $vars ) = @_; |
293 | my $template = $self->get_sharedir_file( $file ); |
f8d3d4e0 |
294 | die("Cannot get template from $file for $self\n") unless $template; |
e97273a4 |
295 | $self->render_file_contents($template, $path, $vars); |
7025ed89 |
296 | } |
297 | |
298 | sub render_file_contents { |
299 | my ( $self, $template, $path, $vars ) = @_; |
68ccb5e5 |
300 | $vars ||= {}; |
301 | my $t = Template->new; |
68ccb5e5 |
302 | return 0 unless $template; |
303 | my $output; |
304 | $t->process( \$template, { %{$self}, %$vars }, \$output ) |
305 | || Catalyst::Exception->throw( |
7025ed89 |
306 | message => qq/Couldn't process "$template", / . $t->error() ); |
68ccb5e5 |
307 | $self->mk_file( $path, $output ); |
308 | } |
309 | |
45d74601 |
310 | sub _mk_information { |
311 | my $self = shift; |
312 | print qq/Change to application directory and Run "perl Makefile.PL" to make sure your install is complete\n/; |
313 | } |
314 | |
68ccb5e5 |
315 | sub _mk_dirs { |
316 | my $self = shift; |
317 | $self->mk_dir( $self->{dir} ); |
318 | $self->mk_dir( $self->{script} ); |
068587bd |
319 | $self->{lib} = dir( $self->{dir}, 'lib' ); |
68ccb5e5 |
320 | $self->mk_dir( $self->{lib} ); |
068587bd |
321 | $self->{root} = dir( $self->{dir}, 'root' ); |
68ccb5e5 |
322 | $self->mk_dir( $self->{root} ); |
068587bd |
323 | $self->{static} = dir( $self->{root}, 'static' ); |
68ccb5e5 |
324 | $self->mk_dir( $self->{static} ); |
068587bd |
325 | $self->{images} = dir( $self->{static}, 'images' ); |
68ccb5e5 |
326 | $self->mk_dir( $self->{images} ); |
068587bd |
327 | $self->{t} = dir( $self->{dir}, 't' ); |
68ccb5e5 |
328 | $self->mk_dir( $self->{t} ); |
329 | |
068587bd |
330 | $self->{class} = dir( split( /\:\:/, $self->{name} ) ); |
331 | $self->{mod} = dir( $self->{lib}, $self->{class} ); |
68ccb5e5 |
332 | $self->mk_dir( $self->{mod} ); |
333 | |
334 | if ( $self->{short} ) { |
068587bd |
335 | $self->{m} = dir( $self->{mod}, 'M' ); |
68ccb5e5 |
336 | $self->mk_dir( $self->{m} ); |
068587bd |
337 | $self->{v} = dir( $self->{mod}, 'V' ); |
68ccb5e5 |
338 | $self->mk_dir( $self->{v} ); |
068587bd |
339 | $self->{c} = dir( $self->{mod}, 'C' ); |
68ccb5e5 |
340 | $self->mk_dir( $self->{c} ); |
341 | } |
342 | else { |
068587bd |
343 | $self->{m} = dir( $self->{mod}, 'Model' ); |
68ccb5e5 |
344 | $self->mk_dir( $self->{m} ); |
068587bd |
345 | $self->{v} = dir( $self->{mod}, 'View' ); |
68ccb5e5 |
346 | $self->mk_dir( $self->{v} ); |
068587bd |
347 | $self->{c} = dir( $self->{mod}, 'Controller' ); |
68ccb5e5 |
348 | $self->mk_dir( $self->{c} ); |
349 | } |
350 | my $name = $self->{name}; |
351 | $self->{rootname} = |
352 | $self->{short} ? "$name\::C::Root" : "$name\::Controller::Root"; |
068587bd |
353 | $self->{base} = dir( $self->{dir} )->absolute; |
68ccb5e5 |
354 | } |
355 | |
356 | sub _mk_appclass { |
357 | my $self = shift; |
358 | my $mod = $self->{mod}; |
068587bd |
359 | $self->render_sharedir_file( file('lib', 'MyApp.pm.tt'), "$mod.pm" ); |
68ccb5e5 |
360 | } |
361 | |
362 | sub _mk_rootclass { |
363 | my $self = shift; |
068587bd |
364 | $self->render_sharedir_file( file('lib', 'MyApp', 'Controller', 'Root.pm.tt'), |
365 | file( $self->{c}, "Root.pm" ) ); |
68ccb5e5 |
366 | } |
367 | |
368 | sub _mk_makefile { |
369 | my $self = shift; |
068587bd |
370 | $self->{path} = dir( 'lib', split( '::', $self->{name} ) ); |
68ccb5e5 |
371 | $self->{path} .= '.pm'; |
372 | my $dir = $self->{dir}; |
068587bd |
373 | $self->render_sharedir_file( 'Makefile.PL.tt', file($dir, "Makefile.PL") ); |
68ccb5e5 |
374 | |
375 | if ( $self->{makefile} ) { |
376 | |
377 | # deprecate the old Build.PL file when regenerating Makefile.PL |
378 | $self->_deprecate_file( |
068587bd |
379 | file( $self->{dir}, 'Build.PL' ) ); |
68ccb5e5 |
380 | } |
381 | } |
382 | |
383 | sub _mk_config { |
384 | my $self = shift; |
385 | my $dir = $self->{dir}; |
386 | my $appprefix = $self->{appprefix}; |
d5ff5c0f |
387 | $self->render_sharedir_file( 'myapp.conf.tt', |
068587bd |
388 | file( $dir, "$appprefix.conf" ) ); |
68ccb5e5 |
389 | } |
390 | |
391 | sub _mk_readme { |
392 | my $self = shift; |
393 | my $dir = $self->{dir}; |
068587bd |
394 | $self->render_sharedir_file( 'README.tt', file($dir, "README") ); |
68ccb5e5 |
395 | } |
396 | |
397 | sub _mk_changes { |
398 | my $self = shift; |
399 | my $dir = $self->{dir}; |
5b1ec88b |
400 | my $time = strftime('%Y-%m-%d %H:%M:%S', localtime time); |
068587bd |
401 | $self->render_sharedir_file( 'Changes.tt', file($dir, "Changes", { time => $time } ); |
68ccb5e5 |
402 | } |
403 | |
404 | sub _mk_apptest { |
405 | my $self = shift; |
406 | my $t = $self->{t}; |
068587bd |
407 | $self->render_sharedir_file( file('t', '01app.t.tt'), file($t, "01app.t") ); |
408 | $self->render_sharedir_file( file('t', '02pod.t.tt'), file($t, "02pod.t") ); |
409 | $self->render_sharedir_file( file('t', '03podcoverage.t.tt'), file($t, "03podcoverage.t") ); |
68ccb5e5 |
410 | } |
411 | |
412 | sub _mk_cgi { |
413 | my $self = shift; |
414 | my $script = $self->{script}; |
415 | my $appprefix = $self->{appprefix}; |
068587bd |
416 | $self->render_sharedir_file( file('script', 'myapp_cgi.pl.tt'), file($script,"$appprefix\_cgi.pl") ); |
417 | chmod 0700, file($script,"$appprefix\_cgi.pl"); |
68ccb5e5 |
418 | } |
419 | |
420 | sub _mk_fastcgi { |
421 | my $self = shift; |
422 | my $script = $self->{script}; |
423 | my $appprefix = $self->{appprefix}; |
068587bd |
424 | $self->render_sharedir_file( file('script', 'myapp_fastcgi.pl.tt'), file($script, "$appprefix\_fastcgi.pl") ); |
425 | chmod 0700, file($script, "$appprefix\_fastcgi.pl"); |
68ccb5e5 |
426 | } |
427 | |
428 | sub _mk_server { |
429 | my $self = shift; |
430 | my $script = $self->{script}; |
431 | my $appprefix = $self->{appprefix}; |
068587bd |
432 | $self->render_sharedir_file( file('script', 'myapp_server.pl.tt'), file($script, "$appprefix\_server.pl") ); |
433 | chmod 0700, file($script, "$appprefix\_server.pl"); |
68ccb5e5 |
434 | } |
435 | |
436 | sub _mk_test { |
437 | my $self = shift; |
438 | my $script = $self->{script}; |
439 | my $appprefix = $self->{appprefix}; |
068587bd |
440 | $self->render_sharedir_file( file('script', 'myapp_test.pl.tt'), file($script, "$appprefix\_test.pl") ); |
441 | chmod 0700, file($script, "$appprefix\_test.pl"); |
68ccb5e5 |
442 | } |
443 | |
444 | sub _mk_create { |
445 | my $self = shift; |
446 | my $script = $self->{script}; |
447 | my $appprefix = $self->{appprefix}; |
068587bd |
448 | $self->render_sharedir_file( file('script', 'myapp_create.pl.tt'), file($script, "$appprefix\_create.pl") ); |
449 | chmod 0700, file($script, "$appprefix\_create.pl"); |
68ccb5e5 |
450 | } |
451 | |
452 | sub _mk_compclass { |
453 | my $self = shift; |
454 | my $file = $self->{file}; |
068587bd |
455 | return $self->render_sharedir_file( file('lib', 'Helper', 'compclass.pm.tt'), $file ); |
68ccb5e5 |
456 | } |
457 | |
458 | sub _mk_comptest { |
459 | my $self = shift; |
460 | my $test = $self->{test}; |
068587bd |
461 | $self->render_sharedir_file( file('t', 'comptest.tt'), $test ); ## wtf do i rename this to? |
68ccb5e5 |
462 | } |
463 | |
464 | sub _mk_images { |
465 | my $self = shift; |
466 | my $images = $self->{images}; |
467 | my @images = |
468 | qw/catalyst_logo btn_120x50_built btn_120x50_built_shadow |
469 | btn_120x50_powered btn_120x50_powered_shadow btn_88x31_built |
470 | btn_88x31_built_shadow btn_88x31_powered btn_88x31_powered_shadow/; |
471 | for my $name (@images) { |
3f2f19ec |
472 | my $image = $self->get_sharedir_file("root", "static", "images", "$name.png.bin"); |
068587bd |
473 | $self->mk_file( file( $images, "$name.png" ), $image ); |
68ccb5e5 |
474 | } |
475 | } |
476 | |
477 | sub _mk_favicon { |
478 | my $self = shift; |
479 | my $root = $self->{root}; |
f023d4a1 |
480 | my $favicon = $self->get_sharedir_file( 'root', 'favicon.ico.bin' ); |
068587bd |
481 | my $dest = dir( $root, "favicon.ico" ); |
afd739f1 |
482 | $self->mk_file( $dest, $favicon ); |
68ccb5e5 |
483 | |
484 | } |
485 | |
f5159e3e |
486 | sub _mk_dbic_deploy { |
487 | my $self = shift; |
488 | my $script = $self->{script}; |
489 | my $appprefix = $self->{appprefix}; |
068587bd |
490 | $self->render_sharedir_file( file('script', 'myapp_deploy_schema.pl.tt'), file($script, "$appprefix\_deploy_schema.pl") ); |
491 | chmod 0700, file($script, "$appprefix\_deploy_schema.pl"); |
f5159e3e |
492 | } |
493 | |
68ccb5e5 |
494 | sub _deprecate_file { |
495 | my ( $self, $file ) = @_; |
496 | if ( -e $file ) { |
497 | my $oldcontent; |
498 | if ( my $f = IO::File->new("< $file") ) { |
499 | $oldcontent = join( '', (<$f>) ); |
500 | } |
501 | my $newfile = $file . '.deprecated'; |
502 | if ( my $f = IO::File->new("> $newfile") ) { |
503 | binmode $f; |
504 | print $f $oldcontent; |
505 | print qq/created "$newfile"\n/; |
506 | unlink $file; |
507 | print qq/removed "$file"\n/; |
508 | return 1; |
509 | } |
510 | Catalyst::Exception->throw( |
511 | message => qq/Couldn't create "$file", "$!"/ ); |
512 | } |
513 | } |
514 | |
fab70e0a |
515 | =head1 DESCRIPTION |
516 | |
517 | This module is used by B<catalyst.pl> to create a set of scripts for a |
518 | new catalyst application. The scripts each contain documentation and |
519 | will output help on how to use them if called incorrectly or in some |
520 | cases, with no arguments. |
521 | |
522 | It also provides some useful methods for a Helper module to call when |
523 | creating a component. See L</METHODS>. |
524 | |
525 | =head1 SCRIPTS |
526 | |
527 | =head2 _create.pl |
528 | |
529 | Used to create new components for a catalyst application at the |
530 | development stage. |
531 | |
532 | =head2 _server.pl |
533 | |
534 | The catalyst test server, starts an HTTPD which outputs debugging to |
535 | the terminal. |
536 | |
f5159e3e |
537 | =head2 _deploy_dbic.pl |
538 | |
539 | Deploy a L<DBIx::Class> schema to the database of your choice. |
540 | |
fab70e0a |
541 | =head2 _test.pl |
542 | |
543 | A script for running tests from the command-line. |
544 | |
545 | =head2 _cgi.pl |
546 | |
547 | Run your application as a CGI. |
548 | |
549 | =head2 _fastcgi.pl |
550 | |
551 | Run the application as a fastcgi app. Either by hand, or call this |
552 | from FastCgiServer in your http server config. |
553 | |
68ccb5e5 |
554 | =head1 HELPERS |
555 | |
fab70e0a |
556 | The L</_create.pl> script creates application components using Helper |
557 | modules. The Catalyst team provides a good number of Helper modules |
558 | for you to use. You can also add your own. |
559 | |
68ccb5e5 |
560 | Helpers are classes that provide two methods. |
561 | |
562 | * mk_compclass - creates the Component class |
563 | * mk_comptest - creates the Component test |
564 | |
fab70e0a |
565 | So when you call C<scripts/myapp_create.pl view MyView TT>, create |
566 | will try to execute Catalyst::Helper::View::TT->mk_compclass and |
68ccb5e5 |
567 | Catalyst::Helper::View::TT->mk_comptest. |
568 | |
c4c50c2d |
569 | See L<Catalyst::Helper::View::TT> and |
570 | L<Catalyst::Helper::Model::DBIC::Schema> for examples. |
68ccb5e5 |
571 | |
572 | All helper classes should be under one of the following namespaces. |
573 | |
574 | Catalyst::Helper::Model:: |
575 | Catalyst::Helper::View:: |
576 | Catalyst::Helper::Controller:: |
577 | |
675fef06 |
578 | =head2 COMMON HELPERS |
bc8d7994 |
579 | |
580 | =over |
581 | |
582 | =item * |
583 | |
584 | L<Catalyst::Helper::Model::DBIC::Schema> - DBIx::Class models |
585 | |
586 | =item * |
587 | |
588 | L<Catalyst::Helper::View::TT> - Template Toolkit view |
589 | |
590 | =item * |
591 | |
592 | L<Catalyst::Helper::Model::LDAP> |
593 | |
594 | =item * |
595 | |
596 | L<Catalyst::Helper::Model::Adaptor> - wrap any class into a Catalyst model |
597 | |
598 | =back |
599 | |
600 | =head3 NOTE |
601 | |
675fef06 |
602 | The helpers will read author name from /etc/passwd by default. + To override, please export the AUTHOR variable. |
bc8d7994 |
603 | |
604 | =head1 METHODS |
605 | |
fab70e0a |
606 | =head2 mk_compclass |
607 | |
608 | This method in your Helper module is called with C<$helper> |
609 | which is a L<Catalyst::Helper> object, and whichever other arguments |
610 | the user added to the command-line. You can use the $helper to call methods |
611 | described below. |
612 | |
613 | If the Helper module does not contain a C<mk_compclass> method, it |
614 | will fall back to calling L</render_file>, with an argument of |
615 | C<compclass>. |
616 | |
617 | =head2 mk_comptest |
618 | |
619 | This method in your Helper module is called with C<$helper> |
620 | which is a L<Catalyst::Helper> object, and whichever other arguments |
621 | the user added to the command-line. You can use the $helper to call methods |
622 | described below. |
623 | |
624 | If the Helper module does not contain a C<mk_compclass> method, it |
625 | will fall back to calling L</render_file>, with an argument of |
626 | C<comptest>. |
627 | |
628 | =head2 mk_stuff |
629 | |
630 | This method is called if the user does not supply any of the usual |
631 | component types C<view>, C<controller>, C<model>. It is passed the |
632 | C<$helper> object (an instance of L<Catalyst::Helper>), and any other |
633 | arguments the user typed. |
634 | |
635 | There is no fallback for this method. |
636 | |
bc8d7994 |
637 | =head1 INTERNAL METHODS |
fab70e0a |
638 | |
639 | These are the methods that the Helper classes can call on the |
640 | <$helper> object passed to them. |
641 | |
28eb1300 |
642 | =head2 render_file ($file, $path, $vars) |
fab70e0a |
643 | |
28eb1300 |
644 | Render and create a file from a template in DATA using Template |
645 | Toolkit. $file is the relevent chunk of the __DATA__ section, $path is |
646 | the path to the file and $vars is the hashref as expected by |
647 | L<Template Toolkit|Template>. |
fab70e0a |
648 | |
28eb1300 |
649 | =head2 get_file ($class, $file) |
fab70e0a |
650 | |
651 | Fetch file contents from the DATA section. This is used internally by |
28eb1300 |
652 | L</render_file>. $class is the name of the class to get the DATA |
653 | section from. __PACKAGE__ or ( caller(0) )[0] might be sensible |
654 | values for this. |
fab70e0a |
655 | |
656 | =head2 mk_app |
657 | |
658 | Create the main application skeleton. This is called by L<catalyst.pl>. |
659 | |
28eb1300 |
660 | =head2 mk_component ($app) |
fab70e0a |
661 | |
662 | This method is called by L<create.pl> to make new components |
663 | for your application. |
664 | |
28eb1300 |
665 | =head3 mk_dir ($path) |
fab70e0a |
666 | |
667 | Surprisingly, this function makes a directory. |
668 | |
28eb1300 |
669 | =head2 mk_file ($file, $content) |
fab70e0a |
670 | |
671 | Writes content to a file. Called by L</render_file>. |
672 | |
28eb1300 |
673 | =head2 next_test ($test_name) |
fab70e0a |
674 | |
675 | Calculates the name of the next numbered test file and returns it. |
28eb1300 |
676 | Don't give the number or the .t suffix for the test name. |
fab70e0a |
677 | |
c6dbb300 |
678 | =cut |
679 | |
680 | =head2 get_sharedir_file |
681 | |
682 | Method for getting a file out of share/ |
683 | |
684 | =cut |
685 | |
686 | =head2 render_file_contents |
687 | |
688 | Process a L<Template::Toolkit> template. |
689 | |
690 | =cut |
691 | |
692 | =head2 render_sharedir_file |
693 | |
694 | Render a template/image file from our share directory |
695 | |
696 | =cut |
697 | |
698 | |
68ccb5e5 |
699 | =head1 NOTE |
700 | |
701 | The helpers will read author name from /etc/passwd by default. |
702 | To override, please export the AUTHOR variable. |
703 | |
704 | =head1 SEE ALSO |
705 | |
706 | L<Catalyst::Manual>, L<Catalyst::Test>, L<Catalyst::Request>, |
707 | L<Catalyst::Response>, L<Catalyst> |
708 | |
f64c718c |
709 | =head1 AUTHORS |
68ccb5e5 |
710 | |
f64c718c |
711 | Catalyst Contributors, see Catalyst.pm |
68ccb5e5 |
712 | |
713 | =head1 LICENSE |
714 | |
7cd3b67e |
715 | This library is free software. You can redistribute it and/or modify |
68ccb5e5 |
716 | it under the same terms as Perl itself. |
717 | |
64d4433e |
718 | =begin pod_to_ignore |
719 | |
68ccb5e5 |
720 | =cut |
721 | |
722 | 1; |
68ccb5e5 |
723 | |