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