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