Added prepare_body_chunk method for upload progress support
[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
466 $c->response->output('Congratulations, [% name %] is on Catalyst!');
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
fbcc39ad 656my $fork = 0;
61cfdd57 657my $help = 0;
fbcc39ad 658my $host = undef;
61cfdd57 659my $port = 3000;
fc7ec1d9 660
fbcc39ad 661GetOptions(
662 'fork' => \$fork,
663 'help|?' => \$help,
664 'host=s' => \$host,
665 'port=s' => \$port
666);
fc7ec1d9 667
195631f4 668pod2usage(1) if $help;
fc7ec1d9 669
fbcc39ad 670[% name %]->run( $port, $host, $fork );
fc7ec1d9 671
6721;
fc7ec1d9 673
674=head1 NAME
675
67308304 676[% appprefix %]_server.pl - Catalyst Testserver
fc7ec1d9 677
678=head1 SYNOPSIS
679
67308304 680[% appprefix %]_server.pl [options]
fc7ec1d9 681
682 Options:
fbcc39ad 683 -f -fork handle each request in a new process
ad41e777 684 -? -help display this help and exits
fbcc39ad 685 -host host (defaults to all)
ad41e777 686 -p -port port (defaults to 3000)
fc7ec1d9 687
03a53815 688 See also:
689 perldoc Catalyst::Manual
690 perldoc Catalyst::Manual::Intro
691
fc7ec1d9 692=head1 DESCRIPTION
693
694Run a Catalyst Testserver for this application.
695
696=head1 AUTHOR
697
61cfdd57 698Sebastian Riedel, C<sri@oook.de>
fc7ec1d9 699
700=head1 COPYRIGHT
701
702Copyright 2004 Sebastian Riedel. All rights reserved.
703
9c48119a 704This library is free software. You can redistribute it and/or modify
b160463f 705it under the same terms as perl itself.
fc7ec1d9 706
707=cut
61cfdd57 708__test__
709[% startperl %] -w
fc7ec1d9 710
5a59ef2a 711BEGIN { $ENV{CATALYST_ENGINE} ||= 'Test' }
712
fc7ec1d9 713use strict;
714use Getopt::Long;
715use Pod::Usage;
716use FindBin;
5a59ef2a 717use lib "$FindBin::Bin/../lib";
61cfdd57 718use [% name %];
fc7ec1d9 719
61cfdd57 720my $help = 0;
fc7ec1d9 721
61cfdd57 722GetOptions( 'help|?' => \$help );
fc7ec1d9 723
61cfdd57 724pod2usage(1) if ( $help || !$ARGV[0] );
fc7ec1d9 725
61cfdd57 726print [% name %]->run($ARGV[0])->content . "\n";
fc7ec1d9 727
7281;
fc7ec1d9 729
730=head1 NAME
731
67308304 732[% appprefix %]_test.pl - Catalyst Test
fc7ec1d9 733
734=head1 SYNOPSIS
735
67308304 736[% appprefix %]_test.pl [options] uri
fc7ec1d9 737
738 Options:
739 -help display this help and exits
740
741 Examples:
67308304 742 [% appprefix %]_test.pl http://localhost/some_action
743 [% appprefix %]_test.pl /some_action
fc7ec1d9 744
03a53815 745 See also:
746 perldoc Catalyst::Manual
747 perldoc Catalyst::Manual::Intro
748
fc7ec1d9 749=head1 DESCRIPTION
750
751Run a Catalyst action from the comand line.
752
753=head1 AUTHOR
754
61cfdd57 755Sebastian Riedel, C<sri@oook.de>
fc7ec1d9 756
757=head1 COPYRIGHT
758
759Copyright 2004 Sebastian Riedel. All rights reserved.
760
9c48119a 761This library is free software. You can redistribute it and/or modify
b160463f 762it under the same terms as perl itself.
fc7ec1d9 763
764=cut
61cfdd57 765__create__
766[% startperl %] -w
fc7ec1d9 767
768use strict;
769use Getopt::Long;
770use Pod::Usage;
771use Catalyst::Helper;
772
61cfdd57 773my $help = 0;
ef3250bc 774my $nonew = 0;
fc7ec1d9 775
ef3250bc 776GetOptions( 'help|?' => \$help,
777 'nonew' => \$nonew );
fc7ec1d9 778
61cfdd57 779pod2usage(1) if ( $help || !$ARGV[0] );
fc7ec1d9 780
ef3250bc 781my $helper = Catalyst::Helper->new({'.newfiles' => !$nonew});
61cfdd57 782pod2usage(1) unless $helper->mk_component( '[% name %]', @ARGV );
fc7ec1d9 783
7841;
fc7ec1d9 785
786=head1 NAME
787
67308304 788[% appprefix %]_create.pl - Create a new Catalyst Component
fc7ec1d9 789
790=head1 SYNOPSIS
791
67308304 792[% appprefix %]_create.pl [options] model|view|controller name [helper] [options]
fc7ec1d9 793
794 Options:
795 -help display this help and exits
ef3250bc 796 -nonew don't create a .new file where a file to be created exists
fc7ec1d9 797
798 Examples:
67308304 799 [% appprefix %]_create.pl controller My::Controller
800 [% appprefix %]_create.pl view My::View
801 [% appprefix %]_create.pl view MyView TT
802 [% appprefix %]_create.pl view TT TT
803 [% appprefix %]_create.pl model My::Model
804 [% appprefix %]_create.pl model SomeDB CDBI dbi:SQLite:/tmp/my.db
805 [% appprefix %]_create.pl model AnotherDB CDBI dbi:Pg:dbname=foo root 4321
03a53815 806
807 See also:
808 perldoc Catalyst::Manual
809 perldoc Catalyst::Manual::Intro
fc7ec1d9 810
811=head1 DESCRIPTION
812
813Create a new Catalyst Component.
814
ef3250bc 815Existing component files are not overwritten. If any of the component files
816to be created already exist the file will be written with a '.new' suffix.
817This behaviour can be supressed with the C<-nonew> option.
818
fc7ec1d9 819=head1 AUTHOR
820
821Sebastian Riedel, C<sri\@oook.de>
822
823=head1 COPYRIGHT
824
825Copyright 2004 Sebastian Riedel. All rights reserved.
826
9c48119a 827This library is free software. You can redistribute it and/or modify
b160463f 828it under the same terms as perl itself.
fc7ec1d9 829
830=cut
61cfdd57 831__compclass__
832package [% class %];
833
834use strict;
835use base 'Catalyst::Base';
fc7ec1d9 836
fc7ec1d9 837=head1 NAME
838
d4bcc27a 839[% class %] - Catalyst component
fc7ec1d9 840
841=head1 SYNOPSIS
842
df8632c6 843See L<[% app %]>
fc7ec1d9 844
845=head1 DESCRIPTION
846
df8632c6 847Catalyst component.
848[% IF type == 'C' %]
849=head1 METHODS
850
444821f7 851=over 4
df8632c6 852
853=item default
fc7ec1d9 854
df8632c6 855=cut
856
857sub default : Private {
858 my ( $self, $c ) = @_;
fbcc39ad 859
860 # Hello World
861 $c->response->output('Congratulations, [% class %] is on Catalyst!');
df8632c6 862}
444821f7 863
864=back
7dcb4831 865
df8632c6 866[% END %]
fc7ec1d9 867=head1 AUTHOR
868
ddb46924 869[%author%]
fc7ec1d9 870
871=head1 LICENSE
872
9c48119a 873This library is free software . You can redistribute it and/or modify
b160463f 874it under the same terms as perl itself.
fc7ec1d9 875
876=cut
877
8781;
61cfdd57 879__comptest__
880[% IF type == 'C' %]
fc7ec1d9 881use Test::More tests => 3;
61cfdd57 882use_ok( Catalyst::Test, '[% app %]' );
883use_ok('[% class %]');
fc7ec1d9 884
3d5bb03e 885ok( request('[% uri %]')->is_success );
61cfdd57 886[% ELSE %]
fc7ec1d9 887use Test::More tests => 1;
61cfdd57 888use_ok('[% class %]');
889[% END %]