Added first welcome screen mockup
[catagits/Catalyst-Runtime.git] / lib / Catalyst / Helper.pm
1 package Catalyst::Helper;
2
3 use strict;
4 use base 'Class::Accessor::Fast';
5 use Config;
6 use File::Spec;
7 use File::Path;
8 use IO::File;
9 use FindBin;
10 use Template;
11 use Catalyst;
12 use Catalyst::Exception;
13
14 my %cache;
15
16 =head1 NAME
17
18 Catalyst::Helper - Bootstrap a Catalyst application
19
20 =head1 SYNOPSIS
21
22 See L<Catalyst::Manual::Intro>
23
24 =head1 DESCRIPTION
25
26 Bootstrap a Catalyst application. Autogenerates scripts
27
28 =head2 METHODS
29
30 =head3 get_file
31
32 Slurp file from DATA.
33
34 =cut
35
36 sub 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 /^__(.+)__\r?\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
52 =head3 mk_app
53
54 Create the main application skeleton.
55
56 =cut
57
58 sub 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;
64     $self->{appprefix} = lc $self->{dir};
65     $self->{appprefix} =~ s/-/_/g;
66     $self->{startperl} = $Config{startperl};
67     $self->{scriptgen} = $Catalyst::CATALYST_SCRIPT_GEN || 4;
68     $self->{author}    = $self->{author} = $ENV{'AUTHOR'}
69       || eval { @{ [ getpwuid($<) ] }[6] }
70       || 'Catalyst developer';
71     $self->_mk_dirs;
72     $self->_mk_appclass;
73     $self->_mk_build;
74     $self->_mk_makefile;
75     $self->_mk_readme;
76     $self->_mk_changes;
77     $self->_mk_apptest;
78     $self->_mk_cgi;
79     $self->_mk_fastcgi;
80     $self->_mk_server;
81     $self->_mk_test;
82     $self->_mk_create;
83     return 1;
84 }
85
86 =head3 mk_component
87
88 This method is called by create.pl to make new components
89 for your application.
90
91 =cut
92
93 sub mk_component {
94     my $self = shift;
95     my $app  = shift;
96     $self->{app} = $app;
97     $self->{author} = $self->{author} = $ENV{'AUTHOR'}
98       || eval { @{ [ getpwuid($<) ] }[6] }
99       || 'A clever guy';
100     $self->{base} = File::Spec->catdir( $FindBin::Bin, '..' );
101     unless ( $_[0] =~ /^(?:model|m|view|v|controller|c)$/i ) {
102         my $helper = shift;
103         my @args   = @_;
104         my $class  = "Catalyst::Helper::$helper";
105         eval "require $class";
106
107         if ($@) {
108             Catalyst::Exception->throw(
109                 message => qq/Couldn't load helper "$class", "$@"/ );
110         }
111
112         if ( $class->can('mk_stuff') ) {
113             return 1 unless $class->mk_stuff( $self, @args );
114         }
115     }
116     else {
117         my $type   = shift;
118         my $name   = shift || "Missing name for model/view/controller";
119         my $helper = shift;
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 );
138             mkpath [$path];
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";
154
155             if ($@) {
156                 Catalyst::Exception->throw(
157                     message => qq/Couldn't load helper "$class", "$@"/ );
158             }
159
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         }
176     }
177     return 1;
178 }
179
180 =head3 mk_dir
181
182 Surprisingly, this function makes a directory.
183
184 =cut
185
186 sub mk_dir {
187     my ( $self, $dir ) = @_;
188     if ( -d $dir ) {
189         print qq/ exists "$dir"\n/;
190         return 0;
191     }
192     if ( mkpath [$dir] ) {
193         print qq/created "$dir"\n/;
194         return 1;
195     }
196
197     Catalyst::Exception->throw( message => qq/Couldn't create "$dir", "$!"/ );
198 }
199
200 =head3 mk_file
201
202 writes content to a file.
203
204 =cut
205
206 sub mk_file {
207     my ( $self, $file, $content ) = @_;
208     if ( -e $file ) {
209         print qq/ exists "$file"\n/;
210         return 0 unless $self->{'.newfiles'};
211         if ( my $f = IO::File->new("< $file") ) {
212             my $oldcontent = join( '', (<$f>) );
213             return 0 if $content eq $oldcontent;
214         }
215         $file .= '.new';
216     }
217     if ( my $f = IO::File->new("> $file") ) {
218         print $f $content;
219         print qq/created "$file"\n/;
220         return 1;
221     }
222
223     Catalyst::Exception->throw( message => qq/Couldn't create "$file", "$!"/ );
224 }
225
226 =head3 next_test
227
228 =cut
229
230 sub next_test {
231     my ( $self, $tname ) = @_;
232     if ($tname) { $tname = "$tname.t" }
233     else {
234         my $name   = $self->{name};
235         my $prefix = $name;
236         $prefix =~ s/::/-/g;
237         $prefix         = $prefix;
238         $tname          = $prefix . '.t';
239         $self->{prefix} = $prefix;
240         $prefix         = lc $prefix;
241         $prefix =~ s/-/\//g;
242         $self->{uri} = $prefix;
243     }
244     my $dir  = $self->{test_dir};
245     my $type = $self->{type};
246     return File::Spec->catfile( $dir, $type, $tname );
247 }
248
249 =head3 render_file
250
251 Render and create a file from a template in DATA using 
252 Template Toolkit.
253
254 =cut
255
256 sub 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;
263     $t->process( \$template, { %{$self}, %$vars }, \$output )
264       || Catalyst::Exception->throw(
265         message => qq/Couldn't process "$file", / . $t->error() );
266     $self->mk_file( $path, $output );
267 }
268
269 sub _mk_dirs {
270     my $self = shift;
271     $self->mk_dir( $self->{dir} );
272     $self->{script} = File::Spec->catdir( $self->{dir}, 'script' );
273     $self->mk_dir( $self->{script} );
274     $self->{lib} = File::Spec->catdir( $self->{dir}, 'lib' );
275     $self->mk_dir( $self->{lib} );
276     $self->{root} = File::Spec->catdir( $self->{dir}, 'root' );
277     $self->mk_dir( $self->{root} );
278     $self->{t} = File::Spec->catdir( $self->{dir}, 't' );
279     $self->mk_dir( $self->{t} );
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' ) );
283     $self->{class} = File::Spec->catdir( split( /\:\:/, $self->{name} ) );
284     $self->{mod} = File::Spec->catdir( $self->{lib}, $self->{class} );
285     $self->mk_dir( $self->{mod} );
286     $self->{m} = File::Spec->catdir( $self->{mod}, 'M' );
287     $self->mk_dir( $self->{m} );
288     $self->{v} = File::Spec->catdir( $self->{mod}, 'V' );
289     $self->mk_dir( $self->{v} );
290     $self->{c} = File::Spec->catdir( $self->{mod}, 'C' );
291     $self->mk_dir( $self->{c} );
292     $self->{base} = File::Spec->rel2abs( $self->{dir} );
293 }
294
295 sub _mk_appclass {
296     my $self = shift;
297     my $mod  = $self->{mod};
298     $self->render_file( 'appclass', "$mod.pm" );
299 }
300
301 sub _mk_build {
302     my $self = shift;
303     my $dir  = $self->{dir};
304     $self->render_file( 'build', "$dir\/Build.PL" );
305 }
306
307 sub _mk_makefile {
308     my $self = shift;
309     my $dir  = $self->{dir};
310     $self->render_file( 'makefile', "$dir\/Makefile.PL" );
311 }
312
313 sub _mk_readme {
314     my $self = shift;
315     my $dir  = $self->{dir};
316     $self->render_file( 'readme', "$dir\/README" );
317 }
318
319 sub _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
326 sub _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
334 sub _mk_cgi {
335     my $self      = shift;
336     my $script    = $self->{script};
337     my $appprefix = $self->{appprefix};
338     $self->render_file( 'cgi', "$script\/$appprefix\_cgi.pl" );
339     chmod 0700, "$script/$appprefix\_cgi.pl";
340 }
341
342 sub _mk_fastcgi {
343     my $self      = shift;
344     my $script    = $self->{script};
345     my $appprefix = $self->{appprefix};
346     $self->render_file( 'fastcgi', "$script\/$appprefix\_fastcgi.pl" );
347     chmod 0700, "$script/$appprefix\_fastcgi.pl";
348 }
349
350 sub _mk_server {
351     my $self      = shift;
352     my $script    = $self->{script};
353     my $appprefix = $self->{appprefix};
354     $self->render_file( 'server', "$script\/$appprefix\_server.pl" );
355     chmod 0700, "$script/$appprefix\_server.pl";
356 }
357
358 sub _mk_test {
359     my $self      = shift;
360     my $script    = $self->{script};
361     my $appprefix = $self->{appprefix};
362     $self->render_file( 'test', "$script/$appprefix\_test.pl" );
363     chmod 0700, "$script/$appprefix\_test.pl";
364 }
365
366 sub _mk_create {
367     my $self      = shift;
368     my $script    = $self->{script};
369     my $appprefix = $self->{appprefix};
370     $self->render_file( 'create', "$script\/$appprefix\_create.pl" );
371     chmod 0700, "$script/$appprefix\_create.pl";
372 }
373
374 sub _mk_compclass {
375     my $self = shift;
376     my $file = $self->{file};
377     return $self->render_file( 'compclass', "$file" );
378 }
379
380 sub _mk_comptest {
381     my $self = shift;
382     my $test = $self->{test};
383     $self->render_file( 'comptest', "$test" );
384 }
385
386 =head1 HELPERS
387
388 Helpers are classes that provide two methods.
389
390     * mk_compclass - creates the Component class
391     * mk_comptest  - creates the Component test
392
393 So when you call C<bin/create view MyView TT>, create would try to execute
394 Catalyst::Helper::View::TT->mk_compclass and
395 Catalyst::Helper::View::TT->mk_comptest.
396
397 See L<Catalyst::Helper::View::TT> and L<Catalyst::Helper::Model::CDBI> for
398 examples.
399
400 All helper classes should be under one of the following namespaces.
401
402     Catalyst::Helper::Model::
403     Catalyst::Helper::View::
404     Catalyst::Helper::Controller::
405
406 =head1 NOTE
407
408 The helpers will read author name from /etc/passwd by default.
409 To override, please export the AUTHOR variable.
410
411 =head1 SEE ALSO
412
413 L<Catalyst::Manual>, L<Catalyst::Test>, L<Catalyst::Request>,
414 L<Catalyst::Response>, L<Catalyst>
415
416 =head1 AUTHOR
417
418 Sebastian Riedel, C<sri@oook.de>
419
420 =head1 LICENSE
421
422 This library is free software . You can redistribute it and/or modify
423 it under the same terms as perl itself.
424
425 =cut
426
427 1;
428 __DATA__
429
430 __appclass__
431 package [% name %];
432
433 use strict;
434 use Catalyst qw/-Debug/;
435
436 our $VERSION = '0.01';
437
438 [% name %]->config( name => '[% name %]' );
439
440 [% name %]->setup;
441
442 =head1 NAME
443
444 [% name %] - Catalyst based application
445
446 =head1 SYNOPSIS
447
448     script/[% appprefix %]_server.pl
449
450 =head1 DESCRIPTION
451
452 Catalyst based application.
453
454 =head1 METHODS
455
456 =over 4
457
458 =item default
459
460 =cut
461
462 sub default : Private {
463     my ( $self, $c ) = @_;
464
465     # Hello World
466     $c->response->output( $c->welcome_message );
467 }
468
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
480 =back
481
482 =head1 AUTHOR
483
484 [% author %]
485
486 =head1 LICENSE
487
488 This library is free software . You can redistribute it and/or modify
489 it under the same terms as perl itself.
490
491 =cut
492
493 1;
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' );
524 __build__
525 use strict;
526 use Catalyst::Build;
527
528 my $build = Catalyst::Build->new(
529     create_makefile_pl => 'passthrough',
530     license            => 'perl',
531     module_name        => '[% name %]',
532     requires           => { Catalyst => '5.10' },
533     create_makefile_pl => 'passthrough',
534     script_files       => [ glob('script/*') ],
535     test_files         => [ glob('t/*.t'), glob('t/*/*.t') ]
536 );
537 $build->create_build_script;
538 __readme__
539 Run script/[% appprefix %]_server.pl to test the application.
540 __changes__
541 This file documents the revision history for Perl extension [% name %].
542 0.01  [% time %]
543         - initial revision, generated by Catalyst
544 __apptest__
545 use Test::More tests => 2;
546 use_ok( Catalyst::Test, '[% name %]' );
547
548 ok( request('/')->is_success );
549 __podtest__
550 use Test::More;
551
552 eval "use Test::Pod 1.14";
553 plan skip_all => 'Test::Pod 1.14 required' if $@;
554 plan skip_all => 'set TEST_POD to enable this test' unless $ENV{TEST_POD};
555
556 all_pod_files_ok();
557 __podcoveragetest__
558 use Test::More;
559
560 eval "use Test::Pod::Coverage 1.04";
561 plan skip_all => 'Test::Pod::Coverage 1.04 required' if $@;
562 plan skip_all => 'set TEST_POD to enable this test' unless $ENV{TEST_POD};
563
564 all_pod_coverage_ok();
565 __cgi__
566 [% startperl %] -w
567
568 BEGIN { $ENV{CATALYST_ENGINE} ||= 'CGI' }
569
570 use strict;
571 use FindBin;
572 use lib "$FindBin::Bin/../lib";
573 use [% name %];
574
575 [% name %]->run;
576
577 1;
578
579 =head1 NAME
580
581 [% appprefix %]_cgi.pl - Catalyst CGI
582
583 =head1 SYNOPSIS
584
585 See L<Catalyst::Manual>
586
587 =head1 DESCRIPTION
588
589 Run a Catalyst application as cgi.
590
591 =head1 AUTHOR
592
593 Sebastian Riedel, C<sri@oook.de>
594
595 =head1 COPYRIGHT
596
597 Copyright 2004 Sebastian Riedel. All rights reserved.
598
599 This library is free software. You can redistribute it and/or modify
600 it under the same terms as perl itself.
601
602 =cut
603 __fastcgi__
604 [% startperl %] -w
605
606 BEGIN { $ENV{CATALYST_ENGINE} ||= 'FastCGI' }
607
608 use strict;
609 use FindBin;
610 use lib "$FindBin::Bin/../lib";
611 use [% name %];
612
613 [% name %]->run;
614
615 1;
616
617 =head1 NAME
618
619 [% appprefix %]_fastcgi.pl - Catalyst FastCGI
620
621 =head1 SYNOPSIS
622
623 See L<Catalyst::Manual>
624
625 =head1 DESCRIPTION
626
627 Run a Catalyst application as fastcgi.
628
629 =head1 AUTHOR
630
631 Sebastian Riedel, C<sri@oook.de>
632
633 =head1 COPYRIGHT
634
635 Copyright 2004 Sebastian Riedel. All rights reserved.
636
637 This library is free software. You can redistribute it and/or modify
638 it under the same terms as perl itself.
639
640 =cut
641 __server__
642 [% startperl %] -w
643
644 BEGIN { 
645     $ENV{CATALYST_ENGINE} ||= 'HTTP';
646     $ENV{CATALYST_SCRIPT_GEN} = [% scriptgen %];
647 }  
648
649 use strict;
650 use Getopt::Long;
651 use Pod::Usage;
652 use FindBin;
653 use lib "$FindBin::Bin/../lib";
654 use [% name %];
655
656 my $fork          = 0;
657 my $help          = 0;
658 my $host          = undef;
659 my $port          = 3000;
660 my $restart       = 0;
661 my $restart_delay = 1;
662 my $restart_regex = '\.yml$|\.yaml$|\.pm$';
663
664 my @argv = @ARGV;
665
666 GetOptions(
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
674 );
675
676 pod2usage(1) if $help;
677
678 [% name %]->run( $port, $host, {
679     argv   => \@argv,
680     'fork' => $fork,
681     restart => $restart,
682     restart_delay => $restart_delay,
683     restart_regex => qr/$restart_regex/
684 } );
685
686 1;
687
688 =head1 NAME
689
690 [% appprefix %]_server.pl - Catalyst Testserver
691
692 =head1 SYNOPSIS
693
694 [% appprefix %]_server.pl [options]
695
696  Options:
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$')
708
709  See also:
710    perldoc Catalyst::Manual
711    perldoc Catalyst::Manual::Intro
712
713 =head1 DESCRIPTION
714
715 Run a Catalyst Testserver for this application.
716
717 =head1 AUTHOR
718
719 Sebastian Riedel, C<sri@oook.de>
720
721 =head1 COPYRIGHT
722
723 Copyright 2004 Sebastian Riedel. All rights reserved.
724
725 This library is free software. You can redistribute it and/or modify
726 it under the same terms as perl itself.
727
728 =cut
729 __test__
730 [% startperl %] -w
731
732 BEGIN { $ENV{CATALYST_ENGINE} ||= 'Test' }
733
734 use strict;
735 use Getopt::Long;
736 use Pod::Usage;
737 use FindBin;
738 use lib "$FindBin::Bin/../lib";
739 use [% name %];
740
741 my $help = 0;
742
743 GetOptions( 'help|?' => \$help );
744
745 pod2usage(1) if ( $help || !$ARGV[0] );
746
747 print [% name %]->run($ARGV[0])->content . "\n";
748
749 1;
750
751 =head1 NAME
752
753 [% appprefix %]_test.pl - Catalyst Test
754
755 =head1 SYNOPSIS
756
757 [% appprefix %]_test.pl [options] uri
758
759  Options:
760    -help    display this help and exits
761
762  Examples:
763    [% appprefix %]_test.pl http://localhost/some_action
764    [% appprefix %]_test.pl /some_action
765
766  See also:
767    perldoc Catalyst::Manual
768    perldoc Catalyst::Manual::Intro
769
770 =head1 DESCRIPTION
771
772 Run a Catalyst action from the command line.
773
774 =head1 AUTHOR
775
776 Sebastian Riedel, C<sri@oook.de>
777
778 =head1 COPYRIGHT
779
780 Copyright 2004 Sebastian Riedel. All rights reserved.
781
782 This library is free software. You can redistribute it and/or modify
783 it under the same terms as perl itself.
784
785 =cut
786 __create__
787 [% startperl %] -w
788
789 use strict;
790 use Getopt::Long;
791 use Pod::Usage;
792 use Catalyst::Helper;
793
794 my $help = 0;
795 my $nonew = 0;
796
797 GetOptions( 'help|?' => \$help,
798             'nonew'  => \$nonew );
799
800 pod2usage(1) if ( $help || !$ARGV[0] );
801
802 my $helper = Catalyst::Helper->new({'.newfiles' => !$nonew});
803 pod2usage(1) unless $helper->mk_component( '[% name %]', @ARGV );
804
805 1;
806
807 =head1 NAME
808
809 [% appprefix %]_create.pl - Create a new Catalyst Component
810
811 =head1 SYNOPSIS
812
813 [% appprefix %]_create.pl [options] model|view|controller name [helper] [options]
814
815  Options:
816    -help    display this help and exits
817    -nonew   don't create a .new file where a file to be created exists
818
819  Examples:
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
827
828  See also:
829    perldoc Catalyst::Manual
830    perldoc Catalyst::Manual::Intro
831
832 =head1 DESCRIPTION
833
834 Create a new Catalyst Component.
835
836 Existing component files are not overwritten.  If any of the component files
837 to be created already exist the file will be written with a '.new' suffix.
838 This behavior can be suppressed with the C<-nonew> option.
839
840 =head1 AUTHOR
841
842 Sebastian Riedel, C<sri\@oook.de>
843
844 =head1 COPYRIGHT
845
846 Copyright 2004 Sebastian Riedel. All rights reserved.
847
848 This library is free software. You can redistribute it and/or modify
849 it under the same terms as perl itself.
850
851 =cut
852 __compclass__
853 package [% class %];
854
855 use strict;
856 use base 'Catalyst::Base';
857
858 =head1 NAME
859
860 [% class %] - Catalyst component
861
862 =head1 SYNOPSIS
863
864 See L<[% app %]>
865
866 =head1 DESCRIPTION
867
868 Catalyst component.
869 [% IF type == 'C' %]
870 =head1 METHODS
871
872 =over 4
873
874 =item default
875
876 =cut
877
878 sub default : Private {
879     my ( $self, $c ) = @_;
880
881     # Hello World
882     $c->response->output('Congratulations, [% class %] is on Catalyst!');
883 }
884
885 =back
886
887 [% END %]
888 =head1 AUTHOR
889
890 [%author%]
891
892 =head1 LICENSE
893
894 This library is free software . You can redistribute it and/or modify
895 it under the same terms as perl itself.
896
897 =cut
898
899 1;
900 __comptest__
901 [% IF type == 'C' %]
902 use Test::More tests => 3;
903 use_ok( Catalyst::Test, '[% app %]' );
904 use_ok('[% class %]');
905
906 ok( request('[% uri %]')->is_success );
907 [% ELSE %]
908 use Test::More tests => 1;
909 use_ok('[% class %]');
910 [% END %]