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