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 | ); |
225 | |
226 | $name->action( |
227 | |
228 | '!default' => sub { |
229 | my ( \$self, \$c ) = \@_; |
230 | \$c->res->output('Congratulations, $name is on Catalyst!'); |
231 | }, |
232 | |
233 | ); |
234 | |
235 | =head1 NAME |
236 | |
237 | $name - A very nice application |
238 | |
239 | =head1 SYNOPSIS |
240 | |
241 | Very simple to use |
242 | |
243 | =head1 DESCRIPTION |
244 | |
245 | Very nice application. |
246 | |
247 | =head1 AUTHOR |
248 | |
249 | Clever guy |
250 | |
251 | =head1 LICENSE |
252 | |
253 | This library is free software . You can redistribute it and/or modify it under |
254 | the same terms as perl itself. |
255 | |
256 | =cut |
257 | |
258 | 1; |
259 | EOF |
260 | } |
261 | |
262 | sub _mk_makefile { |
ad41e777 |
263 | my $self = shift; |
264 | my $name = $self->{name}; |
265 | my $dir = $self->{dir}; |
266 | my $class = $self->{class}; |
267 | $self->mk_file( "$dir\/Makefile.PL", <<"EOF"); |
fc7ec1d9 |
268 | use ExtUtils::MakeMaker; |
269 | |
270 | WriteMakefile( |
271 | NAME => '$name', |
272 | VERSION_FROM => 'lib/$class.pm', |
3cb1db8c |
273 | PREREQ_PM => { Catalyst => 0 }, |
274 | test => { TESTS => join ' ', ( glob('t/*.t'), glob('t/*/*.t') ) } |
fc7ec1d9 |
275 | ); |
276 | EOF |
277 | } |
278 | |
91864987 |
279 | sub _mk_readme { |
280 | my $self = shift; |
281 | my $dir = $self->{dir}; |
282 | $self->mk_file( "$dir\/README", <<"EOF"); |
283 | Run script/server.pl to test the application. |
284 | EOF |
285 | } |
286 | |
287 | sub _mk_changes { |
288 | my $self = shift; |
289 | my $name = $self->{name}; |
290 | my $dir = $self->{dir}; |
291 | my $time = localtime time; |
292 | $self->mk_file( "$dir\/Changes", <<"EOF"); |
293 | This file documents the revision history for Perl extension $name. |
294 | |
295 | 0.01 $time |
296 | - initial revision, generated by Catalyst |
297 | EOF |
298 | } |
299 | |
fc7ec1d9 |
300 | sub _mk_apptest { |
301 | my $self = shift; |
302 | my $t = $self->{t}; |
303 | my $name = $self->{name}; |
ad41e777 |
304 | $self->mk_file( "$t\/01app.t", <<"EOF"); |
fc7ec1d9 |
305 | use Test::More tests => 2; |
306 | use_ok( Catalyst::Test, '$name' ); |
307 | |
308 | ok( request('/')->is_success ); |
309 | EOF |
ad41e777 |
310 | $self->mk_file( "$t\/02podcoverage.t", <<"EOF"); |
1df125c9 |
311 | use Test::More; |
312 | |
313 | eval "use Test::Pod::Coverage 1.04"; |
314 | plan skip_all => 'Test::Pod::Coverage 1.04 required' if \$@; |
315 | plan skip_all => 'set TEST_POD to enable this test' unless \$ENV{TEST_POD}; |
316 | |
317 | all_pod_coverage_ok(); |
318 | EOF |
fc7ec1d9 |
319 | } |
320 | |
bc024080 |
321 | sub _mk_cgi { |
322 | my $self = shift; |
323 | my $name = $self->{name}; |
324 | my $script = $self->{script}; |
3fde004f |
325 | $self->mk_file( "$script\/nph-cgi.pl", <<"EOF"); |
bc024080 |
326 | $Config{startperl} -w |
327 | |
e646f111 |
328 | BEGIN { \$ENV{CATALYST_ENGINE} = 'CGI::NPH' } |
e4b4c2b6 |
329 | |
bc024080 |
330 | use strict; |
331 | use FindBin; |
332 | use lib "\$FindBin::Bin/../lib"; |
333 | use $name; |
334 | |
335 | $name->run; |
336 | |
337 | 1; |
338 | __END__ |
339 | |
340 | =head1 NAME |
341 | |
3fde004f |
342 | nph-cgi - Catalyst CGI |
bc024080 |
343 | |
344 | =head1 SYNOPSIS |
345 | |
346 | See L<Catalyst::Manual> |
347 | |
348 | =head1 DESCRIPTION |
349 | |
350 | Run a Catalyst application as cgi. |
351 | |
352 | =head1 AUTHOR |
353 | |
354 | Sebastian Riedel, C<sri\@oook.de> |
355 | |
356 | =head1 COPYRIGHT |
357 | |
358 | Copyright 2004 Sebastian Riedel. All rights reserved. |
359 | |
360 | This library is free software. You can redistribute it and/or modify it under |
361 | the same terms as perl itself. |
362 | |
363 | =cut |
364 | EOF |
3fde004f |
365 | chmod 0700, "$script/nph-cgi.pl"; |
bc024080 |
366 | } |
367 | |
cb8d90e5 |
368 | sub _mk_fcgi { |
369 | my $self = shift; |
370 | my $name = $self->{name}; |
371 | my $script = $self->{script}; |
372 | $self->mk_file( "$script\/fcgi.pl", <<"EOF"); |
373 | $Config{startperl} -w |
374 | |
ffb41d94 |
375 | BEGIN { \$ENV{CATALYST_ENGINE} = 'FCGI' } |
cb8d90e5 |
376 | |
377 | use strict; |
378 | use FindBin; |
379 | use lib "\$FindBin::Bin/../lib"; |
cb8d90e5 |
380 | use $name; |
381 | |
ffb41d94 |
382 | $name->run; |
cb8d90e5 |
383 | |
384 | 1; |
385 | __END__ |
386 | |
387 | =head1 NAME |
388 | |
389 | fcgi - Catalyst FCGI |
390 | |
391 | =head1 SYNOPSIS |
392 | |
393 | See L<Catalyst::Manual> |
394 | |
395 | =head1 DESCRIPTION |
396 | |
397 | Run a Catalyst application as fcgi. |
398 | |
399 | =head1 AUTHOR |
400 | |
401 | Sebastian Riedel, C<sri\@oook.de> |
402 | |
403 | =head1 COPYRIGHT |
404 | |
405 | Copyright 2004 Sebastian Riedel. All rights reserved. |
406 | |
407 | This library is free software. You can redistribute it and/or modify it under |
408 | the same terms as perl itself. |
409 | |
410 | =cut |
411 | EOF |
412 | chmod 0700, "$script/fcgi.pl"; |
413 | } |
414 | |
fc7ec1d9 |
415 | sub _mk_server { |
91864987 |
416 | my $self = shift; |
417 | my $name = $self->{name}; |
418 | my $script = $self->{script}; |
419 | $self->mk_file( "$script\/server.pl", <<"EOF"); |
f1d0b7ea |
420 | $Config{startperl} -w |
fc7ec1d9 |
421 | |
ffb41d94 |
422 | BEGIN { \$ENV{CATALYST_ENGINE} = 'Server' } |
585893b9 |
423 | |
fc7ec1d9 |
424 | use strict; |
425 | use Getopt::Long; |
426 | use Pod::Usage; |
427 | use FindBin; |
428 | use lib "\$FindBin::Bin/../lib"; |
585893b9 |
429 | use $name; |
fc7ec1d9 |
430 | |
431 | my \$help = 0; |
432 | my \$port = 3000; |
433 | |
434 | GetOptions( 'help|?' => \\\$help, 'port=s' => \\\$port ); |
435 | |
436 | pod2usage(1) if \$help; |
437 | |
585893b9 |
438 | $name->run(\$port); |
fc7ec1d9 |
439 | |
440 | 1; |
441 | __END__ |
442 | |
443 | =head1 NAME |
444 | |
445 | server - Catalyst Testserver |
446 | |
447 | =head1 SYNOPSIS |
448 | |
91864987 |
449 | server.pl [options] |
fc7ec1d9 |
450 | |
451 | Options: |
ad41e777 |
452 | -? -help display this help and exits |
453 | -p -port port (defaults to 3000) |
fc7ec1d9 |
454 | |
03a53815 |
455 | See also: |
456 | perldoc Catalyst::Manual |
457 | perldoc Catalyst::Manual::Intro |
458 | |
fc7ec1d9 |
459 | =head1 DESCRIPTION |
460 | |
461 | Run a Catalyst Testserver for this application. |
462 | |
463 | =head1 AUTHOR |
464 | |
465 | Sebastian Riedel, C<sri\@oook.de> |
466 | |
467 | =head1 COPYRIGHT |
468 | |
469 | Copyright 2004 Sebastian Riedel. All rights reserved. |
470 | |
471 | This library is free software. You can redistribute it and/or modify it under |
472 | the same terms as perl itself. |
473 | |
474 | =cut |
475 | EOF |
91864987 |
476 | chmod 0700, "$script/server.pl"; |
fc7ec1d9 |
477 | } |
478 | |
479 | sub _mk_test { |
91864987 |
480 | my $self = shift; |
481 | my $name = $self->{name}; |
482 | my $script = $self->{script}; |
483 | $self->mk_file( "$script/test.pl", <<"EOF"); |
f1d0b7ea |
484 | $Config{startperl} -w |
fc7ec1d9 |
485 | |
e646f111 |
486 | BEGIN { \$ENV{CATALYST_ENGINE} = 'Test' } |
487 | |
fc7ec1d9 |
488 | use strict; |
489 | use Getopt::Long; |
490 | use Pod::Usage; |
491 | use FindBin; |
492 | use lib "\$FindBin::Bin/../lib"; |
e646f111 |
493 | use $name; |
fc7ec1d9 |
494 | |
495 | my \$help = 0; |
496 | |
497 | GetOptions( 'help|?' => \\\$help ); |
498 | |
499 | pod2usage(1) if ( \$help || !\$ARGV[0] ); |
500 | |
e646f111 |
501 | print $name->run(\$ARGV[0])->content . "\n"; |
fc7ec1d9 |
502 | |
503 | 1; |
504 | __END__ |
505 | |
506 | =head1 NAME |
507 | |
508 | test - Catalyst Test |
509 | |
510 | =head1 SYNOPSIS |
511 | |
91864987 |
512 | test.pl [options] uri |
fc7ec1d9 |
513 | |
514 | Options: |
515 | -help display this help and exits |
516 | |
517 | Examples: |
91864987 |
518 | test.pl http://localhost/some_action |
519 | test.pl /some_action |
fc7ec1d9 |
520 | |
03a53815 |
521 | See also: |
522 | perldoc Catalyst::Manual |
523 | perldoc Catalyst::Manual::Intro |
524 | |
fc7ec1d9 |
525 | =head1 DESCRIPTION |
526 | |
527 | Run a Catalyst action from the comand line. |
528 | |
529 | =head1 AUTHOR |
530 | |
531 | Sebastian Riedel, C<sri\@oook.de> |
532 | |
533 | =head1 COPYRIGHT |
534 | |
535 | Copyright 2004 Sebastian Riedel. All rights reserved. |
536 | |
537 | This library is free software. You can redistribute it and/or modify it under |
538 | the same terms as perl itself. |
539 | |
540 | =cut |
541 | EOF |
91864987 |
542 | chmod 0700, "$script/test.pl"; |
fc7ec1d9 |
543 | } |
544 | |
545 | sub _mk_create { |
91864987 |
546 | my $self = shift; |
547 | my $name = $self->{name}; |
548 | my $script = $self->{script}; |
549 | $self->mk_file( "$script\/create.pl", <<"EOF"); |
f1d0b7ea |
550 | $Config{startperl} -w |
fc7ec1d9 |
551 | |
552 | use strict; |
553 | use Getopt::Long; |
554 | use Pod::Usage; |
555 | use Catalyst::Helper; |
556 | |
557 | my \$help = 0; |
558 | |
559 | GetOptions( 'help|?' => \$help ); |
560 | |
b5524568 |
561 | pod2usage(1) if ( \$help || !\$ARGV[0] ); |
fc7ec1d9 |
562 | |
563 | my \$helper = Catalyst::Helper->new; |
564 | pod2usage(1) unless \$helper->mk_component( '$name', \@ARGV ); |
565 | |
566 | 1; |
567 | __END__ |
568 | |
569 | =head1 NAME |
570 | |
571 | create - Create a new Catalyst Component |
572 | |
573 | =head1 SYNOPSIS |
574 | |
91864987 |
575 | create.pl [options] model|view|controller name [helper] [options] |
fc7ec1d9 |
576 | |
577 | Options: |
578 | -help display this help and exits |
579 | |
580 | Examples: |
91864987 |
581 | create.pl controller My::Controller |
582 | create.pl view My::View |
583 | create.pl view MyView TT |
584 | create.pl view TT TT |
585 | create.pl model My::Model |
586 | create.pl model SomeDB CDBI dbi:SQLite:/tmp/my.db |
587 | create.pl model AnotherDB CDBI dbi:Pg:dbname=foo root 4321 |
b5524568 |
588 | create.pl Ajax |
03a53815 |
589 | |
590 | See also: |
591 | perldoc Catalyst::Manual |
592 | perldoc Catalyst::Manual::Intro |
fc7ec1d9 |
593 | |
594 | =head1 DESCRIPTION |
595 | |
596 | Create a new Catalyst Component. |
597 | |
598 | =head1 AUTHOR |
599 | |
600 | Sebastian Riedel, C<sri\@oook.de> |
601 | |
602 | =head1 COPYRIGHT |
603 | |
604 | Copyright 2004 Sebastian Riedel. All rights reserved. |
605 | |
606 | This library is free software. You can redistribute it and/or modify it under |
607 | the same terms as perl itself. |
608 | |
609 | =cut |
610 | EOF |
91864987 |
611 | chmod 0700, "$script/create.pl"; |
fc7ec1d9 |
612 | } |
613 | |
fc7ec1d9 |
614 | sub _mk_compclass { |
615 | my $self = shift; |
616 | my $app = $self->{app}; |
617 | my $class = $self->{class}; |
618 | my $type = $self->{type}; |
619 | my $action = ''; |
620 | $action = <<"EOF" if $type eq 'C'; |
621 | |
622 | $app->action( |
623 | |
624 | '!?default' => sub { |
625 | my ( \$self, \$c ) = \@_; |
626 | \$c->res->output('Congratulations, $class is on Catalyst!'); |
627 | }, |
628 | |
629 | ); |
630 | EOF |
631 | my $file = $self->{file}; |
ad41e777 |
632 | return $self->mk_file( "$file", <<"EOF"); |
fc7ec1d9 |
633 | package $class; |
634 | |
635 | use strict; |
636 | use base 'Catalyst::Base'; |
637 | $action |
638 | =head1 NAME |
639 | |
640 | $class - A Component |
641 | |
642 | =head1 SYNOPSIS |
643 | |
644 | Very simple to use |
645 | |
646 | =head1 DESCRIPTION |
647 | |
648 | Very nice component. |
649 | |
650 | =head1 AUTHOR |
651 | |
652 | Clever guy |
653 | |
654 | =head1 LICENSE |
655 | |
656 | This library is free software . You can redistribute it and/or modify it under |
657 | the same terms as perl itself. |
658 | |
659 | =cut |
660 | |
661 | 1; |
662 | EOF |
663 | } |
664 | |
665 | sub _mk_comptest { |
666 | my $self = shift; |
667 | my $prefix = $self->{prefix}; |
668 | my $type = $self->{type}; |
669 | my $class = $self->{class}; |
670 | my $app = $self->{app}; |
671 | my $test = $self->{test}; |
fc7ec1d9 |
672 | if ( $self->{type} eq 'C' ) { |
ad41e777 |
673 | $self->mk_file( "$test", <<"EOF"); |
fc7ec1d9 |
674 | use Test::More tests => 3; |
675 | use_ok( Catalyst::Test, '$app' ); |
676 | use_ok('$class'); |
677 | |
678 | ok( request('$prefix')->is_success ); |
679 | EOF |
680 | } |
681 | else { |
ad41e777 |
682 | $self->mk_file( "$test", <<"EOF"); |
fc7ec1d9 |
683 | use Test::More tests => 1; |
684 | use_ok('$class'); |
685 | EOF |
686 | } |
687 | } |
688 | |
7833fdfc |
689 | =head1 HELPERS |
690 | |
691 | Helpers are classes that provide two methods. |
692 | |
693 | * mk_compclass - creates the Component class |
694 | * mk_comptest - creates the Component test |
695 | |
696 | So when you call C<bin/create view MyView TT>, create would try to execute |
697 | Catalyst::Helper::View::TT->mk_compclass and |
698 | Catalyst::Helper::View::TT->mk_comptest. |
699 | |
700 | See L<Catalyst::Helper::View::TT> and L<Catalyst::Helper::Model::CDBI> for |
701 | examples. |
702 | |
703 | All helper classes should be under one of the following namespaces. |
704 | |
705 | Catalyst::Helper::Model:: |
706 | Catalyst::Helper::View:: |
707 | Catalyst::Helper::Controller:: |
708 | |
fc7ec1d9 |
709 | =head1 SEE ALSO |
710 | |
711 | L<Catalyst::Manual>, L<Catalyst::Test>, L<Catalyst::Request>, |
712 | L<Catalyst::Response>, L<Catalyst> |
713 | |
714 | =head1 AUTHOR |
715 | |
716 | Sebastian Riedel, C<sri@oook.de> |
717 | |
718 | =head1 LICENSE |
719 | |
720 | This library is free software . You can redistribute it and/or modify it under |
721 | the same terms as perl itself. |
722 | |
723 | =cut |
724 | |
725 | 1; |