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'} |
68 | || @{ [ getpwuid($<) ] }[6]; |
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'} |
96 | || @{ [ getpwuid($<) ] }[6]; |
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; |
110 | my $name = shift; |
111 | my $helper = shift; |
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 | |
4f6748f1 |
447 | __build__ |
448 | use strict; |
449 | use Catalyst::Build; |
450 | |
451 | my $build = Catalyst::Build->new( |
452 | create_makefile_pl => 'passthrough', |
453 | license => 'perl', |
454 | module_name => '[% name %]', |
809fd1e0 |
455 | requires => { Catalyst => '5.10' }, |
4f6748f1 |
456 | script_files => [ glob('script/*') ], |
457 | test_files => [ glob('t/*.t'), glob('t/*/*.t') ] |
fc7ec1d9 |
458 | ); |
4f6748f1 |
459 | $build->create_build_script; |
fc7ec1d9 |
460 | |
61cfdd57 |
461 | __readme__ |
4f6748f1 |
462 | Run script/[% apprefix %]_server.pl to test the application. |
91864987 |
463 | |
61cfdd57 |
464 | __changes__ |
7a870961 |
465 | This file documents the revision history for Perl extension [% name %]. |
91864987 |
466 | |
61cfdd57 |
467 | 0.01 [% time %] |
91864987 |
468 | - initial revision, generated by Catalyst |
91864987 |
469 | |
61cfdd57 |
470 | __apptest__ |
fc7ec1d9 |
471 | use Test::More tests => 2; |
61cfdd57 |
472 | use_ok( Catalyst::Test, '[% name %]' ); |
fc7ec1d9 |
473 | |
474 | ok( request('/')->is_success ); |
61cfdd57 |
475 | |
476 | __podtest__ |
5a8fd7e9 |
477 | use Test::More; |
478 | |
479 | eval "use Test::Pod 1.14"; |
61cfdd57 |
480 | plan skip_all => 'Test::Pod 1.14 required' if $@; |
481 | plan skip_all => 'set TEST_POD to enable this test' unless $ENV{TEST_POD}; |
5a8fd7e9 |
482 | |
483 | all_pod_files_ok(); |
61cfdd57 |
484 | |
485 | __podcoveragetest__ |
1df125c9 |
486 | use Test::More; |
487 | |
488 | eval "use Test::Pod::Coverage 1.04"; |
61cfdd57 |
489 | plan skip_all => 'Test::Pod::Coverage 1.04 required' if $@; |
490 | plan skip_all => 'set TEST_POD to enable this test' unless $ENV{TEST_POD}; |
1df125c9 |
491 | |
492 | all_pod_coverage_ok(); |
fc7ec1d9 |
493 | |
195631f4 |
494 | __cgi__ |
61cfdd57 |
495 | [% startperl %] -w |
496 | BEGIN { $ENV{CATALYST_ENGINE} = 'CGI' } |
d8ab1b45 |
497 | |
498 | use strict; |
499 | use FindBin; |
61cfdd57 |
500 | use lib "$FindBin::Bin/../lib"; |
501 | use [% name %]; |
d8ab1b45 |
502 | |
61cfdd57 |
503 | [% name %]->run; |
d8ab1b45 |
504 | |
505 | 1; |
d8ab1b45 |
506 | |
507 | =head1 NAME |
508 | |
509 | cgi - Catalyst CGI |
510 | |
511 | =head1 SYNOPSIS |
512 | |
513 | See L<Catalyst::Manual> |
514 | |
515 | =head1 DESCRIPTION |
516 | |
517 | Run a Catalyst application as cgi. |
518 | |
519 | =head1 AUTHOR |
520 | |
61cfdd57 |
521 | Sebastian Riedel, C<sri@oook.de> |
d8ab1b45 |
522 | |
523 | =head1 COPYRIGHT |
524 | |
525 | Copyright 2004 Sebastian Riedel. All rights reserved. |
526 | |
b160463f |
527 | This library is free software. You can redistribute it and/or modify |
528 | it under the same terms as perl itself. |
d8ab1b45 |
529 | |
530 | =cut |
d8ab1b45 |
531 | |
61cfdd57 |
532 | __fcgi__ |
533 | [% startperl %] -w |
cb8d90e5 |
534 | |
61cfdd57 |
535 | BEGIN { $ENV{CATALYST_ENGINE} = 'FCGI' } |
cb8d90e5 |
536 | |
537 | use strict; |
538 | use FindBin; |
61cfdd57 |
539 | use lib "$FindBin::Bin/../lib"; |
540 | use [% name %]; |
cb8d90e5 |
541 | |
61cfdd57 |
542 | [% name %]->run; |
cb8d90e5 |
543 | |
544 | 1; |
cb8d90e5 |
545 | |
546 | =head1 NAME |
547 | |
548 | fcgi - Catalyst FCGI |
549 | |
550 | =head1 SYNOPSIS |
551 | |
552 | See L<Catalyst::Manual> |
553 | |
554 | =head1 DESCRIPTION |
555 | |
556 | Run a Catalyst application as fcgi. |
557 | |
558 | =head1 AUTHOR |
559 | |
61cfdd57 |
560 | Sebastian Riedel, C<sri@oook.de> |
cb8d90e5 |
561 | |
562 | =head1 COPYRIGHT |
563 | |
564 | Copyright 2004 Sebastian Riedel. All rights reserved. |
565 | |
b160463f |
566 | This library is free software. You can redistribute it and/or modify |
567 | it under the same terms as perl itself. |
cb8d90e5 |
568 | |
569 | =cut |
cb8d90e5 |
570 | |
61cfdd57 |
571 | __server__ |
572 | [% startperl %] -w |
fc7ec1d9 |
573 | |
42a57832 |
574 | BEGIN { |
575 | $ENV{CATALYST_ENGINE} = 'HTTP'; |
576 | $ENV{CATALYST_SCRIPT_GEN} = [% scriptgen %]; |
577 | } |
585893b9 |
578 | |
fc7ec1d9 |
579 | use strict; |
580 | use Getopt::Long; |
581 | use Pod::Usage; |
582 | use FindBin; |
61cfdd57 |
583 | use lib "$FindBin::Bin/../lib"; |
584 | use [% name %]; |
fc7ec1d9 |
585 | |
61cfdd57 |
586 | my $help = 0; |
587 | my $port = 3000; |
fc7ec1d9 |
588 | |
61cfdd57 |
589 | GetOptions( 'help|?' => \$help, 'port=s' => \$port ); |
fc7ec1d9 |
590 | |
195631f4 |
591 | pod2usage(1) if $help; |
fc7ec1d9 |
592 | |
61cfdd57 |
593 | [% name %]->run($port); |
fc7ec1d9 |
594 | |
595 | 1; |
fc7ec1d9 |
596 | |
597 | =head1 NAME |
598 | |
599 | server - Catalyst Testserver |
600 | |
601 | =head1 SYNOPSIS |
602 | |
91864987 |
603 | server.pl [options] |
fc7ec1d9 |
604 | |
605 | Options: |
ad41e777 |
606 | -? -help display this help and exits |
607 | -p -port port (defaults to 3000) |
fc7ec1d9 |
608 | |
03a53815 |
609 | See also: |
610 | perldoc Catalyst::Manual |
611 | perldoc Catalyst::Manual::Intro |
612 | |
fc7ec1d9 |
613 | =head1 DESCRIPTION |
614 | |
615 | Run a Catalyst Testserver for this application. |
616 | |
617 | =head1 AUTHOR |
618 | |
61cfdd57 |
619 | Sebastian Riedel, C<sri@oook.de> |
fc7ec1d9 |
620 | |
621 | =head1 COPYRIGHT |
622 | |
623 | Copyright 2004 Sebastian Riedel. All rights reserved. |
624 | |
b160463f |
625 | This library is free software. You can redistribute it and/or modify |
626 | it under the same terms as perl itself. |
fc7ec1d9 |
627 | |
628 | =cut |
fc7ec1d9 |
629 | |
61cfdd57 |
630 | __test__ |
631 | [% startperl %] -w |
fc7ec1d9 |
632 | |
61cfdd57 |
633 | BEGIN { $ENV{CATALYST_ENGINE} = 'Test' } |
e646f111 |
634 | |
fc7ec1d9 |
635 | use strict; |
636 | use Getopt::Long; |
637 | use Pod::Usage; |
638 | use FindBin; |
61cfdd57 |
639 | use lib "$FindBin::Bin/../lib"; |
640 | use [% name %]; |
fc7ec1d9 |
641 | |
61cfdd57 |
642 | my $help = 0; |
fc7ec1d9 |
643 | |
61cfdd57 |
644 | GetOptions( 'help|?' => \$help ); |
fc7ec1d9 |
645 | |
61cfdd57 |
646 | pod2usage(1) if ( $help || !$ARGV[0] ); |
fc7ec1d9 |
647 | |
61cfdd57 |
648 | print [% name %]->run($ARGV[0])->content . "\n"; |
fc7ec1d9 |
649 | |
650 | 1; |
fc7ec1d9 |
651 | |
652 | =head1 NAME |
653 | |
654 | test - Catalyst Test |
655 | |
656 | =head1 SYNOPSIS |
657 | |
91864987 |
658 | test.pl [options] uri |
fc7ec1d9 |
659 | |
660 | Options: |
661 | -help display this help and exits |
662 | |
663 | Examples: |
91864987 |
664 | test.pl http://localhost/some_action |
665 | test.pl /some_action |
fc7ec1d9 |
666 | |
03a53815 |
667 | See also: |
668 | perldoc Catalyst::Manual |
669 | perldoc Catalyst::Manual::Intro |
670 | |
fc7ec1d9 |
671 | =head1 DESCRIPTION |
672 | |
673 | Run a Catalyst action from the comand line. |
674 | |
675 | =head1 AUTHOR |
676 | |
61cfdd57 |
677 | Sebastian Riedel, C<sri@oook.de> |
fc7ec1d9 |
678 | |
679 | =head1 COPYRIGHT |
680 | |
681 | Copyright 2004 Sebastian Riedel. All rights reserved. |
682 | |
b160463f |
683 | This library is free software. You can redistribute it and/or modify |
684 | it under the same terms as perl itself. |
fc7ec1d9 |
685 | |
686 | =cut |
fc7ec1d9 |
687 | |
61cfdd57 |
688 | __create__ |
689 | [% startperl %] -w |
fc7ec1d9 |
690 | |
691 | use strict; |
692 | use Getopt::Long; |
693 | use Pod::Usage; |
694 | use Catalyst::Helper; |
695 | |
61cfdd57 |
696 | my $help = 0; |
fc7ec1d9 |
697 | |
698 | GetOptions( 'help|?' => \$help ); |
699 | |
61cfdd57 |
700 | pod2usage(1) if ( $help || !$ARGV[0] ); |
fc7ec1d9 |
701 | |
61cfdd57 |
702 | my $helper = Catalyst::Helper->new; |
703 | pod2usage(1) unless $helper->mk_component( '[% name %]', @ARGV ); |
fc7ec1d9 |
704 | |
705 | 1; |
fc7ec1d9 |
706 | |
707 | =head1 NAME |
708 | |
709 | create - Create a new Catalyst Component |
710 | |
711 | =head1 SYNOPSIS |
712 | |
91864987 |
713 | create.pl [options] model|view|controller name [helper] [options] |
fc7ec1d9 |
714 | |
715 | Options: |
716 | -help display this help and exits |
717 | |
718 | Examples: |
91864987 |
719 | create.pl controller My::Controller |
720 | create.pl view My::View |
721 | create.pl view MyView TT |
722 | create.pl view TT TT |
723 | create.pl model My::Model |
724 | create.pl model SomeDB CDBI dbi:SQLite:/tmp/my.db |
725 | create.pl model AnotherDB CDBI dbi:Pg:dbname=foo root 4321 |
b5524568 |
726 | create.pl Ajax |
03a53815 |
727 | |
728 | See also: |
729 | perldoc Catalyst::Manual |
730 | perldoc Catalyst::Manual::Intro |
fc7ec1d9 |
731 | |
732 | =head1 DESCRIPTION |
733 | |
734 | Create a new Catalyst Component. |
735 | |
736 | =head1 AUTHOR |
737 | |
738 | Sebastian Riedel, C<sri\@oook.de> |
739 | |
740 | =head1 COPYRIGHT |
741 | |
742 | Copyright 2004 Sebastian Riedel. All rights reserved. |
743 | |
b160463f |
744 | This library is free software. You can redistribute it and/or modify |
745 | it under the same terms as perl itself. |
fc7ec1d9 |
746 | |
747 | =cut |
fc7ec1d9 |
748 | |
61cfdd57 |
749 | __compclass__ |
750 | package [% class %]; |
751 | |
752 | use strict; |
753 | use base 'Catalyst::Base'; |
fc7ec1d9 |
754 | |
61cfdd57 |
755 | [% IF type == 'C' %] |
5a8ed4fe |
756 | sub default : Private { |
ffa15401 |
757 | my ( $self, $c ) = @_; |
61cfdd57 |
758 | $c->res->output('Congratulations, [% class %] is on Catalyst!'); |
5a8ed4fe |
759 | } |
fc7ec1d9 |
760 | |
61cfdd57 |
761 | [% END %] |
fc7ec1d9 |
762 | =head1 NAME |
763 | |
61cfdd57 |
764 | [% class %] - A Component |
fc7ec1d9 |
765 | |
766 | =head1 SYNOPSIS |
767 | |
768 | Very simple to use |
769 | |
770 | =head1 DESCRIPTION |
771 | |
772 | Very nice component. |
773 | |
774 | =head1 AUTHOR |
775 | |
ddb46924 |
776 | [%author%] |
fc7ec1d9 |
777 | |
778 | =head1 LICENSE |
779 | |
b160463f |
780 | This library is free software . You can redistribute it and/or modify |
781 | it under the same terms as perl itself. |
fc7ec1d9 |
782 | |
783 | =cut |
784 | |
785 | 1; |
fc7ec1d9 |
786 | |
61cfdd57 |
787 | __comptest__ |
788 | [% IF type == 'C' %] |
fc7ec1d9 |
789 | use Test::More tests => 3; |
61cfdd57 |
790 | use_ok( Catalyst::Test, '[% app %]' ); |
791 | use_ok('[% class %]'); |
fc7ec1d9 |
792 | |
61cfdd57 |
793 | ok( request('[% prefix %]')->is_success ); |
794 | [% ELSE %] |
fc7ec1d9 |
795 | use Test::More tests => 1; |
61cfdd57 |
796 | use_ok('[% class %]'); |
797 | [% END %] |