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