clean up pod location and module ends
[catagits/Catalyst-Devel.git] / lib / Catalyst / Helper.pm
CommitLineData
68ccb5e5 1package Catalyst::Helper;
957ccd4d 2use Moose;
68ccb5e5 3use Config;
4use File::Spec;
18b4b23e 5use File::Spec::Unix;
68ccb5e5 6use File::Path;
68ccb5e5 7use FindBin;
2415f774 8use IO::File;
9use POSIX 'strftime';
68ccb5e5 10use Template;
9ffb6b83 11use Catalyst::Devel;
68ccb5e5 12use Catalyst::Utils;
13use Catalyst::Exception;
afd739f1 14use Path::Class qw/dir file/;
15use File::ShareDir qw/dist_dir/;
51f3ab37 16use YAML::Tiny;
957ccd4d 17use namespace::autoclean;
68ccb5e5 18
dcc30470 19with 'MooseX::Emulate::Class::Accessor::Fast';
20
45d58983 21our $VERSION = '1.41';
22d52725 22$VERSION =~ tr/_//d;
efc787e1 23
68ccb5e5 24my %cache;
25
afd739f1 26sub get_sharedir_file {
27 my ($self, @filename) = @_;
1ef88a06 28 my $dist_dir;
4c709311 29 if (exists $ENV{CATALYST_DEVEL_SHAREDIR}) {
1ef88a06 30 $dist_dir = $ENV{CATALYST_DEVEL_SHAREDIR};
4c709311 31 }
1ef88a06 32 elsif (-d "inc/.author" && -f "lib/Catalyst/Helper.pm"
d7ebca0f 33 ) { # Can't use sharedir if we're in a checkout
34 # this feels horrible, better ideas?
1ef88a06 35 $dist_dir = 'share';
76b106bc 36 }
37 else {
1ef88a06 38 $dist_dir = dist_dir('Catalyst-Devel');
76b106bc 39 }
1ef88a06 40 my $file = file( $dist_dir, @filename);
f8d3d4e0 41 Carp::confess("Cannot find $file") unless -r $file;
b728fa3c 42 my $contents = $file->slurp(iomode => "<:raw");
afd739f1 43 return $contents;
44}
45
faae88e5 46# Do not touch this method, *EVER*, it is needed for back compat.
68ccb5e5 47sub get_file {
03082a71 48 my ( $self, $class, $file ) = @_;
49 unless ( $cache{$class} ) {
50 local $/;
51 $cache{$class} = eval "package $class; <DATA>";
52 }
53 my $data = $cache{$class};
0acedf59 54 Carp::confess("Could not get data from __DATA__ segment for $class")
55 unless $data;
03082a71 56 my @files = split /^__(.+)__\r?\n/m, $data;
57 shift @files;
58 while (@files) {
59 my ( $name, $content ) = splice @files, 0, 2;
60 return $content if $name eq $file;
61 }
62 return 0;
68ccb5e5 63}
b4b7c206 64
a73b3971 65
68ccb5e5 66sub mk_app {
fdb9d1d9 67 my ( $self, $name ) = @_;
68ccb5e5 68
69 # Needs to be here for PAR
70 require Catalyst;
71
51f3ab37 72 if($name eq '.') {
73 if(!-e 'META.yml') {
74 system perl => 'Makefile.PL'
75 and Catalyst::Exception->throw(message => q(
76 Failed to run "perl Makefile.PL".
77 ));
78 }
79
80 $name = YAML::Tiny->read('META.yml')->[0]->{'name'};
81 $name =~ s/-/::/g;
82 $self->{dir} = '.';
83 }
84
fdb9d1d9 85 if ( $name =~ /[^\w:]/ || $name =~ /^\d/ || $name =~ /\b:\b|:{3,}/) {
86 warn "Error: Invalid application name.\n";
87 return 0;
88 }
51f3ab37 89
90
91 if(!defined $self->{'dir'}) {
92 $self->{dir} = $name;
93 $self->{dir} =~ s/\:\:/-/g;
94 }
95
fdb9d1d9 96 $self->{name } = $name;
fdb9d1d9 97 $self->{script } = dir( $self->{dir}, 'script' );
98 $self->{appprefix } = Catalyst::Utils::appprefix($name);
99 $self->{appenv } = Catalyst::Utils::class2env($name);
675fef06 100 $self->{startperl } = -r '/usr/bin/env'
101 ? '#!/usr/bin/env perl'
4dc075f9 102 : "#!$Config{perlpath}";
2ad36447 103 $self->{scriptgen } = $Catalyst::Devel::CATALYST_SCRIPT_GEN;
902763f2 104 $self->{catalyst_version} = $Catalyst::VERSION;
a39434ca 105 $self->{author } ||= $ENV{'AUTHOR'}
fdb9d1d9 106 || eval { @{ [ getpwuid($<) ] }[6] }
107 || 'Catalyst developer';
68ccb5e5 108
109 my $gen_scripts = ( $self->{makefile} ) ? 0 : 1;
110 my $gen_makefile = ( $self->{scripts} ) ? 0 : 1;
111 my $gen_app = ( $self->{scripts} || $self->{makefile} ) ? 0 : 1;
112
113 if ($gen_app) {
b769c101 114 for ( qw/ _mk_dirs _mk_config _mk_psgi _mk_appclass _mk_rootclass
115 _mk_readme _mk_changes _mk_apptest _mk_podtest _mk_podcoveragetest
da109dfb 116 _mk_images _mk_favicon/ ) {
fdb9d1d9 117 $self->$_;
420ad692 118 }
68ccb5e5 119 }
120 if ($gen_makefile) {
121 $self->_mk_makefile;
122 }
123 if ($gen_scripts) {
b769c101 124 for ( qw/ _mk_cgi _mk_fastcgi _mk_server
28d172c6 125 _mk_test _mk_create _mk_information
126 / ) {
fdb9d1d9 127 $self->$_;
28d172c6 128 }
68ccb5e5 129 }
fdb9d1d9 130 return $self->{dir};
68ccb5e5 131}
132
b769c101 133## not much of this can really be changed, mk_compclass must be left for
23f9f145 134## backcompat
68ccb5e5 135sub mk_component {
136 my $self = shift;
137 my $app = shift;
138 $self->{app} = $app;
fdb9d1d9 139 $self->{author} = $self->{author} = $ENV{'AUTHOR'}
140 || eval { @{ [ getpwuid($<) ] }[6] }
141 || 'A clever guy';
142 $self->{base} ||= dir( $FindBin::Bin, '..' );
68ccb5e5 143 unless ( $_[0] =~ /^(?:model|view|controller)$/i ) {
144 my $helper = shift;
145 my @args = @_;
146 my $class = "Catalyst::Helper::$helper";
147 eval "require $class";
148
149 if ($@) {
150 Catalyst::Exception->throw(
151 message => qq/Couldn't load helper "$class", "$@"/ );
152 }
153
154 if ( $class->can('mk_stuff') ) {
155 return 1 unless $class->mk_stuff( $self, @args );
156 }
157 }
158 else {
159 my $type = shift;
160 my $name = shift || "Missing name for model/view/controller";
161 my $helper = shift;
162 my @args = @_;
fab70e0a 163 return 0 if $name =~ /[^\w\:]/;
68ccb5e5 164 $type = lc $type;
165 $self->{long_type} = ucfirst $type;
166 $type = 'M' if $type =~ /model/i;
167 $type = 'V' if $type =~ /view/i;
168 $type = 'C' if $type =~ /controller/i;
068587bd 169 my $appdir = dir( split /\:\:/, $app );
68ccb5e5 170 my $test_path =
068587bd 171 dir( $self->{base}, 'lib', $appdir, 'C' );
68ccb5e5 172 $type = $self->{long_type} unless -d $test_path;
173 $self->{type} = $type;
174 $self->{name} = $name;
175 $self->{class} = "$app\::$type\::$name";
176
177 # Class
178 my $path =
068587bd 179 dir( $self->{base}, 'lib', $appdir, $type );
68ccb5e5 180 my $file = $name;
181 if ( $name =~ /\:/ ) {
182 my @path = split /\:\:/, $name;
183 $file = pop @path;
068587bd 184 $path = dir( $path, @path );
68ccb5e5 185 }
186 $self->mk_dir($path);
068587bd 187 $file = file( $path, "$file.pm" );
68ccb5e5 188 $self->{file} = $file;
189
190 # Test
068587bd 191 $self->{test_dir} = dir( $self->{base}, 't' );
68ccb5e5 192 $self->{test} = $self->next_test;
193
194 # Helper
195 if ($helper) {
196 my $comp = $self->{long_type};
197 my $class = "Catalyst::Helper::$comp\::$helper";
198 eval "require $class";
199
200 if ($@) {
201 Catalyst::Exception->throw(
202 message => qq/Couldn't load helper "$class", "$@"/ );
203 }
204
205 if ( $class->can('mk_compclass') ) {
206 return 1 unless $class->mk_compclass( $self, @args );
207 }
20755aa7 208 else {
209 return 1 unless $self->_mk_compclass
210 }
68ccb5e5 211
212 if ( $class->can('mk_comptest') ) {
213 $class->mk_comptest( $self, @args );
214 }
20755aa7 215 else {
216 $self->_mk_comptest
217 }
68ccb5e5 218 }
219
220 # Fallback
221 else {
222 return 1 unless $self->_mk_compclass;
223 $self->_mk_comptest;
224 }
225 }
226 return 1;
227}
228
68ccb5e5 229sub mk_dir {
230 my ( $self, $dir ) = @_;
231 if ( -d $dir ) {
232 print qq/ exists "$dir"\n/;
233 return 0;
234 }
235 if ( mkpath [$dir] ) {
236 print qq/created "$dir"\n/;
237 return 1;
238 }
239
240 Catalyst::Exception->throw( message => qq/Couldn't create "$dir", "$!"/ );
241}
242
68ccb5e5 243sub mk_file {
244 my ( $self, $file, $content ) = @_;
06f62452 245 if ( -e $file && -s _ ) {
68ccb5e5 246 print qq/ exists "$file"\n/;
247 return 0
248 unless ( $self->{'.newfiles'}
249 || $self->{scripts}
250 || $self->{makefile} );
251 if ( $self->{'.newfiles'} ) {
252 if ( my $f = IO::File->new("< $file") ) {
253 my $oldcontent = join( '', (<$f>) );
254 return 0 if $content eq $oldcontent;
255 }
256 $file .= '.new';
257 }
258 }
620dd287 259
68ccb5e5 260 if ( my $f = IO::File->new("> $file") ) {
261 binmode $f;
262 print $f $content;
263 print qq/created "$file"\n/;
b6d89690 264 return $file;
68ccb5e5 265 }
266
267 Catalyst::Exception->throw( message => qq/Couldn't create "$file", "$!"/ );
268}
269
68ccb5e5 270sub next_test {
271 my ( $self, $tname ) = @_;
272 if ($tname) { $tname = "$tname.t" }
273 else {
274 my $name = $self->{name};
275 my $prefix = $name;
276 $prefix =~ s/::/-/g;
277 $prefix = $prefix;
278 $tname = $prefix . '.t';
279 $self->{prefix} = $prefix;
280 $prefix = lc $prefix;
281 $prefix =~ s/-/\//g;
282 $self->{uri} = "/$prefix";
283 }
284 my $dir = $self->{test_dir};
285 my $type = lc $self->{type};
286 $self->mk_dir($dir);
068587bd 287 return file( $dir, "$type\_$tname" );
68ccb5e5 288}
289
faae88e5 290# Do not touch this method, *EVER*, it is needed for back compat.
7025ed89 291## addendum: we had to split this method so we could have backwards
40b26f8b 292## compatibility. otherwise, we'd have no way to pass stuff from __DATA__
faae88e5 293
68ccb5e5 294sub render_file {
b6d89690 295 my ( $self, $file, $path, $vars, $perms ) = @_;
7025ed89 296 my $template = $self->get_file( ( caller(0) )[0], $file );
b6d89690 297 $self->render_file_contents($template, $path, $vars, $perms);
7025ed89 298}
299
300sub render_sharedir_file {
b6d89690 301 my ( $self, $file, $path, $vars, $perms ) = @_;
7025ed89 302 my $template = $self->get_sharedir_file( $file );
f8d3d4e0 303 die("Cannot get template from $file for $self\n") unless $template;
b6d89690 304 $self->render_file_contents($template, $path, $vars, $perms);
7025ed89 305}
306
307sub render_file_contents {
b6d89690 308 my ( $self, $template, $path, $vars, $perms ) = @_;
68ccb5e5 309 $vars ||= {};
310 my $t = Template->new;
68ccb5e5 311 return 0 unless $template;
312 my $output;
313 $t->process( \$template, { %{$self}, %$vars }, \$output )
314 || Catalyst::Exception->throw(
7025ed89 315 message => qq/Couldn't process "$template", / . $t->error() );
b6d89690 316 my $file = $self->mk_file( $path, $output );
47f36ce5 317 chmod $perms, file($file) if defined $perms;
49d5395a 318 return $file;
68ccb5e5 319}
320
45d74601 321sub _mk_information {
322 my $self = shift;
323 print qq/Change to application directory and Run "perl Makefile.PL" to make sure your install is complete\n/;
324}
325
68ccb5e5 326sub _mk_dirs {
327 my $self = shift;
fdb9d1d9 328 $self->mk_dir( $self->{dir} );
329 $self->mk_dir( $self->{script} );
330 $self->{lib} = dir( $self->{dir}, 'lib' );
331 $self->mk_dir( $self->{lib} );
332 $self->{root} = dir( $self->{dir}, 'root' );
333 $self->mk_dir( $self->{root} );
334 $self->{static} = dir( $self->{root}, 'static' );
335 $self->mk_dir( $self->{static} );
336 $self->{images} = dir( $self->{static}, 'images' );
337 $self->mk_dir( $self->{images} );
338 $self->{t} = dir( $self->{dir}, 't' );
339 $self->mk_dir( $self->{t} );
340
341 $self->{class} = dir( split( /\:\:/, $self->{name} ) );
342 $self->{mod} = dir( $self->{lib}, $self->{class} );
343 $self->mk_dir( $self->{mod} );
344
345 if ( $self->{short} ) {
346 $self->{m} = dir( $self->{mod}, 'M' );
347 $self->mk_dir( $self->{m} );
348 $self->{v} = dir( $self->{mod}, 'V' );
349 $self->mk_dir( $self->{v} );
350 $self->{c} = dir( $self->{mod}, 'C' );
351 $self->mk_dir( $self->{c} );
352 }
353 else {
354 $self->{m} = dir( $self->{mod}, 'Model' );
355 $self->mk_dir( $self->{m} );
356 $self->{v} = dir( $self->{mod}, 'View' );
357 $self->mk_dir( $self->{v} );
358 $self->{c} = dir( $self->{mod}, 'Controller' );
359 $self->mk_dir( $self->{c} );
ec62787d 360 }
fdb9d1d9 361 my $name = $self->{name};
362 $self->{rootname} =
363 $self->{short} ? "$name\::C::Root" : "$name\::Controller::Root";
364 $self->{base} = dir( $self->{dir} )->absolute;
68ccb5e5 365}
366
367sub _mk_appclass {
368 my $self = shift;
fdb9d1d9 369 my $mod = $self->{mod};
068587bd 370 $self->render_sharedir_file( file('lib', 'MyApp.pm.tt'), "$mod.pm" );
68ccb5e5 371}
372
373sub _mk_rootclass {
374 my $self = shift;
068587bd 375 $self->render_sharedir_file( file('lib', 'MyApp', 'Controller', 'Root.pm.tt'),
fdb9d1d9 376 file( $self->{c}, "Root.pm" ) );
68ccb5e5 377}
378
379sub _mk_makefile {
380 my $self = shift;
f7cb00cb 381 $self->{path} = join('/', 'lib', split( '::', $self->{name} ) );
68ccb5e5 382 $self->{path} .= '.pm';
fdb9d1d9 383 my $dir = $self->{dir};
384 $self->render_sharedir_file( 'Makefile.PL.tt', file($dir, "Makefile.PL") );
68ccb5e5 385
386 if ( $self->{makefile} ) {
387
388 # deprecate the old Build.PL file when regenerating Makefile.PL
389 $self->_deprecate_file(
fdb9d1d9 390 file( $self->{dir}, 'Build.PL' ) );
68ccb5e5 391 }
392}
393
b769c101 394sub _mk_psgi {
395 my $self = shift;
396 my $dir = $self->{dir};
397 my $appprefix = $self->{appprefix};
398 $self->render_sharedir_file( 'myapp.psgi.tt',
399 file( $dir, "$appprefix.psgi" ) );
400}
401
68ccb5e5 402sub _mk_config {
403 my $self = shift;
fdb9d1d9 404 my $dir = $self->{dir};
405 my $appprefix = $self->{appprefix};
d5ff5c0f 406 $self->render_sharedir_file( 'myapp.conf.tt',
fdb9d1d9 407 file( $dir, "$appprefix.conf" ) );
68ccb5e5 408}
409
410sub _mk_readme {
411 my $self = shift;
fdb9d1d9 412 my $dir = $self->{dir};
413 $self->render_sharedir_file( 'README.tt', file($dir, "README") );
68ccb5e5 414}
415
416sub _mk_changes {
417 my $self = shift;
fdb9d1d9 418 my $dir = $self->{dir};
5b1ec88b 419 my $time = strftime('%Y-%m-%d %H:%M:%S', localtime time);
fdb9d1d9 420 $self->render_sharedir_file( 'Changes.tt', file($dir, "Changes"), { time => $time } );
68ccb5e5 421}
422
423sub _mk_apptest {
424 my $self = shift;
425 my $t = $self->{t};
068587bd 426 $self->render_sharedir_file( file('t', '01app.t.tt'), file($t, "01app.t") );
da109dfb 427}
428
429sub _mk_podtest {
430 my $self = shift;
431 my $t = $self->{t};
068587bd 432 $self->render_sharedir_file( file('t', '02pod.t.tt'), file($t, "02pod.t") );
da109dfb 433}
434
435sub _mk_podcoveragetest {
436 my $self = shift;
437 my $t = $self->{t};
068587bd 438 $self->render_sharedir_file( file('t', '03podcoverage.t.tt'), file($t, "03podcoverage.t") );
68ccb5e5 439}
440
441sub _mk_cgi {
442 my $self = shift;
fdb9d1d9 443 my $script = $self->{script};
444 my $appprefix = $self->{appprefix};
b6d89690 445 $self->render_sharedir_file( file('script', 'myapp_cgi.pl.tt'),
8b0107a5 446 file($script,"$appprefix\_cgi.pl"), undef, 0755 );
68ccb5e5 447}
448
449sub _mk_fastcgi {
450 my $self = shift;
fdb9d1d9 451 my $script = $self->{script};
452 my $appprefix = $self->{appprefix};
b6d89690 453 $self->render_sharedir_file( file('script', 'myapp_fastcgi.pl.tt'),
8b0107a5 454 file($script, "$appprefix\_fastcgi.pl"), undef, 0755 );
68ccb5e5 455}
456
457sub _mk_server {
458 my $self = shift;
fdb9d1d9 459 my $script = $self->{script};
460 my $appprefix = $self->{appprefix};
b6d89690 461 $self->render_sharedir_file( file('script', 'myapp_server.pl.tt'),
8b0107a5 462 file($script, "$appprefix\_server.pl"), undef, 0755 );
68ccb5e5 463}
464
465sub _mk_test {
466 my $self = shift;
fdb9d1d9 467 my $script = $self->{script};
468 my $appprefix = $self->{appprefix};
b6d89690 469 $self->render_sharedir_file( file('script', 'myapp_test.pl.tt'),
8b0107a5 470 file($script, "$appprefix\_test.pl"), undef, 0755 );
68ccb5e5 471}
472
473sub _mk_create {
474 my $self = shift;
fdb9d1d9 475 my $script = $self->{script};
476 my $appprefix = $self->{appprefix};
b6d89690 477 $self->render_sharedir_file( file('script', 'myapp_create.pl.tt'),
8b0107a5 478 file($script, "$appprefix\_create.pl"), undef, 0755 );
68ccb5e5 479}
480
481sub _mk_compclass {
482 my $self = shift;
483 my $file = $self->{file};
068587bd 484 return $self->render_sharedir_file( file('lib', 'Helper', 'compclass.pm.tt'), $file );
68ccb5e5 485}
486
487sub _mk_comptest {
488 my $self = shift;
489 my $test = $self->{test};
068587bd 490 $self->render_sharedir_file( file('t', 'comptest.tt'), $test ); ## wtf do i rename this to?
68ccb5e5 491}
492
493sub _mk_images {
494 my $self = shift;
495 my $images = $self->{images};
496 my @images =
497 qw/catalyst_logo btn_120x50_built btn_120x50_built_shadow
498 btn_120x50_powered btn_120x50_powered_shadow btn_88x31_built
499 btn_88x31_built_shadow btn_88x31_powered btn_88x31_powered_shadow/;
500 for my $name (@images) {
3f2f19ec 501 my $image = $self->get_sharedir_file("root", "static", "images", "$name.png.bin");
068587bd 502 $self->mk_file( file( $images, "$name.png" ), $image );
68ccb5e5 503 }
504}
505
506sub _mk_favicon {
507 my $self = shift;
508 my $root = $self->{root};
f023d4a1 509 my $favicon = $self->get_sharedir_file( 'root', 'favicon.ico.bin' );
068587bd 510 my $dest = dir( $root, "favicon.ico" );
afd739f1 511 $self->mk_file( $dest, $favicon );
68ccb5e5 512
513}
514
515sub _deprecate_file {
516 my ( $self, $file ) = @_;
517 if ( -e $file ) {
28d172c6 518 my ($f, $oldcontent);
519 if ( $f = IO::File->new("< $file") ) {
68ccb5e5 520 $oldcontent = join( '', (<$f>) );
521 }
522 my $newfile = $file . '.deprecated';
28d172c6 523 if ( $f = IO::File->new("> $newfile") ) {
68ccb5e5 524 binmode $f;
525 print $f $oldcontent;
526 print qq/created "$newfile"\n/;
527 unlink $file;
528 print qq/removed "$file"\n/;
529 return 1;
530 }
531 Catalyst::Exception->throw(
532 message => qq/Couldn't create "$file", "$!"/ );
533 }
534}
535
1198a7d4 5361;
537__END__
538
539=head1 NAME
540
541Catalyst::Helper - Bootstrap a Catalyst application
542
543=head1 SYNOPSIS
544
545 catalyst.pl <myappname>
546
fab70e0a 547=head1 DESCRIPTION
548
549This module is used by B<catalyst.pl> to create a set of scripts for a
550new catalyst application. The scripts each contain documentation and
551will output help on how to use them if called incorrectly or in some
552cases, with no arguments.
553
554It also provides some useful methods for a Helper module to call when
555creating a component. See L</METHODS>.
556
557=head1 SCRIPTS
558
559=head2 _create.pl
560
561Used to create new components for a catalyst application at the
562development stage.
563
564=head2 _server.pl
565
566The catalyst test server, starts an HTTPD which outputs debugging to
567the terminal.
568
569=head2 _test.pl
570
571A script for running tests from the command-line.
572
573=head2 _cgi.pl
574
575Run your application as a CGI.
576
577=head2 _fastcgi.pl
578
579Run the application as a fastcgi app. Either by hand, or call this
580from FastCgiServer in your http server config.
581
68ccb5e5 582=head1 HELPERS
583
fab70e0a 584The L</_create.pl> script creates application components using Helper
585modules. The Catalyst team provides a good number of Helper modules
586for you to use. You can also add your own.
587
68ccb5e5 588Helpers are classes that provide two methods.
589
590 * mk_compclass - creates the Component class
591 * mk_comptest - creates the Component test
592
fab70e0a 593So when you call C<scripts/myapp_create.pl view MyView TT>, create
594will try to execute Catalyst::Helper::View::TT->mk_compclass and
68ccb5e5 595Catalyst::Helper::View::TT->mk_comptest.
596
c4c50c2d 597See L<Catalyst::Helper::View::TT> and
598L<Catalyst::Helper::Model::DBIC::Schema> for examples.
68ccb5e5 599
600All helper classes should be under one of the following namespaces.
601
602 Catalyst::Helper::Model::
603 Catalyst::Helper::View::
604 Catalyst::Helper::Controller::
605
675fef06 606=head2 COMMON HELPERS
bc8d7994 607
608=over
609
610=item *
611
612L<Catalyst::Helper::Model::DBIC::Schema> - DBIx::Class models
613
614=item *
615
616L<Catalyst::Helper::View::TT> - Template Toolkit view
617
618=item *
619
620L<Catalyst::Helper::Model::LDAP>
621
622=item *
623
624L<Catalyst::Helper::Model::Adaptor> - wrap any class into a Catalyst model
625
626=back
627
628=head3 NOTE
629
acde1869 630The helpers will read author name from /etc/passwd by default.
631To override, please export the AUTHOR variable.
bc8d7994 632
633=head1 METHODS
634
fab70e0a 635=head2 mk_compclass
636
637This method in your Helper module is called with C<$helper>
638which is a L<Catalyst::Helper> object, and whichever other arguments
639the user added to the command-line. You can use the $helper to call methods
640described below.
641
642If the Helper module does not contain a C<mk_compclass> method, it
643will fall back to calling L</render_file>, with an argument of
644C<compclass>.
645
646=head2 mk_comptest
647
648This method in your Helper module is called with C<$helper>
649which is a L<Catalyst::Helper> object, and whichever other arguments
650the user added to the command-line. You can use the $helper to call methods
651described below.
652
653If the Helper module does not contain a C<mk_compclass> method, it
654will fall back to calling L</render_file>, with an argument of
655C<comptest>.
656
657=head2 mk_stuff
658
659This method is called if the user does not supply any of the usual
660component types C<view>, C<controller>, C<model>. It is passed the
661C<$helper> object (an instance of L<Catalyst::Helper>), and any other
662arguments the user typed.
663
664There is no fallback for this method.
665
bc8d7994 666=head1 INTERNAL METHODS
fab70e0a 667
668These are the methods that the Helper classes can call on the
669<$helper> object passed to them.
670
b6d89690 671=head2 render_file ($file, $path, $vars, $perms)
fab70e0a 672
28eb1300 673Render and create a file from a template in DATA using Template
40b26f8b 674Toolkit. $file is the relevant chunk of the __DATA__ section, $path is
b6d89690 675the path to the file, $vars is the hashref as expected by
676L<Template Toolkit|Template> and $perms are desired permissions (or system
677defaults if not set).
fab70e0a 678
28eb1300 679=head2 get_file ($class, $file)
fab70e0a 680
681Fetch file contents from the DATA section. This is used internally by
28eb1300 682L</render_file>. $class is the name of the class to get the DATA
683section from. __PACKAGE__ or ( caller(0) )[0] might be sensible
684values for this.
fab70e0a 685
686=head2 mk_app
687
688Create the main application skeleton. This is called by L<catalyst.pl>.
689
28eb1300 690=head2 mk_component ($app)
fab70e0a 691
692This method is called by L<create.pl> to make new components
693for your application.
694
608f6b92 695=head2 mk_dir ($path)
fab70e0a 696
697Surprisingly, this function makes a directory.
698
28eb1300 699=head2 mk_file ($file, $content)
fab70e0a 700
701Writes content to a file. Called by L</render_file>.
702
28eb1300 703=head2 next_test ($test_name)
fab70e0a 704
705Calculates the name of the next numbered test file and returns it.
28eb1300 706Don't give the number or the .t suffix for the test name.
fab70e0a 707
c6dbb300 708=cut
709
710=head2 get_sharedir_file
711
712Method for getting a file out of share/
713
c6dbb300 714=head2 render_file_contents
715
716Process a L<Template::Toolkit> template.
717
c6dbb300 718=head2 render_sharedir_file
719
720Render a template/image file from our share directory
721
68ccb5e5 722=head1 NOTE
723
724The helpers will read author name from /etc/passwd by default.
725To override, please export the AUTHOR variable.
726
727=head1 SEE ALSO
728
729L<Catalyst::Manual>, L<Catalyst::Test>, L<Catalyst::Request>,
730L<Catalyst::Response>, L<Catalyst>
731
f64c718c 732=head1 AUTHORS
68ccb5e5 733
f64c718c 734Catalyst Contributors, see Catalyst.pm
68ccb5e5 735
736=head1 LICENSE
737
7cd3b67e 738This library is free software. You can redistribute it and/or modify
68ccb5e5 739it under the same terms as Perl itself.
740
741=cut