Commit | Line | Data |
fc7ec1d9 |
1 | package Catalyst::Helper; |
2 | |
3 | use strict; |
4 | use base 'Class::Accessor::Fast'; |
f1d0b7ea |
5 | use Config; |
fc7ec1d9 |
6 | use File::Spec; |
7 | use File::Path; |
8 | use IO::File; |
9 | use FindBin; |
61cfdd57 |
10 | use Template; |
2a276acb |
11 | use Catalyst; |
a2f2cde9 |
12 | use Catalyst::Exception; |
61cfdd57 |
13 | |
14 | my %cache; |
fc7ec1d9 |
15 | |
16 | =head1 NAME |
17 | |
18 | Catalyst::Helper - Bootstrap a Catalyst application |
19 | |
20 | =head1 SYNOPSIS |
21 | |
22 | See L<Catalyst::Manual::Intro> |
23 | |
24 | =head1 DESCRIPTION |
25 | |
b160463f |
26 | Bootstrap a Catalyst application. Autogenerates scripts |
fc7ec1d9 |
27 | |
28 | =head2 METHODS |
29 | |
61cfdd57 |
30 | =head3 get_file |
31 | |
32 | Slurp file from DATA. |
33 | |
34 | =cut |
35 | |
36 | sub get_file { |
37 | my ( $self, $class, $file ) = @_; |
38 | unless ( $cache{$class} ) { |
39 | local $/; |
40 | $cache{$class} = eval "package $class; <DATA>"; |
41 | } |
42 | my $data = $cache{$class}; |
6a5c55b6 |
43 | my @files = split /^__(.+)__\r?\n/m, $data; |
61cfdd57 |
44 | shift @files; |
45 | while (@files) { |
46 | my ( $name, $content ) = splice @files, 0, 2; |
47 | return $content if $name eq $file; |
48 | } |
49 | return 0; |
50 | } |
51 | |
fc7ec1d9 |
52 | =head3 mk_app |
53 | |
b160463f |
54 | Create the main application skeleton. |
55 | |
fc7ec1d9 |
56 | =cut |
57 | |
58 | sub mk_app { |
59 | my ( $self, $name ) = @_; |
60 | return 0 if $name =~ /[^\w\:]/; |
61 | $self->{name} = $name; |
62 | $self->{dir} = $name; |
63 | $self->{dir} =~ s/\:\:/-/g; |
4f6748f1 |
64 | $self->{appprefix} = lc $self->{dir}; |
65 | $self->{appprefix} =~ s/-/_/g; |
61cfdd57 |
66 | $self->{startperl} = $Config{startperl}; |
7dcb4831 |
67 | $self->{scriptgen} = $Catalyst::CATALYST_SCRIPT_GEN || 4; |
4f6748f1 |
68 | $self->{author} = $self->{author} = $ENV{'AUTHOR'} |
28e68b83 |
69 | || eval { @{ [ getpwuid($<) ] }[6] } |
098e9288 |
70 | || 'Catalyst developer'; |
fc7ec1d9 |
71 | $self->_mk_dirs; |
72 | $self->_mk_appclass; |
4f6748f1 |
73 | $self->_mk_build; |
fc7ec1d9 |
74 | $self->_mk_makefile; |
91864987 |
75 | $self->_mk_readme; |
76 | $self->_mk_changes; |
fc7ec1d9 |
77 | $self->_mk_apptest; |
bc024080 |
78 | $self->_mk_cgi; |
28e68b83 |
79 | $self->_mk_fastcgi; |
fc7ec1d9 |
80 | $self->_mk_server; |
81 | $self->_mk_test; |
82 | $self->_mk_create; |
83 | return 1; |
84 | } |
85 | |
ad41e777 |
86 | =head3 mk_component |
87 | |
b160463f |
88 | This method is called by create.pl to make new components |
89 | for your application. |
90 | |
ad41e777 |
91 | =cut |
92 | |
93 | sub mk_component { |
b5524568 |
94 | my $self = shift; |
95 | my $app = shift; |
96 | $self->{app} = $app; |
4f6748f1 |
97 | $self->{author} = $self->{author} = $ENV{'AUTHOR'} |
28e68b83 |
98 | || eval { @{ [ getpwuid($<) ] }[6] } |
99 | || 'A clever guy'; |
b5524568 |
100 | $self->{base} = File::Spec->catdir( $FindBin::Bin, '..' ); |
f74f8f38 |
101 | unless ( $_[0] =~ /^(?:model|m|view|v|controller|c)$/i ) { |
b5524568 |
102 | my $helper = shift; |
103 | my @args = @_; |
104 | my $class = "Catalyst::Helper::$helper"; |
ad41e777 |
105 | eval "require $class"; |
fbcc39ad |
106 | |
107 | if ($@) { |
108 | Catalyst::Exception->throw( |
109 | message => qq/Couldn't load helper "$class", "$@"/ ); |
a2f2cde9 |
110 | } |
fbcc39ad |
111 | |
b5524568 |
112 | if ( $class->can('mk_stuff') ) { |
113 | return 1 unless $class->mk_stuff( $self, @args ); |
ad41e777 |
114 | } |
ad41e777 |
115 | } |
ad41e777 |
116 | else { |
b5524568 |
117 | my $type = shift; |
adfe7ead |
118 | my $name = shift || "Missing name for model/view/controller"; |
28e68b83 |
119 | my $helper = shift; |
b5524568 |
120 | my @args = @_; |
121 | return 0 if $name =~ /[^\w\:]/; |
122 | $type = 'M' if $type =~ /model|m/i; |
123 | $type = 'V' if $type =~ /view|v/i; |
124 | $type = 'C' if $type =~ /controller|c/i; |
125 | $self->{type} = $type; |
126 | $self->{name} = $name; |
127 | $self->{class} = "$app\::$type\::$name"; |
128 | |
129 | # Class |
130 | my $appdir = File::Spec->catdir( split /\:\:/, $app ); |
131 | my $path = |
132 | File::Spec->catdir( $FindBin::Bin, '..', 'lib', $appdir, $type ); |
133 | my $file = $name; |
134 | if ( $name =~ /\:/ ) { |
135 | my @path = split /\:\:/, $name; |
136 | $file = pop @path; |
137 | $path = File::Spec->catdir( $path, @path ); |
fd59198f |
138 | mkpath [$path]; |
b5524568 |
139 | } |
140 | $file = File::Spec->catfile( $path, "$file.pm" ); |
141 | $self->{file} = $file; |
142 | |
143 | # Test |
144 | $self->{test_dir} = File::Spec->catdir( $FindBin::Bin, '..', 't' ); |
145 | $self->{test} = $self->next_test; |
146 | |
147 | # Helper |
148 | if ($helper) { |
149 | my $comp = 'Model'; |
150 | $comp = 'View' if $type eq 'V'; |
151 | $comp = 'Controller' if $type eq 'C'; |
152 | my $class = "Catalyst::Helper::$comp\::$helper"; |
153 | eval "require $class"; |
fbcc39ad |
154 | |
155 | if ($@) { |
156 | Catalyst::Exception->throw( |
157 | message => qq/Couldn't load helper "$class", "$@"/ ); |
158 | } |
159 | |
b5524568 |
160 | if ( $class->can('mk_compclass') ) { |
161 | return 1 unless $class->mk_compclass( $self, @args ); |
162 | } |
163 | else { return 1 unless $self->_mk_compclass } |
164 | |
165 | if ( $class->can('mk_comptest') ) { |
166 | $class->mk_comptest( $self, @args ); |
167 | } |
168 | else { $self->_mk_comptest } |
169 | } |
170 | |
171 | # Fallback |
172 | else { |
173 | return 1 unless $self->_mk_compclass; |
174 | $self->_mk_comptest; |
175 | } |
ad41e777 |
176 | } |
177 | return 1; |
178 | } |
179 | |
180 | =head3 mk_dir |
181 | |
b160463f |
182 | Surprisingly, this function makes a directory. |
183 | |
ad41e777 |
184 | =cut |
185 | |
186 | sub mk_dir { |
187 | my ( $self, $dir ) = @_; |
188 | if ( -d $dir ) { |
189 | print qq/ exists "$dir"\n/; |
190 | return 0; |
191 | } |
d2ee9760 |
192 | if ( mkpath [$dir] ) { |
ad41e777 |
193 | print qq/created "$dir"\n/; |
194 | return 1; |
195 | } |
fbcc39ad |
196 | |
197 | Catalyst::Exception->throw( message => qq/Couldn't create "$dir", "$!"/ ); |
ad41e777 |
198 | } |
199 | |
200 | =head3 mk_file |
201 | |
b160463f |
202 | writes content to a file. |
203 | |
ad41e777 |
204 | =cut |
205 | |
206 | sub mk_file { |
207 | my ( $self, $file, $content ) = @_; |
208 | if ( -e $file ) { |
209 | print qq/ exists "$file"\n/; |
ef3250bc |
210 | return 0 unless $self->{'.newfiles'}; |
fbcc39ad |
211 | if ( my $f = IO::File->new("< $file") ) { |
212 | my $oldcontent = join( '', (<$f>) ); |
213 | return 0 if $content eq $oldcontent; |
214 | } |
215 | $file .= '.new'; |
ad41e777 |
216 | } |
217 | if ( my $f = IO::File->new("> $file") ) { |
218 | print $f $content; |
219 | print qq/created "$file"\n/; |
220 | return 1; |
221 | } |
fbcc39ad |
222 | |
223 | Catalyst::Exception->throw( message => qq/Couldn't create "$file", "$!"/ ); |
ad41e777 |
224 | } |
225 | |
226 | =head3 next_test |
227 | |
228 | =cut |
229 | |
230 | sub next_test { |
231 | my ( $self, $tname ) = @_; |
3cb1db8c |
232 | if ($tname) { $tname = "$tname.t" } |
ad41e777 |
233 | else { |
234 | my $name = $self->{name}; |
ad41e777 |
235 | my $prefix = $name; |
67308304 |
236 | $prefix =~ s/::/-/g; |
237 | $prefix = $prefix; |
3cb1db8c |
238 | $tname = $prefix . '.t'; |
ad41e777 |
239 | $self->{prefix} = $prefix; |
fbcc39ad |
240 | $prefix = lc $prefix; |
fa474081 |
241 | $prefix =~ s/-/\//g; |
3d5bb03e |
242 | $self->{uri} = $prefix; |
ad41e777 |
243 | } |
3cb1db8c |
244 | my $dir = $self->{test_dir}; |
67308304 |
245 | my $type = $self->{type}; |
3cb1db8c |
246 | return File::Spec->catfile( $dir, $type, $tname ); |
ad41e777 |
247 | } |
248 | |
61cfdd57 |
249 | =head3 render_file |
250 | |
b160463f |
251 | Render and create a file from a template in DATA using |
252 | Template Toolkit. |
61cfdd57 |
253 | |
254 | =cut |
255 | |
256 | sub render_file { |
257 | my ( $self, $file, $path, $vars ) = @_; |
258 | $vars ||= {}; |
259 | my $t = Template->new; |
260 | my $template = $self->get_file( ( caller(0) )[0], $file ); |
261 | return 0 unless $template; |
262 | my $output; |
fbcc39ad |
263 | $t->process( \$template, { %{$self}, %$vars }, \$output ) |
264 | || Catalyst::Exception->throw( |
265 | message => qq/Couldn't process "$file", / . $t->error() ); |
61cfdd57 |
266 | $self->mk_file( $path, $output ); |
267 | } |
268 | |
fc7ec1d9 |
269 | sub _mk_dirs { |
270 | my $self = shift; |
ad41e777 |
271 | $self->mk_dir( $self->{dir} ); |
91864987 |
272 | $self->{script} = File::Spec->catdir( $self->{dir}, 'script' ); |
273 | $self->mk_dir( $self->{script} ); |
fc7ec1d9 |
274 | $self->{lib} = File::Spec->catdir( $self->{dir}, 'lib' ); |
ad41e777 |
275 | $self->mk_dir( $self->{lib} ); |
fc7ec1d9 |
276 | $self->{root} = File::Spec->catdir( $self->{dir}, 'root' ); |
ad41e777 |
277 | $self->mk_dir( $self->{root} ); |
fc7ec1d9 |
278 | $self->{t} = File::Spec->catdir( $self->{dir}, 't' ); |
ad41e777 |
279 | $self->mk_dir( $self->{t} ); |
67308304 |
280 | $self->mk_dir( File::Spec->catdir( $self->{t}, 'M' ) ); |
281 | $self->mk_dir( File::Spec->catdir( $self->{t}, 'V' ) ); |
282 | $self->mk_dir( File::Spec->catdir( $self->{t}, 'C' ) ); |
fc7ec1d9 |
283 | $self->{class} = File::Spec->catdir( split( /\:\:/, $self->{name} ) ); |
284 | $self->{mod} = File::Spec->catdir( $self->{lib}, $self->{class} ); |
ad41e777 |
285 | $self->mk_dir( $self->{mod} ); |
fc7ec1d9 |
286 | $self->{m} = File::Spec->catdir( $self->{mod}, 'M' ); |
ad41e777 |
287 | $self->mk_dir( $self->{m} ); |
fc7ec1d9 |
288 | $self->{v} = File::Spec->catdir( $self->{mod}, 'V' ); |
ad41e777 |
289 | $self->mk_dir( $self->{v} ); |
fc7ec1d9 |
290 | $self->{c} = File::Spec->catdir( $self->{mod}, 'C' ); |
ad41e777 |
291 | $self->mk_dir( $self->{c} ); |
fc7ec1d9 |
292 | $self->{base} = File::Spec->rel2abs( $self->{dir} ); |
293 | } |
294 | |
295 | sub _mk_appclass { |
ad41e777 |
296 | my $self = shift; |
297 | my $mod = $self->{mod}; |
61cfdd57 |
298 | $self->render_file( 'appclass', "$mod.pm" ); |
299 | } |
300 | |
4f6748f1 |
301 | sub _mk_build { |
302 | my $self = shift; |
303 | my $dir = $self->{dir}; |
304 | $self->render_file( 'build', "$dir\/Build.PL" ); |
305 | } |
306 | |
61cfdd57 |
307 | sub _mk_makefile { |
308 | my $self = shift; |
309 | my $dir = $self->{dir}; |
310 | $self->render_file( 'makefile', "$dir\/Makefile.PL" ); |
311 | } |
312 | |
313 | sub _mk_readme { |
314 | my $self = shift; |
315 | my $dir = $self->{dir}; |
316 | $self->render_file( 'readme', "$dir\/README" ); |
317 | } |
318 | |
319 | sub _mk_changes { |
320 | my $self = shift; |
321 | my $dir = $self->{dir}; |
322 | my $time = localtime time; |
323 | $self->render_file( 'changes', "$dir\/Changes", { time => $time } ); |
324 | } |
325 | |
326 | sub _mk_apptest { |
327 | my $self = shift; |
328 | my $t = $self->{t}; |
329 | $self->render_file( 'apptest', "$t\/01app.t" ); |
330 | $self->render_file( 'podtest', "$t\/02pod.t" ); |
331 | $self->render_file( 'podcoveragetest', "$t\/03podcoverage.t" ); |
332 | } |
333 | |
334 | sub _mk_cgi { |
28e68b83 |
335 | my $self = shift; |
336 | my $script = $self->{script}; |
4f6748f1 |
337 | my $appprefix = $self->{appprefix}; |
338 | $self->render_file( 'cgi', "$script\/$appprefix\_cgi.pl" ); |
339 | chmod 0700, "$script/$appprefix\_cgi.pl"; |
61cfdd57 |
340 | } |
341 | |
28e68b83 |
342 | sub _mk_fastcgi { |
343 | my $self = shift; |
344 | my $script = $self->{script}; |
4f6748f1 |
345 | my $appprefix = $self->{appprefix}; |
28e68b83 |
346 | $self->render_file( 'fastcgi', "$script\/$appprefix\_fastcgi.pl" ); |
347 | chmod 0700, "$script/$appprefix\_fastcgi.pl"; |
61cfdd57 |
348 | } |
349 | |
350 | sub _mk_server { |
28e68b83 |
351 | my $self = shift; |
352 | my $script = $self->{script}; |
4f6748f1 |
353 | my $appprefix = $self->{appprefix}; |
354 | $self->render_file( 'server', "$script\/$appprefix\_server.pl" ); |
355 | chmod 0700, "$script/$appprefix\_server.pl"; |
61cfdd57 |
356 | } |
357 | |
358 | sub _mk_test { |
28e68b83 |
359 | my $self = shift; |
360 | my $script = $self->{script}; |
4f6748f1 |
361 | my $appprefix = $self->{appprefix}; |
362 | $self->render_file( 'test', "$script/$appprefix\_test.pl" ); |
363 | chmod 0700, "$script/$appprefix\_test.pl"; |
61cfdd57 |
364 | } |
365 | |
366 | sub _mk_create { |
28e68b83 |
367 | my $self = shift; |
368 | my $script = $self->{script}; |
4f6748f1 |
369 | my $appprefix = $self->{appprefix}; |
370 | $self->render_file( 'create', "$script\/$appprefix\_create.pl" ); |
371 | chmod 0700, "$script/$appprefix\_create.pl"; |
61cfdd57 |
372 | } |
373 | |
374 | sub _mk_compclass { |
375 | my $self = shift; |
376 | my $file = $self->{file}; |
377 | return $self->render_file( 'compclass', "$file" ); |
378 | } |
379 | |
380 | sub _mk_comptest { |
381 | my $self = shift; |
382 | my $test = $self->{test}; |
383 | $self->render_file( 'comptest', "$test" ); |
384 | } |
385 | |
386 | =head1 HELPERS |
387 | |
388 | Helpers are classes that provide two methods. |
389 | |
390 | * mk_compclass - creates the Component class |
391 | * mk_comptest - creates the Component test |
392 | |
393 | So when you call C<bin/create view MyView TT>, create would try to execute |
394 | Catalyst::Helper::View::TT->mk_compclass and |
395 | Catalyst::Helper::View::TT->mk_comptest. |
396 | |
397 | See L<Catalyst::Helper::View::TT> and L<Catalyst::Helper::Model::CDBI> for |
398 | examples. |
399 | |
400 | All helper classes should be under one of the following namespaces. |
401 | |
402 | Catalyst::Helper::Model:: |
403 | Catalyst::Helper::View:: |
404 | Catalyst::Helper::Controller:: |
405 | |
ddb46924 |
406 | =head1 NOTE |
407 | |
408 | The helpers will read author name from /etc/passwd by default. |
409 | To override, please export the AUTHOR variable. |
410 | |
61cfdd57 |
411 | =head1 SEE ALSO |
412 | |
413 | L<Catalyst::Manual>, L<Catalyst::Test>, L<Catalyst::Request>, |
414 | L<Catalyst::Response>, L<Catalyst> |
415 | |
416 | =head1 AUTHOR |
417 | |
418 | Sebastian Riedel, C<sri@oook.de> |
419 | |
420 | =head1 LICENSE |
421 | |
9c48119a |
422 | This library is free software . You can redistribute it and/or modify |
b160463f |
423 | it under the same terms as perl itself. |
61cfdd57 |
424 | |
425 | =cut |
426 | |
427 | 1; |
428 | __DATA__ |
429 | |
430 | __appclass__ |
431 | package [% name %]; |
fc7ec1d9 |
432 | |
433 | use strict; |
d2ee9760 |
434 | use Catalyst qw/-Debug/; |
fc7ec1d9 |
435 | |
61cfdd57 |
436 | our $VERSION = '0.01'; |
fc7ec1d9 |
437 | |
4efc6b10 |
438 | [% name %]->config( name => '[% name %]' ); |
5811fa3e |
439 | |
d2ee9760 |
440 | [% name %]->setup; |
fc7ec1d9 |
441 | |
fc7ec1d9 |
442 | =head1 NAME |
443 | |
df8632c6 |
444 | [% name %] - Catalyst based application |
fc7ec1d9 |
445 | |
446 | =head1 SYNOPSIS |
447 | |
df8632c6 |
448 | script/[% appprefix %]_server.pl |
fc7ec1d9 |
449 | |
450 | =head1 DESCRIPTION |
451 | |
df8632c6 |
452 | Catalyst based application. |
453 | |
454 | =head1 METHODS |
455 | |
444821f7 |
456 | =over 4 |
df8632c6 |
457 | |
458 | =item default |
459 | |
460 | =cut |
461 | |
462 | sub default : Private { |
463 | my ( $self, $c ) = @_; |
fbcc39ad |
464 | |
465 | # Hello World |
ab2374d3 |
466 | $c->response->output( $c->welcome_message ); |
df8632c6 |
467 | } |
fc7ec1d9 |
468 | |
fbcc39ad |
469 | #=item end |
470 | # |
471 | #=cut |
472 | # |
473 | #sub end : Private { |
474 | # my ( $self, $c ) = @_; |
475 | # |
476 | # # Forward to View unless response body is already defined |
477 | # $c->forward('MyApp::V::') unless $c->response->body; |
478 | #} |
479 | |
444821f7 |
480 | =back |
481 | |
fc7ec1d9 |
482 | =head1 AUTHOR |
483 | |
fbcc39ad |
484 | [% author %] |
fc7ec1d9 |
485 | |
486 | =head1 LICENSE |
487 | |
9c48119a |
488 | This library is free software . You can redistribute it and/or modify |
b160463f |
489 | it under the same terms as perl itself. |
fc7ec1d9 |
490 | |
491 | =cut |
492 | |
493 | 1; |
87c87366 |
494 | __makefile__ |
495 | unless ( eval "use Module::Build::Compat 0.02; 1" ) { |
496 | print "This module requires Module::Build to install itself.\n"; |
497 | |
498 | require ExtUtils::MakeMaker; |
499 | my $yn = |
500 | ExtUtils::MakeMaker::prompt( ' Install Module::Build now from CPAN?', 'y' ); |
501 | |
502 | unless ( $yn =~ /^y/i ) { |
503 | die " *** Cannot install without Module::Build. Exiting ...\n"; |
504 | } |
505 | |
506 | require Cwd; |
507 | require File::Spec; |
508 | require CPAN; |
509 | |
510 | # Save this 'cause CPAN will chdir all over the place. |
511 | my $cwd = Cwd::cwd(); |
512 | my $makefile = File::Spec->rel2abs($0); |
513 | |
514 | CPAN::Shell->install('Module::Build::Compat') |
515 | or die " *** Cannot install without Module::Build. Exiting ...\n"; |
516 | |
517 | chdir $cwd or die "Cannot chdir() back to $cwd: $!"; |
518 | } |
519 | eval "use Module::Build::Compat 0.02; 1" or die $@; |
520 | use lib '_build/lib'; |
521 | Module::Build::Compat->run_build_pl( args => \@ARGV ); |
522 | require Module::Build; |
523 | Module::Build::Compat->write_makefile( build_class => 'Module::Build' ); |
4f6748f1 |
524 | __build__ |
525 | use strict; |
526 | use Catalyst::Build; |
527 | |
528 | my $build = Catalyst::Build->new( |
529 | create_makefile_pl => 'passthrough', |
530 | license => 'perl', |
531 | module_name => '[% name %]', |
809fd1e0 |
532 | requires => { Catalyst => '5.10' }, |
adfe7ead |
533 | create_makefile_pl => 'passthrough', |
4f6748f1 |
534 | script_files => [ glob('script/*') ], |
535 | test_files => [ glob('t/*.t'), glob('t/*/*.t') ] |
fc7ec1d9 |
536 | ); |
4f6748f1 |
537 | $build->create_build_script; |
61cfdd57 |
538 | __readme__ |
749df43d |
539 | Run script/[% appprefix %]_server.pl to test the application. |
61cfdd57 |
540 | __changes__ |
7a870961 |
541 | This file documents the revision history for Perl extension [% name %]. |
61cfdd57 |
542 | 0.01 [% time %] |
91864987 |
543 | - initial revision, generated by Catalyst |
61cfdd57 |
544 | __apptest__ |
fc7ec1d9 |
545 | use Test::More tests => 2; |
61cfdd57 |
546 | use_ok( Catalyst::Test, '[% name %]' ); |
fc7ec1d9 |
547 | |
548 | ok( request('/')->is_success ); |
61cfdd57 |
549 | __podtest__ |
5a8fd7e9 |
550 | use Test::More; |
551 | |
552 | eval "use Test::Pod 1.14"; |
61cfdd57 |
553 | plan skip_all => 'Test::Pod 1.14 required' if $@; |
554 | plan skip_all => 'set TEST_POD to enable this test' unless $ENV{TEST_POD}; |
5a8fd7e9 |
555 | |
556 | all_pod_files_ok(); |
61cfdd57 |
557 | __podcoveragetest__ |
1df125c9 |
558 | use Test::More; |
559 | |
560 | eval "use Test::Pod::Coverage 1.04"; |
61cfdd57 |
561 | plan skip_all => 'Test::Pod::Coverage 1.04 required' if $@; |
562 | plan skip_all => 'set TEST_POD to enable this test' unless $ENV{TEST_POD}; |
1df125c9 |
563 | |
564 | all_pod_coverage_ok(); |
195631f4 |
565 | __cgi__ |
61cfdd57 |
566 | [% startperl %] -w |
67308304 |
567 | |
5a59ef2a |
568 | BEGIN { $ENV{CATALYST_ENGINE} ||= 'CGI' } |
d8ab1b45 |
569 | |
570 | use strict; |
571 | use FindBin; |
5a59ef2a |
572 | use lib "$FindBin::Bin/../lib"; |
61cfdd57 |
573 | use [% name %]; |
d8ab1b45 |
574 | |
61cfdd57 |
575 | [% name %]->run; |
d8ab1b45 |
576 | |
577 | 1; |
d8ab1b45 |
578 | |
579 | =head1 NAME |
580 | |
67308304 |
581 | [% appprefix %]_cgi.pl - Catalyst CGI |
d8ab1b45 |
582 | |
583 | =head1 SYNOPSIS |
584 | |
585 | See L<Catalyst::Manual> |
586 | |
587 | =head1 DESCRIPTION |
588 | |
589 | Run a Catalyst application as cgi. |
590 | |
591 | =head1 AUTHOR |
592 | |
61cfdd57 |
593 | Sebastian Riedel, C<sri@oook.de> |
d8ab1b45 |
594 | |
595 | =head1 COPYRIGHT |
596 | |
597 | Copyright 2004 Sebastian Riedel. All rights reserved. |
598 | |
9c48119a |
599 | This library is free software. You can redistribute it and/or modify |
b160463f |
600 | it under the same terms as perl itself. |
d8ab1b45 |
601 | |
602 | =cut |
28e68b83 |
603 | __fastcgi__ |
61cfdd57 |
604 | [% startperl %] -w |
cb8d90e5 |
605 | |
5a59ef2a |
606 | BEGIN { $ENV{CATALYST_ENGINE} ||= 'FastCGI' } |
607 | |
cb8d90e5 |
608 | use strict; |
609 | use FindBin; |
5a59ef2a |
610 | use lib "$FindBin::Bin/../lib"; |
61cfdd57 |
611 | use [% name %]; |
cb8d90e5 |
612 | |
61cfdd57 |
613 | [% name %]->run; |
cb8d90e5 |
614 | |
615 | 1; |
cb8d90e5 |
616 | |
617 | =head1 NAME |
618 | |
67308304 |
619 | [% appprefix %]_fastcgi.pl - Catalyst FastCGI |
cb8d90e5 |
620 | |
621 | =head1 SYNOPSIS |
622 | |
623 | See L<Catalyst::Manual> |
624 | |
625 | =head1 DESCRIPTION |
626 | |
28e68b83 |
627 | Run a Catalyst application as fastcgi. |
cb8d90e5 |
628 | |
629 | =head1 AUTHOR |
630 | |
61cfdd57 |
631 | Sebastian Riedel, C<sri@oook.de> |
cb8d90e5 |
632 | |
633 | =head1 COPYRIGHT |
634 | |
635 | Copyright 2004 Sebastian Riedel. All rights reserved. |
636 | |
9c48119a |
637 | This library is free software. You can redistribute it and/or modify |
b160463f |
638 | it under the same terms as perl itself. |
cb8d90e5 |
639 | |
640 | =cut |
61cfdd57 |
641 | __server__ |
642 | [% startperl %] -w |
fc7ec1d9 |
643 | |
5a59ef2a |
644 | BEGIN { |
645 | $ENV{CATALYST_ENGINE} ||= 'HTTP'; |
646 | $ENV{CATALYST_SCRIPT_GEN} = [% scriptgen %]; |
647 | } |
648 | |
fc7ec1d9 |
649 | use strict; |
650 | use Getopt::Long; |
651 | use Pod::Usage; |
652 | use FindBin; |
5a59ef2a |
653 | use lib "$FindBin::Bin/../lib"; |
61cfdd57 |
654 | use [% name %]; |
fc7ec1d9 |
655 | |
37553dc8 |
656 | my $fork = 0; |
657 | my $help = 0; |
658 | my $host = undef; |
659 | my $port = 3000; |
660 | my $restart = 0; |
661 | my $restart_delay = 1; |
662 | my $restart_regex = '\.yml$|\.yaml$|\.pm$'; |
fc7ec1d9 |
663 | |
6844bc1c |
664 | my @argv = @ARGV; |
665 | |
fbcc39ad |
666 | GetOptions( |
37553dc8 |
667 | 'fork' => \$fork, |
668 | 'help|?' => \$help, |
669 | 'host=s' => \$host, |
670 | 'port=s' => \$port, |
671 | 'restart|r' => \$restart, |
672 | 'restartdelay|rd=s' => \$restart_delay, |
673 | 'restartregex|rr=s' => \$restart_regex |
fbcc39ad |
674 | ); |
fc7ec1d9 |
675 | |
195631f4 |
676 | pod2usage(1) if $help; |
fc7ec1d9 |
677 | |
37553dc8 |
678 | [% name %]->run( $port, $host, { |
6844bc1c |
679 | argv => \@argv, |
37553dc8 |
680 | 'fork' => $fork, |
681 | restart => $restart, |
682 | restart_delay => $restart_delay, |
683 | restart_regex => qr/$restart_regex/ |
684 | } ); |
fc7ec1d9 |
685 | |
686 | 1; |
fc7ec1d9 |
687 | |
688 | =head1 NAME |
689 | |
67308304 |
690 | [% appprefix %]_server.pl - Catalyst Testserver |
fc7ec1d9 |
691 | |
692 | =head1 SYNOPSIS |
693 | |
67308304 |
694 | [% appprefix %]_server.pl [options] |
fc7ec1d9 |
695 | |
696 | Options: |
37553dc8 |
697 | -f -fork handle each request in a new process |
698 | (defaults to false) |
699 | -? -help display this help and exits |
700 | -host host (defaults to all) |
701 | -p -port port (defaults to 3000) |
702 | -r -restart restart when files got modified |
703 | (defaults to false) |
704 | -rd -restartdelay delay between file checks |
705 | -rr -restartregex regex match files that trigger |
706 | a restart when modified |
707 | (defaults to '\.yml$|\.yaml$|\.pm$') |
fc7ec1d9 |
708 | |
03a53815 |
709 | See also: |
710 | perldoc Catalyst::Manual |
711 | perldoc Catalyst::Manual::Intro |
712 | |
fc7ec1d9 |
713 | =head1 DESCRIPTION |
714 | |
715 | Run a Catalyst Testserver for this application. |
716 | |
717 | =head1 AUTHOR |
718 | |
61cfdd57 |
719 | Sebastian Riedel, C<sri@oook.de> |
fc7ec1d9 |
720 | |
721 | =head1 COPYRIGHT |
722 | |
723 | Copyright 2004 Sebastian Riedel. All rights reserved. |
724 | |
9c48119a |
725 | This library is free software. You can redistribute it and/or modify |
b160463f |
726 | it under the same terms as perl itself. |
fc7ec1d9 |
727 | |
728 | =cut |
61cfdd57 |
729 | __test__ |
730 | [% startperl %] -w |
fc7ec1d9 |
731 | |
5a59ef2a |
732 | BEGIN { $ENV{CATALYST_ENGINE} ||= 'Test' } |
733 | |
fc7ec1d9 |
734 | use strict; |
735 | use Getopt::Long; |
736 | use Pod::Usage; |
737 | use FindBin; |
5a59ef2a |
738 | use lib "$FindBin::Bin/../lib"; |
61cfdd57 |
739 | use [% name %]; |
fc7ec1d9 |
740 | |
61cfdd57 |
741 | my $help = 0; |
fc7ec1d9 |
742 | |
61cfdd57 |
743 | GetOptions( 'help|?' => \$help ); |
fc7ec1d9 |
744 | |
61cfdd57 |
745 | pod2usage(1) if ( $help || !$ARGV[0] ); |
fc7ec1d9 |
746 | |
61cfdd57 |
747 | print [% name %]->run($ARGV[0])->content . "\n"; |
fc7ec1d9 |
748 | |
749 | 1; |
fc7ec1d9 |
750 | |
751 | =head1 NAME |
752 | |
67308304 |
753 | [% appprefix %]_test.pl - Catalyst Test |
fc7ec1d9 |
754 | |
755 | =head1 SYNOPSIS |
756 | |
67308304 |
757 | [% appprefix %]_test.pl [options] uri |
fc7ec1d9 |
758 | |
759 | Options: |
760 | -help display this help and exits |
761 | |
762 | Examples: |
67308304 |
763 | [% appprefix %]_test.pl http://localhost/some_action |
764 | [% appprefix %]_test.pl /some_action |
fc7ec1d9 |
765 | |
03a53815 |
766 | See also: |
767 | perldoc Catalyst::Manual |
768 | perldoc Catalyst::Manual::Intro |
769 | |
fc7ec1d9 |
770 | =head1 DESCRIPTION |
771 | |
26e73131 |
772 | Run a Catalyst action from the command line. |
fc7ec1d9 |
773 | |
774 | =head1 AUTHOR |
775 | |
61cfdd57 |
776 | Sebastian Riedel, C<sri@oook.de> |
fc7ec1d9 |
777 | |
778 | =head1 COPYRIGHT |
779 | |
780 | Copyright 2004 Sebastian Riedel. All rights reserved. |
781 | |
9c48119a |
782 | This library is free software. You can redistribute it and/or modify |
b160463f |
783 | it under the same terms as perl itself. |
fc7ec1d9 |
784 | |
785 | =cut |
61cfdd57 |
786 | __create__ |
787 | [% startperl %] -w |
fc7ec1d9 |
788 | |
789 | use strict; |
790 | use Getopt::Long; |
791 | use Pod::Usage; |
792 | use Catalyst::Helper; |
793 | |
61cfdd57 |
794 | my $help = 0; |
ef3250bc |
795 | my $nonew = 0; |
fc7ec1d9 |
796 | |
ef3250bc |
797 | GetOptions( 'help|?' => \$help, |
798 | 'nonew' => \$nonew ); |
fc7ec1d9 |
799 | |
61cfdd57 |
800 | pod2usage(1) if ( $help || !$ARGV[0] ); |
fc7ec1d9 |
801 | |
ef3250bc |
802 | my $helper = Catalyst::Helper->new({'.newfiles' => !$nonew}); |
61cfdd57 |
803 | pod2usage(1) unless $helper->mk_component( '[% name %]', @ARGV ); |
fc7ec1d9 |
804 | |
805 | 1; |
fc7ec1d9 |
806 | |
807 | =head1 NAME |
808 | |
67308304 |
809 | [% appprefix %]_create.pl - Create a new Catalyst Component |
fc7ec1d9 |
810 | |
811 | =head1 SYNOPSIS |
812 | |
67308304 |
813 | [% appprefix %]_create.pl [options] model|view|controller name [helper] [options] |
fc7ec1d9 |
814 | |
815 | Options: |
816 | -help display this help and exits |
ef3250bc |
817 | -nonew don't create a .new file where a file to be created exists |
fc7ec1d9 |
818 | |
819 | Examples: |
67308304 |
820 | [% appprefix %]_create.pl controller My::Controller |
821 | [% appprefix %]_create.pl view My::View |
822 | [% appprefix %]_create.pl view MyView TT |
823 | [% appprefix %]_create.pl view TT TT |
824 | [% appprefix %]_create.pl model My::Model |
825 | [% appprefix %]_create.pl model SomeDB CDBI dbi:SQLite:/tmp/my.db |
826 | [% appprefix %]_create.pl model AnotherDB CDBI dbi:Pg:dbname=foo root 4321 |
03a53815 |
827 | |
828 | See also: |
829 | perldoc Catalyst::Manual |
830 | perldoc Catalyst::Manual::Intro |
fc7ec1d9 |
831 | |
832 | =head1 DESCRIPTION |
833 | |
834 | Create a new Catalyst Component. |
835 | |
ef3250bc |
836 | Existing component files are not overwritten. If any of the component files |
837 | to be created already exist the file will be written with a '.new' suffix. |
26e73131 |
838 | This behavior can be suppressed with the C<-nonew> option. |
ef3250bc |
839 | |
fc7ec1d9 |
840 | =head1 AUTHOR |
841 | |
842 | Sebastian Riedel, C<sri\@oook.de> |
843 | |
844 | =head1 COPYRIGHT |
845 | |
846 | Copyright 2004 Sebastian Riedel. All rights reserved. |
847 | |
9c48119a |
848 | This library is free software. You can redistribute it and/or modify |
b160463f |
849 | it under the same terms as perl itself. |
fc7ec1d9 |
850 | |
851 | =cut |
61cfdd57 |
852 | __compclass__ |
853 | package [% class %]; |
854 | |
855 | use strict; |
856 | use base 'Catalyst::Base'; |
fc7ec1d9 |
857 | |
fc7ec1d9 |
858 | =head1 NAME |
859 | |
d4bcc27a |
860 | [% class %] - Catalyst component |
fc7ec1d9 |
861 | |
862 | =head1 SYNOPSIS |
863 | |
df8632c6 |
864 | See L<[% app %]> |
fc7ec1d9 |
865 | |
866 | =head1 DESCRIPTION |
867 | |
df8632c6 |
868 | Catalyst component. |
869 | [% IF type == 'C' %] |
870 | =head1 METHODS |
871 | |
444821f7 |
872 | =over 4 |
df8632c6 |
873 | |
874 | =item default |
fc7ec1d9 |
875 | |
df8632c6 |
876 | =cut |
877 | |
878 | sub default : Private { |
879 | my ( $self, $c ) = @_; |
fbcc39ad |
880 | |
881 | # Hello World |
882 | $c->response->output('Congratulations, [% class %] is on Catalyst!'); |
df8632c6 |
883 | } |
444821f7 |
884 | |
885 | =back |
7dcb4831 |
886 | |
df8632c6 |
887 | [% END %] |
fc7ec1d9 |
888 | =head1 AUTHOR |
889 | |
ddb46924 |
890 | [%author%] |
fc7ec1d9 |
891 | |
892 | =head1 LICENSE |
893 | |
9c48119a |
894 | This library is free software . You can redistribute it and/or modify |
b160463f |
895 | it under the same terms as perl itself. |
fc7ec1d9 |
896 | |
897 | =cut |
898 | |
899 | 1; |
61cfdd57 |
900 | __comptest__ |
901 | [% IF type == 'C' %] |
fc7ec1d9 |
902 | use Test::More tests => 3; |
61cfdd57 |
903 | use_ok( Catalyst::Test, '[% app %]' ); |
904 | use_ok('[% class %]'); |
fc7ec1d9 |
905 | |
3d5bb03e |
906 | ok( request('[% uri %]')->is_success ); |
61cfdd57 |
907 | [% ELSE %] |
fc7ec1d9 |
908 | use Test::More tests => 1; |
61cfdd57 |
909 | use_ok('[% class %]'); |
910 | [% END %] |