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