Commit | Line | Data |
fc7ec1d9 |
1 | package Catalyst::Helper; |
2 | |
3 | use strict; |
4 | use base 'Class::Accessor::Fast'; |
f1d0b7ea |
5 | use Config; |
fc7ec1d9 |
6 | use File::Spec; |
7 | use File::Path; |
8 | use IO::File; |
9 | use FindBin; |
10 | |
11 | =head1 NAME |
12 | |
13 | Catalyst::Helper - Bootstrap a Catalyst application |
14 | |
15 | =head1 SYNOPSIS |
16 | |
17 | See L<Catalyst::Manual::Intro> |
18 | |
19 | =head1 DESCRIPTION |
20 | |
21 | Bootstrap a Catalyst application. |
22 | |
23 | =head2 METHODS |
24 | |
25 | =head3 mk_app |
26 | |
27 | =cut |
28 | |
29 | sub mk_app { |
30 | my ( $self, $name ) = @_; |
31 | return 0 if $name =~ /[^\w\:]/; |
32 | $self->{name} = $name; |
33 | $self->{dir} = $name; |
34 | $self->{dir} =~ s/\:\:/-/g; |
35 | $self->_mk_dirs; |
36 | $self->_mk_appclass; |
37 | $self->_mk_makefile; |
91864987 |
38 | $self->_mk_readme; |
39 | $self->_mk_changes; |
fc7ec1d9 |
40 | $self->_mk_apptest; |
bc024080 |
41 | $self->_mk_cgi; |
cb8d90e5 |
42 | $self->_mk_fcgi; |
fc7ec1d9 |
43 | $self->_mk_server; |
44 | $self->_mk_test; |
45 | $self->_mk_create; |
46 | return 1; |
47 | } |
48 | |
ad41e777 |
49 | =head3 mk_component |
50 | |
51 | =cut |
52 | |
53 | sub mk_component { |
b5524568 |
54 | my $self = shift; |
55 | my $app = shift; |
56 | $self->{app} = $app; |
57 | $self->{base} = File::Spec->catdir( $FindBin::Bin, '..' ); |
58 | unless ( $_[0] =~ /^model|m|view|v|controller|c\$/i ) { |
59 | my $helper = shift; |
60 | my @args = @_; |
61 | my $class = "Catalyst::Helper::$helper"; |
ad41e777 |
62 | eval "require $class"; |
63 | die qq/Couldn't load helper "$class", "$@"/ if $@; |
b5524568 |
64 | if ( $class->can('mk_stuff') ) { |
65 | return 1 unless $class->mk_stuff( $self, @args ); |
ad41e777 |
66 | } |
ad41e777 |
67 | } |
ad41e777 |
68 | else { |
b5524568 |
69 | my $type = shift; |
70 | my $name = shift; |
71 | my $helper = shift; |
72 | my @args = @_; |
73 | return 0 if $name =~ /[^\w\:]/; |
74 | $type = 'M' if $type =~ /model|m/i; |
75 | $type = 'V' if $type =~ /view|v/i; |
76 | $type = 'C' if $type =~ /controller|c/i; |
77 | $self->{type} = $type; |
78 | $self->{name} = $name; |
79 | $self->{class} = "$app\::$type\::$name"; |
80 | |
81 | # Class |
82 | my $appdir = File::Spec->catdir( split /\:\:/, $app ); |
83 | my $path = |
84 | File::Spec->catdir( $FindBin::Bin, '..', 'lib', $appdir, $type ); |
85 | my $file = $name; |
86 | if ( $name =~ /\:/ ) { |
87 | my @path = split /\:\:/, $name; |
88 | $file = pop @path; |
89 | $path = File::Spec->catdir( $path, @path ); |
90 | mkpath $path; |
91 | } |
92 | $file = File::Spec->catfile( $path, "$file.pm" ); |
93 | $self->{file} = $file; |
94 | |
95 | # Test |
96 | $self->{test_dir} = File::Spec->catdir( $FindBin::Bin, '..', 't' ); |
97 | $self->{test} = $self->next_test; |
98 | |
99 | # Helper |
100 | if ($helper) { |
101 | my $comp = 'Model'; |
102 | $comp = 'View' if $type eq 'V'; |
103 | $comp = 'Controller' if $type eq 'C'; |
104 | my $class = "Catalyst::Helper::$comp\::$helper"; |
105 | eval "require $class"; |
106 | die qq/Couldn't load helper "$class", "$@"/ if $@; |
107 | if ( $class->can('mk_compclass') ) { |
108 | return 1 unless $class->mk_compclass( $self, @args ); |
109 | } |
110 | else { return 1 unless $self->_mk_compclass } |
111 | |
112 | if ( $class->can('mk_comptest') ) { |
113 | $class->mk_comptest( $self, @args ); |
114 | } |
115 | else { $self->_mk_comptest } |
116 | } |
117 | |
118 | # Fallback |
119 | else { |
120 | return 1 unless $self->_mk_compclass; |
121 | $self->_mk_comptest; |
122 | } |
ad41e777 |
123 | } |
124 | return 1; |
125 | } |
126 | |
127 | =head3 mk_dir |
128 | |
129 | =cut |
130 | |
131 | sub mk_dir { |
132 | my ( $self, $dir ) = @_; |
133 | if ( -d $dir ) { |
134 | print qq/ exists "$dir"\n/; |
135 | return 0; |
136 | } |
137 | if ( mkpath $dir) { |
138 | print qq/created "$dir"\n/; |
139 | return 1; |
140 | } |
141 | die qq/Couldn't create "$dir", "$!"/; |
142 | } |
143 | |
144 | =head3 mk_file |
145 | |
146 | =cut |
147 | |
148 | sub mk_file { |
149 | my ( $self, $file, $content ) = @_; |
150 | if ( -e $file ) { |
151 | print qq/ exists "$file"\n/; |
152 | return 0; |
153 | } |
154 | if ( my $f = IO::File->new("> $file") ) { |
155 | print $f $content; |
156 | print qq/created "$file"\n/; |
157 | return 1; |
158 | } |
159 | die qq/Couldn't create "$file", "$!"/; |
160 | } |
161 | |
162 | =head3 next_test |
163 | |
164 | =cut |
165 | |
166 | sub next_test { |
167 | my ( $self, $tname ) = @_; |
3cb1db8c |
168 | if ($tname) { $tname = "$tname.t" } |
ad41e777 |
169 | else { |
170 | my $name = $self->{name}; |
ad41e777 |
171 | my $prefix = $name; |
172 | $prefix =~ s/::/_/g; |
173 | $prefix = lc $prefix; |
3cb1db8c |
174 | $tname = $prefix . '.t'; |
ad41e777 |
175 | $self->{prefix} = $prefix; |
176 | } |
3cb1db8c |
177 | my $dir = $self->{test_dir}; |
178 | my $type = lc $self->{type}; |
179 | return File::Spec->catfile( $dir, $type, $tname ); |
ad41e777 |
180 | } |
181 | |
fc7ec1d9 |
182 | sub _mk_dirs { |
183 | my $self = shift; |
ad41e777 |
184 | $self->mk_dir( $self->{dir} ); |
91864987 |
185 | $self->{script} = File::Spec->catdir( $self->{dir}, 'script' ); |
186 | $self->mk_dir( $self->{script} ); |
fc7ec1d9 |
187 | $self->{lib} = File::Spec->catdir( $self->{dir}, 'lib' ); |
ad41e777 |
188 | $self->mk_dir( $self->{lib} ); |
fc7ec1d9 |
189 | $self->{root} = File::Spec->catdir( $self->{dir}, 'root' ); |
ad41e777 |
190 | $self->mk_dir( $self->{root} ); |
fc7ec1d9 |
191 | $self->{t} = File::Spec->catdir( $self->{dir}, 't' ); |
ad41e777 |
192 | $self->mk_dir( $self->{t} ); |
3cb1db8c |
193 | $self->mk_dir( File::Spec->catdir( $self->{t}, 'm' ) ); |
194 | $self->mk_dir( File::Spec->catdir( $self->{t}, 'v' ) ); |
195 | $self->mk_dir( File::Spec->catdir( $self->{t}, 'c' ) ); |
fc7ec1d9 |
196 | $self->{class} = File::Spec->catdir( split( /\:\:/, $self->{name} ) ); |
197 | $self->{mod} = File::Spec->catdir( $self->{lib}, $self->{class} ); |
ad41e777 |
198 | $self->mk_dir( $self->{mod} ); |
fc7ec1d9 |
199 | $self->{m} = File::Spec->catdir( $self->{mod}, 'M' ); |
ad41e777 |
200 | $self->mk_dir( $self->{m} ); |
fc7ec1d9 |
201 | $self->{v} = File::Spec->catdir( $self->{mod}, 'V' ); |
ad41e777 |
202 | $self->mk_dir( $self->{v} ); |
fc7ec1d9 |
203 | $self->{c} = File::Spec->catdir( $self->{mod}, 'C' ); |
ad41e777 |
204 | $self->mk_dir( $self->{c} ); |
fc7ec1d9 |
205 | $self->{base} = File::Spec->rel2abs( $self->{dir} ); |
206 | } |
207 | |
208 | sub _mk_appclass { |
ad41e777 |
209 | my $self = shift; |
210 | my $mod = $self->{mod}; |
211 | my $name = $self->{name}; |
212 | my $base = $self->{base}; |
213 | $self->mk_file( "$mod.pm", <<"EOF"); |
fc7ec1d9 |
214 | package $name; |
215 | |
216 | use strict; |
217 | use Catalyst qw/-Debug/; |
218 | |
219 | our \$VERSION = '0.01'; |
220 | |
221 | $name->config( |
222 | name => '$name', |
223 | root => '$base/root', |
224 | ); |
5811fa3e |
225 | |
226 | $name->setup; |
fc7ec1d9 |
227 | |
5a8ed4fe |
228 | sub default : Private { |
229 | my ( \$self, \$c ) = \@_; |
230 | \$c->res->output('Congratulations, $name is on Catalyst!'); |
231 | } |
fc7ec1d9 |
232 | |
233 | =head1 NAME |
234 | |
235 | $name - A very nice application |
236 | |
237 | =head1 SYNOPSIS |
238 | |
239 | Very simple to use |
240 | |
241 | =head1 DESCRIPTION |
242 | |
243 | Very nice application. |
244 | |
245 | =head1 AUTHOR |
246 | |
247 | Clever guy |
248 | |
249 | =head1 LICENSE |
250 | |
251 | This library is free software . You can redistribute it and/or modify it under |
252 | the same terms as perl itself. |
253 | |
254 | =cut |
255 | |
256 | 1; |
257 | EOF |
258 | } |
259 | |
260 | sub _mk_makefile { |
ad41e777 |
261 | my $self = shift; |
262 | my $name = $self->{name}; |
263 | my $dir = $self->{dir}; |
264 | my $class = $self->{class}; |
265 | $self->mk_file( "$dir\/Makefile.PL", <<"EOF"); |
fc7ec1d9 |
266 | use ExtUtils::MakeMaker; |
267 | |
268 | WriteMakefile( |
269 | NAME => '$name', |
270 | VERSION_FROM => 'lib/$class.pm', |
4400b5ef |
271 | PREREQ_PM => { Catalyst => 5 }, |
3cb1db8c |
272 | test => { TESTS => join ' ', ( glob('t/*.t'), glob('t/*/*.t') ) } |
fc7ec1d9 |
273 | ); |
274 | EOF |
275 | } |
276 | |
91864987 |
277 | sub _mk_readme { |
278 | my $self = shift; |
279 | my $dir = $self->{dir}; |
280 | $self->mk_file( "$dir\/README", <<"EOF"); |
281 | Run script/server.pl to test the application. |
282 | EOF |
283 | } |
284 | |
285 | sub _mk_changes { |
286 | my $self = shift; |
287 | my $name = $self->{name}; |
288 | my $dir = $self->{dir}; |
289 | my $time = localtime time; |
290 | $self->mk_file( "$dir\/Changes", <<"EOF"); |
291 | This file documents the revision history for Perl extension $name. |
292 | |
293 | 0.01 $time |
294 | - initial revision, generated by Catalyst |
295 | EOF |
296 | } |
297 | |
fc7ec1d9 |
298 | sub _mk_apptest { |
299 | my $self = shift; |
300 | my $t = $self->{t}; |
301 | my $name = $self->{name}; |
ad41e777 |
302 | $self->mk_file( "$t\/01app.t", <<"EOF"); |
fc7ec1d9 |
303 | use Test::More tests => 2; |
304 | use_ok( Catalyst::Test, '$name' ); |
305 | |
306 | ok( request('/')->is_success ); |
307 | EOF |
5a8fd7e9 |
308 | $self->mk_file( "$t\/02pod.t", <<"EOF"); |
309 | use Test::More; |
310 | |
311 | eval "use Test::Pod 1.14"; |
a5d4355a |
312 | plan skip_all => 'Test::Pod 1.14 required' if \$@; |
313 | plan skip_all => 'set TEST_POD to enable this test' unless \$ENV{TEST_POD}; |
5a8fd7e9 |
314 | |
315 | all_pod_files_ok(); |
316 | EOF |
317 | $self->mk_file( "$t\/03podcoverage.t", <<"EOF"); |
1df125c9 |
318 | use Test::More; |
319 | |
320 | eval "use Test::Pod::Coverage 1.04"; |
321 | plan skip_all => 'Test::Pod::Coverage 1.04 required' if \$@; |
322 | plan skip_all => 'set TEST_POD to enable this test' unless \$ENV{TEST_POD}; |
323 | |
324 | all_pod_coverage_ok(); |
325 | EOF |
fc7ec1d9 |
326 | } |
327 | |
bc024080 |
328 | sub _mk_cgi { |
329 | my $self = shift; |
330 | my $name = $self->{name}; |
331 | my $script = $self->{script}; |
d8ab1b45 |
332 | $self->mk_file( "$script\/cgi.pl", <<"EOF"); |
333 | $Config{startperl} -w |
334 | |
335 | BEGIN { \$ENV{CATALYST_ENGINE} = 'CGI' } |
336 | |
337 | use strict; |
338 | use FindBin; |
339 | use lib "\$FindBin::Bin/../lib"; |
340 | use $name; |
341 | |
342 | $name->run; |
343 | |
344 | 1; |
345 | __END__ |
346 | |
347 | =head1 NAME |
348 | |
349 | cgi - Catalyst CGI |
350 | |
351 | =head1 SYNOPSIS |
352 | |
353 | See L<Catalyst::Manual> |
354 | |
355 | =head1 DESCRIPTION |
356 | |
357 | Run a Catalyst application as cgi. |
358 | |
359 | =head1 AUTHOR |
360 | |
361 | Sebastian Riedel, C<sri\@oook.de> |
362 | |
363 | =head1 COPYRIGHT |
364 | |
365 | Copyright 2004 Sebastian Riedel. All rights reserved. |
366 | |
367 | This library is free software. You can redistribute it and/or modify it under |
368 | the same terms as perl itself. |
369 | |
370 | =cut |
371 | EOF |
372 | chmod 0700, "$script/cgi.pl"; |
373 | } |
374 | |
cb8d90e5 |
375 | sub _mk_fcgi { |
376 | my $self = shift; |
377 | my $name = $self->{name}; |
378 | my $script = $self->{script}; |
379 | $self->mk_file( "$script\/fcgi.pl", <<"EOF"); |
380 | $Config{startperl} -w |
381 | |
ffb41d94 |
382 | BEGIN { \$ENV{CATALYST_ENGINE} = 'FCGI' } |
cb8d90e5 |
383 | |
384 | use strict; |
385 | use FindBin; |
386 | use lib "\$FindBin::Bin/../lib"; |
cb8d90e5 |
387 | use $name; |
388 | |
ffb41d94 |
389 | $name->run; |
cb8d90e5 |
390 | |
391 | 1; |
392 | __END__ |
393 | |
394 | =head1 NAME |
395 | |
396 | fcgi - Catalyst FCGI |
397 | |
398 | =head1 SYNOPSIS |
399 | |
400 | See L<Catalyst::Manual> |
401 | |
402 | =head1 DESCRIPTION |
403 | |
404 | Run a Catalyst application as fcgi. |
405 | |
406 | =head1 AUTHOR |
407 | |
408 | Sebastian Riedel, C<sri\@oook.de> |
409 | |
410 | =head1 COPYRIGHT |
411 | |
412 | Copyright 2004 Sebastian Riedel. All rights reserved. |
413 | |
414 | This library is free software. You can redistribute it and/or modify it under |
415 | the same terms as perl itself. |
416 | |
417 | =cut |
418 | EOF |
419 | chmod 0700, "$script/fcgi.pl"; |
420 | } |
421 | |
fc7ec1d9 |
422 | sub _mk_server { |
91864987 |
423 | my $self = shift; |
424 | my $name = $self->{name}; |
425 | my $script = $self->{script}; |
426 | $self->mk_file( "$script\/server.pl", <<"EOF"); |
f1d0b7ea |
427 | $Config{startperl} -w |
fc7ec1d9 |
428 | |
ca61af20 |
429 | BEGIN { \$ENV{CATALYST_ENGINE} = 'HTTP' } |
585893b9 |
430 | |
fc7ec1d9 |
431 | use strict; |
432 | use Getopt::Long; |
433 | use Pod::Usage; |
434 | use FindBin; |
435 | use lib "\$FindBin::Bin/../lib"; |
585893b9 |
436 | use $name; |
fc7ec1d9 |
437 | |
438 | my \$help = 0; |
439 | my \$port = 3000; |
440 | |
441 | GetOptions( 'help|?' => \\\$help, 'port=s' => \\\$port ); |
442 | |
443 | pod2usage(1) if \$help; |
444 | |
585893b9 |
445 | $name->run(\$port); |
fc7ec1d9 |
446 | |
447 | 1; |
448 | __END__ |
449 | |
450 | =head1 NAME |
451 | |
452 | server - Catalyst Testserver |
453 | |
454 | =head1 SYNOPSIS |
455 | |
91864987 |
456 | server.pl [options] |
fc7ec1d9 |
457 | |
458 | Options: |
ad41e777 |
459 | -? -help display this help and exits |
460 | -p -port port (defaults to 3000) |
fc7ec1d9 |
461 | |
03a53815 |
462 | See also: |
463 | perldoc Catalyst::Manual |
464 | perldoc Catalyst::Manual::Intro |
465 | |
fc7ec1d9 |
466 | =head1 DESCRIPTION |
467 | |
468 | Run a Catalyst Testserver for this application. |
469 | |
470 | =head1 AUTHOR |
471 | |
472 | Sebastian Riedel, C<sri\@oook.de> |
473 | |
474 | =head1 COPYRIGHT |
475 | |
476 | Copyright 2004 Sebastian Riedel. All rights reserved. |
477 | |
478 | This library is free software. You can redistribute it and/or modify it under |
479 | the same terms as perl itself. |
480 | |
481 | =cut |
482 | EOF |
91864987 |
483 | chmod 0700, "$script/server.pl"; |
fc7ec1d9 |
484 | } |
485 | |
486 | sub _mk_test { |
91864987 |
487 | my $self = shift; |
488 | my $name = $self->{name}; |
489 | my $script = $self->{script}; |
490 | $self->mk_file( "$script/test.pl", <<"EOF"); |
f1d0b7ea |
491 | $Config{startperl} -w |
fc7ec1d9 |
492 | |
e646f111 |
493 | BEGIN { \$ENV{CATALYST_ENGINE} = 'Test' } |
494 | |
fc7ec1d9 |
495 | use strict; |
496 | use Getopt::Long; |
497 | use Pod::Usage; |
498 | use FindBin; |
499 | use lib "\$FindBin::Bin/../lib"; |
e646f111 |
500 | use $name; |
fc7ec1d9 |
501 | |
502 | my \$help = 0; |
503 | |
504 | GetOptions( 'help|?' => \\\$help ); |
505 | |
506 | pod2usage(1) if ( \$help || !\$ARGV[0] ); |
507 | |
e646f111 |
508 | print $name->run(\$ARGV[0])->content . "\n"; |
fc7ec1d9 |
509 | |
510 | 1; |
511 | __END__ |
512 | |
513 | =head1 NAME |
514 | |
515 | test - Catalyst Test |
516 | |
517 | =head1 SYNOPSIS |
518 | |
91864987 |
519 | test.pl [options] uri |
fc7ec1d9 |
520 | |
521 | Options: |
522 | -help display this help and exits |
523 | |
524 | Examples: |
91864987 |
525 | test.pl http://localhost/some_action |
526 | test.pl /some_action |
fc7ec1d9 |
527 | |
03a53815 |
528 | See also: |
529 | perldoc Catalyst::Manual |
530 | perldoc Catalyst::Manual::Intro |
531 | |
fc7ec1d9 |
532 | =head1 DESCRIPTION |
533 | |
534 | Run a Catalyst action from the comand line. |
535 | |
536 | =head1 AUTHOR |
537 | |
538 | Sebastian Riedel, C<sri\@oook.de> |
539 | |
540 | =head1 COPYRIGHT |
541 | |
542 | Copyright 2004 Sebastian Riedel. All rights reserved. |
543 | |
544 | This library is free software. You can redistribute it and/or modify it under |
545 | the same terms as perl itself. |
546 | |
547 | =cut |
548 | EOF |
91864987 |
549 | chmod 0700, "$script/test.pl"; |
fc7ec1d9 |
550 | } |
551 | |
552 | sub _mk_create { |
91864987 |
553 | my $self = shift; |
554 | my $name = $self->{name}; |
555 | my $script = $self->{script}; |
556 | $self->mk_file( "$script\/create.pl", <<"EOF"); |
f1d0b7ea |
557 | $Config{startperl} -w |
fc7ec1d9 |
558 | |
559 | use strict; |
560 | use Getopt::Long; |
561 | use Pod::Usage; |
562 | use Catalyst::Helper; |
563 | |
564 | my \$help = 0; |
565 | |
566 | GetOptions( 'help|?' => \$help ); |
567 | |
b5524568 |
568 | pod2usage(1) if ( \$help || !\$ARGV[0] ); |
fc7ec1d9 |
569 | |
570 | my \$helper = Catalyst::Helper->new; |
571 | pod2usage(1) unless \$helper->mk_component( '$name', \@ARGV ); |
572 | |
573 | 1; |
574 | __END__ |
575 | |
576 | =head1 NAME |
577 | |
578 | create - Create a new Catalyst Component |
579 | |
580 | =head1 SYNOPSIS |
581 | |
91864987 |
582 | create.pl [options] model|view|controller name [helper] [options] |
fc7ec1d9 |
583 | |
584 | Options: |
585 | -help display this help and exits |
586 | |
587 | Examples: |
91864987 |
588 | create.pl controller My::Controller |
589 | create.pl view My::View |
590 | create.pl view MyView TT |
591 | create.pl view TT TT |
592 | create.pl model My::Model |
593 | create.pl model SomeDB CDBI dbi:SQLite:/tmp/my.db |
594 | create.pl model AnotherDB CDBI dbi:Pg:dbname=foo root 4321 |
b5524568 |
595 | create.pl Ajax |
03a53815 |
596 | |
597 | See also: |
598 | perldoc Catalyst::Manual |
599 | perldoc Catalyst::Manual::Intro |
fc7ec1d9 |
600 | |
601 | =head1 DESCRIPTION |
602 | |
603 | Create a new Catalyst Component. |
604 | |
605 | =head1 AUTHOR |
606 | |
607 | Sebastian Riedel, C<sri\@oook.de> |
608 | |
609 | =head1 COPYRIGHT |
610 | |
611 | Copyright 2004 Sebastian Riedel. All rights reserved. |
612 | |
613 | This library is free software. You can redistribute it and/or modify it under |
614 | the same terms as perl itself. |
615 | |
616 | =cut |
617 | EOF |
91864987 |
618 | chmod 0700, "$script/create.pl"; |
fc7ec1d9 |
619 | } |
620 | |
fc7ec1d9 |
621 | sub _mk_compclass { |
622 | my $self = shift; |
623 | my $app = $self->{app}; |
624 | my $class = $self->{class}; |
625 | my $type = $self->{type}; |
626 | my $action = ''; |
627 | $action = <<"EOF" if $type eq 'C'; |
628 | |
5a8ed4fe |
629 | sub default : Private { |
630 | my ( \$self, \$c ) = \@_; |
631 | \$c->res->output('Congratulations, $class is on Catalyst!'); |
632 | } |
fc7ec1d9 |
633 | EOF |
634 | my $file = $self->{file}; |
ad41e777 |
635 | return $self->mk_file( "$file", <<"EOF"); |
fc7ec1d9 |
636 | package $class; |
637 | |
638 | use strict; |
639 | use base 'Catalyst::Base'; |
640 | $action |
641 | =head1 NAME |
642 | |
643 | $class - A Component |
644 | |
645 | =head1 SYNOPSIS |
646 | |
647 | Very simple to use |
648 | |
649 | =head1 DESCRIPTION |
650 | |
651 | Very nice component. |
652 | |
653 | =head1 AUTHOR |
654 | |
655 | Clever guy |
656 | |
657 | =head1 LICENSE |
658 | |
659 | This library is free software . You can redistribute it and/or modify it under |
660 | the same terms as perl itself. |
661 | |
662 | =cut |
663 | |
664 | 1; |
665 | EOF |
666 | } |
667 | |
668 | sub _mk_comptest { |
669 | my $self = shift; |
670 | my $prefix = $self->{prefix}; |
671 | my $type = $self->{type}; |
672 | my $class = $self->{class}; |
673 | my $app = $self->{app}; |
674 | my $test = $self->{test}; |
fc7ec1d9 |
675 | if ( $self->{type} eq 'C' ) { |
ad41e777 |
676 | $self->mk_file( "$test", <<"EOF"); |
fc7ec1d9 |
677 | use Test::More tests => 3; |
678 | use_ok( Catalyst::Test, '$app' ); |
679 | use_ok('$class'); |
680 | |
681 | ok( request('$prefix')->is_success ); |
682 | EOF |
683 | } |
684 | else { |
ad41e777 |
685 | $self->mk_file( "$test", <<"EOF"); |
fc7ec1d9 |
686 | use Test::More tests => 1; |
687 | use_ok('$class'); |
688 | EOF |
689 | } |
690 | } |
691 | |
7833fdfc |
692 | =head1 HELPERS |
693 | |
694 | Helpers are classes that provide two methods. |
695 | |
696 | * mk_compclass - creates the Component class |
697 | * mk_comptest - creates the Component test |
698 | |
699 | So when you call C<bin/create view MyView TT>, create would try to execute |
700 | Catalyst::Helper::View::TT->mk_compclass and |
701 | Catalyst::Helper::View::TT->mk_comptest. |
702 | |
703 | See L<Catalyst::Helper::View::TT> and L<Catalyst::Helper::Model::CDBI> for |
704 | examples. |
705 | |
706 | All helper classes should be under one of the following namespaces. |
707 | |
708 | Catalyst::Helper::Model:: |
709 | Catalyst::Helper::View:: |
710 | Catalyst::Helper::Controller:: |
711 | |
fc7ec1d9 |
712 | =head1 SEE ALSO |
713 | |
714 | L<Catalyst::Manual>, L<Catalyst::Test>, L<Catalyst::Request>, |
715 | L<Catalyst::Response>, L<Catalyst> |
716 | |
717 | =head1 AUTHOR |
718 | |
719 | Sebastian Riedel, C<sri@oook.de> |
720 | |
721 | =head1 LICENSE |
722 | |
723 | This library is free software . You can redistribute it and/or modify it under |
724 | the same terms as perl itself. |
725 | |
726 | =cut |
727 | |
728 | 1; |