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; |
42a57832 |
11 | our $CATALYST_SCRIPT_GEN = 2; |
61cfdd57 |
12 | |
13 | my %cache; |
fc7ec1d9 |
14 | |
15 | =head1 NAME |
16 | |
17 | Catalyst::Helper - Bootstrap a Catalyst application |
18 | |
19 | =head1 SYNOPSIS |
20 | |
21 | See L<Catalyst::Manual::Intro> |
22 | |
23 | =head1 DESCRIPTION |
24 | |
b160463f |
25 | Bootstrap a Catalyst application. Autogenerates scripts |
fc7ec1d9 |
26 | |
27 | =head2 METHODS |
28 | |
61cfdd57 |
29 | =head3 get_file |
30 | |
31 | Slurp file from DATA. |
32 | |
33 | =cut |
34 | |
35 | sub get_file { |
36 | my ( $self, $class, $file ) = @_; |
37 | unless ( $cache{$class} ) { |
38 | local $/; |
39 | $cache{$class} = eval "package $class; <DATA>"; |
40 | } |
41 | my $data = $cache{$class}; |
42 | my @files = split /^__(.+)__\n/m, $data; |
43 | shift @files; |
44 | while (@files) { |
45 | my ( $name, $content ) = splice @files, 0, 2; |
46 | return $content if $name eq $file; |
47 | } |
48 | return 0; |
49 | } |
50 | |
fc7ec1d9 |
51 | =head3 mk_app |
52 | |
b160463f |
53 | Create the main application skeleton. |
54 | |
fc7ec1d9 |
55 | =cut |
56 | |
57 | sub mk_app { |
58 | my ( $self, $name ) = @_; |
59 | return 0 if $name =~ /[^\w\:]/; |
60 | $self->{name} = $name; |
61 | $self->{dir} = $name; |
62 | $self->{dir} =~ s/\:\:/-/g; |
61cfdd57 |
63 | $self->{startperl} = $Config{startperl}; |
42a57832 |
64 | $self->{scriptgen}=$CATALYST_SCRIPT_GEN; |
fc7ec1d9 |
65 | $self->_mk_dirs; |
66 | $self->_mk_appclass; |
67 | $self->_mk_makefile; |
91864987 |
68 | $self->_mk_readme; |
69 | $self->_mk_changes; |
fc7ec1d9 |
70 | $self->_mk_apptest; |
bc024080 |
71 | $self->_mk_cgi; |
cb8d90e5 |
72 | $self->_mk_fcgi; |
fc7ec1d9 |
73 | $self->_mk_server; |
74 | $self->_mk_test; |
75 | $self->_mk_create; |
76 | return 1; |
77 | } |
78 | |
ad41e777 |
79 | =head3 mk_component |
80 | |
b160463f |
81 | This method is called by create.pl to make new components |
82 | for your application. |
83 | |
ad41e777 |
84 | =cut |
85 | |
86 | sub mk_component { |
b5524568 |
87 | my $self = shift; |
88 | my $app = shift; |
89 | $self->{app} = $app; |
90 | $self->{base} = File::Spec->catdir( $FindBin::Bin, '..' ); |
91 | unless ( $_[0] =~ /^model|m|view|v|controller|c\$/i ) { |
92 | my $helper = shift; |
93 | my @args = @_; |
94 | my $class = "Catalyst::Helper::$helper"; |
ad41e777 |
95 | eval "require $class"; |
96 | die qq/Couldn't load helper "$class", "$@"/ if $@; |
b5524568 |
97 | if ( $class->can('mk_stuff') ) { |
98 | return 1 unless $class->mk_stuff( $self, @args ); |
ad41e777 |
99 | } |
ad41e777 |
100 | } |
ad41e777 |
101 | else { |
b5524568 |
102 | my $type = shift; |
103 | my $name = shift; |
104 | my $helper = shift; |
105 | my @args = @_; |
106 | return 0 if $name =~ /[^\w\:]/; |
107 | $type = 'M' if $type =~ /model|m/i; |
108 | $type = 'V' if $type =~ /view|v/i; |
109 | $type = 'C' if $type =~ /controller|c/i; |
110 | $self->{type} = $type; |
111 | $self->{name} = $name; |
112 | $self->{class} = "$app\::$type\::$name"; |
113 | |
114 | # Class |
115 | my $appdir = File::Spec->catdir( split /\:\:/, $app ); |
116 | my $path = |
117 | File::Spec->catdir( $FindBin::Bin, '..', 'lib', $appdir, $type ); |
118 | my $file = $name; |
119 | if ( $name =~ /\:/ ) { |
120 | my @path = split /\:\:/, $name; |
121 | $file = pop @path; |
122 | $path = File::Spec->catdir( $path, @path ); |
123 | mkpath $path; |
124 | } |
125 | $file = File::Spec->catfile( $path, "$file.pm" ); |
126 | $self->{file} = $file; |
127 | |
128 | # Test |
129 | $self->{test_dir} = File::Spec->catdir( $FindBin::Bin, '..', 't' ); |
130 | $self->{test} = $self->next_test; |
131 | |
132 | # Helper |
133 | if ($helper) { |
134 | my $comp = 'Model'; |
135 | $comp = 'View' if $type eq 'V'; |
136 | $comp = 'Controller' if $type eq 'C'; |
137 | my $class = "Catalyst::Helper::$comp\::$helper"; |
138 | eval "require $class"; |
139 | die qq/Couldn't load helper "$class", "$@"/ if $@; |
140 | if ( $class->can('mk_compclass') ) { |
141 | return 1 unless $class->mk_compclass( $self, @args ); |
142 | } |
143 | else { return 1 unless $self->_mk_compclass } |
144 | |
145 | if ( $class->can('mk_comptest') ) { |
146 | $class->mk_comptest( $self, @args ); |
147 | } |
148 | else { $self->_mk_comptest } |
149 | } |
150 | |
151 | # Fallback |
152 | else { |
153 | return 1 unless $self->_mk_compclass; |
154 | $self->_mk_comptest; |
155 | } |
ad41e777 |
156 | } |
157 | return 1; |
158 | } |
159 | |
160 | =head3 mk_dir |
161 | |
b160463f |
162 | Surprisingly, this function makes a directory. |
163 | |
ad41e777 |
164 | =cut |
165 | |
166 | sub mk_dir { |
167 | my ( $self, $dir ) = @_; |
168 | if ( -d $dir ) { |
169 | print qq/ exists "$dir"\n/; |
170 | return 0; |
171 | } |
172 | if ( mkpath $dir) { |
173 | print qq/created "$dir"\n/; |
174 | return 1; |
175 | } |
176 | die qq/Couldn't create "$dir", "$!"/; |
177 | } |
178 | |
179 | =head3 mk_file |
180 | |
b160463f |
181 | writes content to a file. |
182 | |
ad41e777 |
183 | =cut |
184 | |
185 | sub mk_file { |
186 | my ( $self, $file, $content ) = @_; |
187 | if ( -e $file ) { |
188 | print qq/ exists "$file"\n/; |
189 | return 0; |
190 | } |
191 | if ( my $f = IO::File->new("> $file") ) { |
192 | print $f $content; |
193 | print qq/created "$file"\n/; |
194 | return 1; |
195 | } |
196 | die qq/Couldn't create "$file", "$!"/; |
197 | } |
198 | |
199 | =head3 next_test |
200 | |
201 | =cut |
202 | |
203 | sub next_test { |
204 | my ( $self, $tname ) = @_; |
3cb1db8c |
205 | if ($tname) { $tname = "$tname.t" } |
ad41e777 |
206 | else { |
207 | my $name = $self->{name}; |
ad41e777 |
208 | my $prefix = $name; |
209 | $prefix =~ s/::/_/g; |
210 | $prefix = lc $prefix; |
3cb1db8c |
211 | $tname = $prefix . '.t'; |
ad41e777 |
212 | $self->{prefix} = $prefix; |
213 | } |
3cb1db8c |
214 | my $dir = $self->{test_dir}; |
215 | my $type = lc $self->{type}; |
216 | return File::Spec->catfile( $dir, $type, $tname ); |
ad41e777 |
217 | } |
218 | |
61cfdd57 |
219 | =head3 render_file |
220 | |
b160463f |
221 | Render and create a file from a template in DATA using |
222 | Template Toolkit. |
61cfdd57 |
223 | |
224 | =cut |
225 | |
226 | sub render_file { |
227 | my ( $self, $file, $path, $vars ) = @_; |
228 | $vars ||= {}; |
229 | my $t = Template->new; |
230 | my $template = $self->get_file( ( caller(0) )[0], $file ); |
231 | return 0 unless $template; |
232 | my $output; |
233 | $t->process( \$template, { %{$self}, %$vars }, \$output ); |
234 | $self->mk_file( $path, $output ); |
235 | } |
236 | |
fc7ec1d9 |
237 | sub _mk_dirs { |
238 | my $self = shift; |
ad41e777 |
239 | $self->mk_dir( $self->{dir} ); |
91864987 |
240 | $self->{script} = File::Spec->catdir( $self->{dir}, 'script' ); |
241 | $self->mk_dir( $self->{script} ); |
fc7ec1d9 |
242 | $self->{lib} = File::Spec->catdir( $self->{dir}, 'lib' ); |
ad41e777 |
243 | $self->mk_dir( $self->{lib} ); |
fc7ec1d9 |
244 | $self->{root} = File::Spec->catdir( $self->{dir}, 'root' ); |
ad41e777 |
245 | $self->mk_dir( $self->{root} ); |
fc7ec1d9 |
246 | $self->{t} = File::Spec->catdir( $self->{dir}, 't' ); |
ad41e777 |
247 | $self->mk_dir( $self->{t} ); |
3cb1db8c |
248 | $self->mk_dir( File::Spec->catdir( $self->{t}, 'm' ) ); |
249 | $self->mk_dir( File::Spec->catdir( $self->{t}, 'v' ) ); |
250 | $self->mk_dir( File::Spec->catdir( $self->{t}, 'c' ) ); |
fc7ec1d9 |
251 | $self->{class} = File::Spec->catdir( split( /\:\:/, $self->{name} ) ); |
252 | $self->{mod} = File::Spec->catdir( $self->{lib}, $self->{class} ); |
ad41e777 |
253 | $self->mk_dir( $self->{mod} ); |
fc7ec1d9 |
254 | $self->{m} = File::Spec->catdir( $self->{mod}, 'M' ); |
ad41e777 |
255 | $self->mk_dir( $self->{m} ); |
fc7ec1d9 |
256 | $self->{v} = File::Spec->catdir( $self->{mod}, 'V' ); |
ad41e777 |
257 | $self->mk_dir( $self->{v} ); |
fc7ec1d9 |
258 | $self->{c} = File::Spec->catdir( $self->{mod}, 'C' ); |
ad41e777 |
259 | $self->mk_dir( $self->{c} ); |
fc7ec1d9 |
260 | $self->{base} = File::Spec->rel2abs( $self->{dir} ); |
261 | } |
262 | |
263 | sub _mk_appclass { |
ad41e777 |
264 | my $self = shift; |
265 | my $mod = $self->{mod}; |
61cfdd57 |
266 | $self->render_file( 'appclass', "$mod.pm" ); |
267 | } |
268 | |
269 | sub _mk_makefile { |
270 | my $self = shift; |
271 | my $dir = $self->{dir}; |
272 | $self->render_file( 'makefile', "$dir\/Makefile.PL" ); |
273 | } |
274 | |
275 | sub _mk_readme { |
276 | my $self = shift; |
277 | my $dir = $self->{dir}; |
278 | $self->render_file( 'readme', "$dir\/README" ); |
279 | } |
280 | |
281 | sub _mk_changes { |
282 | my $self = shift; |
283 | my $dir = $self->{dir}; |
284 | my $time = localtime time; |
285 | $self->render_file( 'changes', "$dir\/Changes", { time => $time } ); |
286 | } |
287 | |
288 | sub _mk_apptest { |
289 | my $self = shift; |
290 | my $t = $self->{t}; |
291 | $self->render_file( 'apptest', "$t\/01app.t" ); |
292 | $self->render_file( 'podtest', "$t\/02pod.t" ); |
293 | $self->render_file( 'podcoveragetest', "$t\/03podcoverage.t" ); |
294 | } |
295 | |
296 | sub _mk_cgi { |
297 | my $self = shift; |
298 | my $script = $self->{script}; |
299 | $self->render_file( 'cgi', "$script\/cgi.pl" ); |
300 | chmod 0700, "$script/cgi.pl"; |
301 | } |
302 | |
303 | sub _mk_fcgi { |
304 | my $self = shift; |
305 | my $script = $self->{script}; |
306 | $self->render_file( 'fcgi', "$script\/fcgi.pl" ); |
307 | chmod 0700, "$script/fcgi.pl"; |
308 | } |
309 | |
310 | sub _mk_server { |
311 | my $self = shift; |
312 | my $script = $self->{script}; |
313 | $self->render_file( 'server', "$script\/server.pl" ); |
314 | chmod 0700, "$script/server.pl"; |
315 | } |
316 | |
317 | sub _mk_test { |
318 | my $self = shift; |
319 | my $script = $self->{script}; |
320 | $self->render_file( 'test', "$script/test.pl" ); |
321 | chmod 0700, "$script/test.pl"; |
322 | } |
323 | |
324 | sub _mk_create { |
325 | my $self = shift; |
326 | my $script = $self->{script}; |
327 | $self->render_file( 'create', "$script\/create.pl" ); |
328 | chmod 0700, "$script/create.pl"; |
329 | } |
330 | |
331 | sub _mk_compclass { |
332 | my $self = shift; |
333 | my $file = $self->{file}; |
334 | return $self->render_file( 'compclass', "$file" ); |
335 | } |
336 | |
337 | sub _mk_comptest { |
338 | my $self = shift; |
339 | my $test = $self->{test}; |
340 | $self->render_file( 'comptest', "$test" ); |
341 | } |
342 | |
343 | =head1 HELPERS |
344 | |
345 | Helpers are classes that provide two methods. |
346 | |
347 | * mk_compclass - creates the Component class |
348 | * mk_comptest - creates the Component test |
349 | |
350 | So when you call C<bin/create view MyView TT>, create would try to execute |
351 | Catalyst::Helper::View::TT->mk_compclass and |
352 | Catalyst::Helper::View::TT->mk_comptest. |
353 | |
354 | See L<Catalyst::Helper::View::TT> and L<Catalyst::Helper::Model::CDBI> for |
355 | examples. |
356 | |
357 | All helper classes should be under one of the following namespaces. |
358 | |
359 | Catalyst::Helper::Model:: |
360 | Catalyst::Helper::View:: |
361 | Catalyst::Helper::Controller:: |
362 | |
363 | =head1 SEE ALSO |
364 | |
365 | L<Catalyst::Manual>, L<Catalyst::Test>, L<Catalyst::Request>, |
366 | L<Catalyst::Response>, L<Catalyst> |
367 | |
368 | =head1 AUTHOR |
369 | |
370 | Sebastian Riedel, C<sri@oook.de> |
371 | |
372 | =head1 LICENSE |
373 | |
b160463f |
374 | This library is free software . You can redistribute it and/or modify |
375 | it under the same terms as perl itself. |
61cfdd57 |
376 | |
377 | =cut |
378 | |
379 | 1; |
380 | __DATA__ |
381 | |
382 | __appclass__ |
383 | package [% name %]; |
fc7ec1d9 |
384 | |
385 | use strict; |
386 | use Catalyst qw/-Debug/; |
387 | |
61cfdd57 |
388 | our $VERSION = '0.01'; |
fc7ec1d9 |
389 | |
61cfdd57 |
390 | [% name %]->config( |
391 | name => '[% name %]', |
392 | root => '[% base %]/root', |
fc7ec1d9 |
393 | ); |
5811fa3e |
394 | |
61cfdd57 |
395 | [% name %]->setup; |
fc7ec1d9 |
396 | |
5a8ed4fe |
397 | sub default : Private { |
61cfdd57 |
398 | my ( $self, $c ) = @_; |
399 | $c->res->output('Congratulations, [% name %] is on Catalyst!'); |
5a8ed4fe |
400 | } |
fc7ec1d9 |
401 | |
402 | =head1 NAME |
403 | |
61cfdd57 |
404 | [% name %] - A very nice application |
fc7ec1d9 |
405 | |
406 | =head1 SYNOPSIS |
407 | |
408 | Very simple to use |
409 | |
410 | =head1 DESCRIPTION |
411 | |
412 | Very nice application. |
413 | |
414 | =head1 AUTHOR |
415 | |
416 | Clever guy |
417 | |
418 | =head1 LICENSE |
419 | |
b160463f |
420 | This library is free software . You can redistribute it and/or modify |
421 | it under the same terms as perl itself. |
fc7ec1d9 |
422 | |
423 | =cut |
424 | |
425 | 1; |
fc7ec1d9 |
426 | |
61cfdd57 |
427 | __makefile__ |
fc7ec1d9 |
428 | use ExtUtils::MakeMaker; |
429 | |
430 | WriteMakefile( |
61cfdd57 |
431 | NAME => '[% name %]', |
432 | VERSION_FROM => 'lib/[% class %].pm', |
4400b5ef |
433 | PREREQ_PM => { Catalyst => 5 }, |
3cb1db8c |
434 | test => { TESTS => join ' ', ( glob('t/*.t'), glob('t/*/*.t') ) } |
fc7ec1d9 |
435 | ); |
fc7ec1d9 |
436 | |
61cfdd57 |
437 | __readme__ |
91864987 |
438 | Run script/server.pl to test the application. |
91864987 |
439 | |
61cfdd57 |
440 | __changes__ |
91864987 |
441 | This file documents the revision history for Perl extension $name. |
442 | |
61cfdd57 |
443 | 0.01 [% time %] |
91864987 |
444 | - initial revision, generated by Catalyst |
91864987 |
445 | |
61cfdd57 |
446 | __apptest__ |
fc7ec1d9 |
447 | use Test::More tests => 2; |
61cfdd57 |
448 | use_ok( Catalyst::Test, '[% name %]' ); |
fc7ec1d9 |
449 | |
450 | ok( request('/')->is_success ); |
61cfdd57 |
451 | |
452 | __podtest__ |
5a8fd7e9 |
453 | use Test::More; |
454 | |
455 | eval "use Test::Pod 1.14"; |
61cfdd57 |
456 | plan skip_all => 'Test::Pod 1.14 required' if $@; |
457 | plan skip_all => 'set TEST_POD to enable this test' unless $ENV{TEST_POD}; |
5a8fd7e9 |
458 | |
459 | all_pod_files_ok(); |
61cfdd57 |
460 | |
461 | __podcoveragetest__ |
1df125c9 |
462 | use Test::More; |
463 | |
464 | eval "use Test::Pod::Coverage 1.04"; |
61cfdd57 |
465 | plan skip_all => 'Test::Pod::Coverage 1.04 required' if $@; |
466 | plan skip_all => 'set TEST_POD to enable this test' unless $ENV{TEST_POD}; |
1df125c9 |
467 | |
468 | all_pod_coverage_ok(); |
fc7ec1d9 |
469 | |
195631f4 |
470 | __cgi__ |
61cfdd57 |
471 | [% startperl %] -w |
472 | BEGIN { $ENV{CATALYST_ENGINE} = 'CGI' } |
d8ab1b45 |
473 | |
474 | use strict; |
475 | use FindBin; |
61cfdd57 |
476 | use lib "$FindBin::Bin/../lib"; |
477 | use [% name %]; |
d8ab1b45 |
478 | |
61cfdd57 |
479 | [% name %]->run; |
d8ab1b45 |
480 | |
481 | 1; |
d8ab1b45 |
482 | |
483 | =head1 NAME |
484 | |
485 | cgi - Catalyst CGI |
486 | |
487 | =head1 SYNOPSIS |
488 | |
489 | See L<Catalyst::Manual> |
490 | |
491 | =head1 DESCRIPTION |
492 | |
493 | Run a Catalyst application as cgi. |
494 | |
495 | =head1 AUTHOR |
496 | |
61cfdd57 |
497 | Sebastian Riedel, C<sri@oook.de> |
d8ab1b45 |
498 | |
499 | =head1 COPYRIGHT |
500 | |
501 | Copyright 2004 Sebastian Riedel. All rights reserved. |
502 | |
b160463f |
503 | This library is free software. You can redistribute it and/or modify |
504 | it under the same terms as perl itself. |
d8ab1b45 |
505 | |
506 | =cut |
d8ab1b45 |
507 | |
61cfdd57 |
508 | __fcgi__ |
509 | [% startperl %] -w |
cb8d90e5 |
510 | |
61cfdd57 |
511 | BEGIN { $ENV{CATALYST_ENGINE} = 'FCGI' } |
cb8d90e5 |
512 | |
513 | use strict; |
514 | use FindBin; |
61cfdd57 |
515 | use lib "$FindBin::Bin/../lib"; |
516 | use [% name %]; |
cb8d90e5 |
517 | |
61cfdd57 |
518 | [% name %]->run; |
cb8d90e5 |
519 | |
520 | 1; |
cb8d90e5 |
521 | |
522 | =head1 NAME |
523 | |
524 | fcgi - Catalyst FCGI |
525 | |
526 | =head1 SYNOPSIS |
527 | |
528 | See L<Catalyst::Manual> |
529 | |
530 | =head1 DESCRIPTION |
531 | |
532 | Run a Catalyst application as fcgi. |
533 | |
534 | =head1 AUTHOR |
535 | |
61cfdd57 |
536 | Sebastian Riedel, C<sri@oook.de> |
cb8d90e5 |
537 | |
538 | =head1 COPYRIGHT |
539 | |
540 | Copyright 2004 Sebastian Riedel. All rights reserved. |
541 | |
b160463f |
542 | This library is free software. You can redistribute it and/or modify |
543 | it under the same terms as perl itself. |
cb8d90e5 |
544 | |
545 | =cut |
cb8d90e5 |
546 | |
61cfdd57 |
547 | __server__ |
548 | [% startperl %] -w |
fc7ec1d9 |
549 | |
42a57832 |
550 | BEGIN { |
551 | $ENV{CATALYST_ENGINE} = 'HTTP'; |
552 | $ENV{CATALYST_SCRIPT_GEN} = [% scriptgen %]; |
553 | } |
585893b9 |
554 | |
fc7ec1d9 |
555 | use strict; |
556 | use Getopt::Long; |
557 | use Pod::Usage; |
558 | use FindBin; |
61cfdd57 |
559 | use lib "$FindBin::Bin/../lib"; |
560 | use [% name %]; |
fc7ec1d9 |
561 | |
61cfdd57 |
562 | my $help = 0; |
563 | my $port = 3000; |
fc7ec1d9 |
564 | |
61cfdd57 |
565 | GetOptions( 'help|?' => \$help, 'port=s' => \$port ); |
fc7ec1d9 |
566 | |
195631f4 |
567 | pod2usage(1) if $help; |
fc7ec1d9 |
568 | |
61cfdd57 |
569 | [% name %]->run($port); |
fc7ec1d9 |
570 | |
571 | 1; |
fc7ec1d9 |
572 | |
573 | =head1 NAME |
574 | |
575 | server - Catalyst Testserver |
576 | |
577 | =head1 SYNOPSIS |
578 | |
91864987 |
579 | server.pl [options] |
fc7ec1d9 |
580 | |
581 | Options: |
ad41e777 |
582 | -? -help display this help and exits |
583 | -p -port port (defaults to 3000) |
fc7ec1d9 |
584 | |
03a53815 |
585 | See also: |
586 | perldoc Catalyst::Manual |
587 | perldoc Catalyst::Manual::Intro |
588 | |
fc7ec1d9 |
589 | =head1 DESCRIPTION |
590 | |
591 | Run a Catalyst Testserver for this application. |
592 | |
593 | =head1 AUTHOR |
594 | |
61cfdd57 |
595 | Sebastian Riedel, C<sri@oook.de> |
fc7ec1d9 |
596 | |
597 | =head1 COPYRIGHT |
598 | |
599 | Copyright 2004 Sebastian Riedel. All rights reserved. |
600 | |
b160463f |
601 | This library is free software. You can redistribute it and/or modify |
602 | it under the same terms as perl itself. |
fc7ec1d9 |
603 | |
604 | =cut |
fc7ec1d9 |
605 | |
61cfdd57 |
606 | __test__ |
607 | [% startperl %] -w |
fc7ec1d9 |
608 | |
61cfdd57 |
609 | BEGIN { $ENV{CATALYST_ENGINE} = 'Test' } |
e646f111 |
610 | |
fc7ec1d9 |
611 | use strict; |
612 | use Getopt::Long; |
613 | use Pod::Usage; |
614 | use FindBin; |
61cfdd57 |
615 | use lib "$FindBin::Bin/../lib"; |
616 | use [% name %]; |
fc7ec1d9 |
617 | |
61cfdd57 |
618 | my $help = 0; |
fc7ec1d9 |
619 | |
61cfdd57 |
620 | GetOptions( 'help|?' => \$help ); |
fc7ec1d9 |
621 | |
61cfdd57 |
622 | pod2usage(1) if ( $help || !$ARGV[0] ); |
fc7ec1d9 |
623 | |
61cfdd57 |
624 | print [% name %]->run($ARGV[0])->content . "\n"; |
fc7ec1d9 |
625 | |
626 | 1; |
fc7ec1d9 |
627 | |
628 | =head1 NAME |
629 | |
630 | test - Catalyst Test |
631 | |
632 | =head1 SYNOPSIS |
633 | |
91864987 |
634 | test.pl [options] uri |
fc7ec1d9 |
635 | |
636 | Options: |
637 | -help display this help and exits |
638 | |
639 | Examples: |
91864987 |
640 | test.pl http://localhost/some_action |
641 | test.pl /some_action |
fc7ec1d9 |
642 | |
03a53815 |
643 | See also: |
644 | perldoc Catalyst::Manual |
645 | perldoc Catalyst::Manual::Intro |
646 | |
fc7ec1d9 |
647 | =head1 DESCRIPTION |
648 | |
649 | Run a Catalyst action from the comand line. |
650 | |
651 | =head1 AUTHOR |
652 | |
61cfdd57 |
653 | Sebastian Riedel, C<sri@oook.de> |
fc7ec1d9 |
654 | |
655 | =head1 COPYRIGHT |
656 | |
657 | Copyright 2004 Sebastian Riedel. All rights reserved. |
658 | |
b160463f |
659 | This library is free software. You can redistribute it and/or modify |
660 | it under the same terms as perl itself. |
fc7ec1d9 |
661 | |
662 | =cut |
fc7ec1d9 |
663 | |
61cfdd57 |
664 | __create__ |
665 | [% startperl %] -w |
fc7ec1d9 |
666 | |
667 | use strict; |
668 | use Getopt::Long; |
669 | use Pod::Usage; |
670 | use Catalyst::Helper; |
671 | |
61cfdd57 |
672 | my $help = 0; |
fc7ec1d9 |
673 | |
674 | GetOptions( 'help|?' => \$help ); |
675 | |
61cfdd57 |
676 | pod2usage(1) if ( $help || !$ARGV[0] ); |
fc7ec1d9 |
677 | |
61cfdd57 |
678 | my $helper = Catalyst::Helper->new; |
679 | pod2usage(1) unless $helper->mk_component( '[% name %]', @ARGV ); |
fc7ec1d9 |
680 | |
681 | 1; |
fc7ec1d9 |
682 | |
683 | =head1 NAME |
684 | |
685 | create - Create a new Catalyst Component |
686 | |
687 | =head1 SYNOPSIS |
688 | |
91864987 |
689 | create.pl [options] model|view|controller name [helper] [options] |
fc7ec1d9 |
690 | |
691 | Options: |
692 | -help display this help and exits |
693 | |
694 | Examples: |
91864987 |
695 | create.pl controller My::Controller |
696 | create.pl view My::View |
697 | create.pl view MyView TT |
698 | create.pl view TT TT |
699 | create.pl model My::Model |
700 | create.pl model SomeDB CDBI dbi:SQLite:/tmp/my.db |
701 | create.pl model AnotherDB CDBI dbi:Pg:dbname=foo root 4321 |
b5524568 |
702 | create.pl Ajax |
03a53815 |
703 | |
704 | See also: |
705 | perldoc Catalyst::Manual |
706 | perldoc Catalyst::Manual::Intro |
fc7ec1d9 |
707 | |
708 | =head1 DESCRIPTION |
709 | |
710 | Create a new Catalyst Component. |
711 | |
712 | =head1 AUTHOR |
713 | |
714 | Sebastian Riedel, C<sri\@oook.de> |
715 | |
716 | =head1 COPYRIGHT |
717 | |
718 | Copyright 2004 Sebastian Riedel. All rights reserved. |
719 | |
b160463f |
720 | This library is free software. You can redistribute it and/or modify |
721 | it under the same terms as perl itself. |
fc7ec1d9 |
722 | |
723 | =cut |
fc7ec1d9 |
724 | |
61cfdd57 |
725 | __compclass__ |
726 | package [% class %]; |
727 | |
728 | use strict; |
729 | use base 'Catalyst::Base'; |
fc7ec1d9 |
730 | |
61cfdd57 |
731 | [% IF type == 'C' %] |
5a8ed4fe |
732 | sub default : Private { |
ffa15401 |
733 | my ( $self, $c ) = @_; |
61cfdd57 |
734 | $c->res->output('Congratulations, [% class %] is on Catalyst!'); |
5a8ed4fe |
735 | } |
fc7ec1d9 |
736 | |
61cfdd57 |
737 | [% END %] |
fc7ec1d9 |
738 | =head1 NAME |
739 | |
61cfdd57 |
740 | [% class %] - A Component |
fc7ec1d9 |
741 | |
742 | =head1 SYNOPSIS |
743 | |
744 | Very simple to use |
745 | |
746 | =head1 DESCRIPTION |
747 | |
748 | Very nice component. |
749 | |
750 | =head1 AUTHOR |
751 | |
752 | Clever guy |
753 | |
754 | =head1 LICENSE |
755 | |
b160463f |
756 | This library is free software . You can redistribute it and/or modify |
757 | it under the same terms as perl itself. |
fc7ec1d9 |
758 | |
759 | =cut |
760 | |
761 | 1; |
fc7ec1d9 |
762 | |
61cfdd57 |
763 | __comptest__ |
764 | [% IF type == 'C' %] |
fc7ec1d9 |
765 | use Test::More tests => 3; |
61cfdd57 |
766 | use_ok( Catalyst::Test, '[% app %]' ); |
767 | use_ok('[% class %]'); |
fc7ec1d9 |
768 | |
61cfdd57 |
769 | ok( request('[% prefix %]')->is_success ); |
770 | [% ELSE %] |
fc7ec1d9 |
771 | use Test::More tests => 1; |
61cfdd57 |
772 | use_ok('[% class %]'); |
773 | [% END %] |