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