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