Commit | Line | Data |
0ba6e8aa |
1 | package Catalyst::Script::Create; |
a24a5860 |
2 | use Moose; |
ad8b4c91 |
3 | use MooseX::Types::Moose qw/Bool Str/; |
f4a497bb |
4 | use namespace::autoclean; |
4ebd5ecf |
5 | |
d3082fac |
6 | with 'Catalyst::ScriptRole'; |
73e4f0f1 |
7 | |
8 | has force => ( |
ad8b4c91 |
9 | traits => [qw(Getopt)], |
10 | cmd_aliases => 'nonew', |
11 | isa => Bool, |
12 | is => 'ro', |
d3082fac |
13 | documentation => 'Force new scripts', |
73e4f0f1 |
14 | ); |
15 | |
16 | has debug => ( |
ad8b4c91 |
17 | traits => [qw(Getopt)], |
18 | cmd_aliases => 'd', |
19 | isa => Bool, |
20 | is => 'ro', |
d3082fac |
21 | documentation => 'Force debug mode', |
73e4f0f1 |
22 | ); |
23 | |
24 | has mechanize => ( |
ad8b4c91 |
25 | traits => [qw(Getopt)], |
26 | cmd_aliases => 'mech', |
27 | isa => Bool, |
28 | is => 'ro', |
d3082fac |
29 | documentation => 'use WWW::Mechanize', |
73e4f0f1 |
30 | ); |
2824ec8d |
31 | |
ad8b4c91 |
32 | has helper_class => ( |
33 | isa => Str, |
34 | is => 'ro', |
35 | builder => '_build_helper_class', |
36 | ); |
37 | |
38 | sub _build_helper_class { 'Catalyst::Helper' } |
0a33c6d3 |
39 | |
2824ec8d |
40 | sub run { |
f4a497bb |
41 | my ($self) = @_; |
4ebd5ecf |
42 | |
754e86c6 |
43 | $self->_getopt_full_usage if !$self->ARGV->[0]; |
4ebd5ecf |
44 | |
0a33c6d3 |
45 | my $helper_class = $self->helper_class; |
46 | Class::MOP::load_class($helper_class); |
47 | my $helper = $helper_class->new( { '.newfiles' => !$self->force, mech => $self->mechanize } ); |
4ebd5ecf |
48 | |
f5325631 |
49 | $self->_getopt_full_usage unless $helper->mk_component( $self->application_name, @{$self->extra_argv} ); |
2824ec8d |
50 | |
51 | } |
4ebd5ecf |
52 | |
d6e8e664 |
53 | __PACKAGE__->meta->make_immutable; |
f4de8c99 |
54 | 1; |
4ebd5ecf |
55 | |
56 | =head1 NAME |
57 | |
d3082fac |
58 | Catalyst::Script::Create - Create a new Catalyst Component |
4ebd5ecf |
59 | |
60 | =head1 SYNOPSIS |
61 | |
cbaaecc0 |
62 | myapp_create.pl [options] model|view|controller name [helper] [options] |
4ebd5ecf |
63 | |
64 | Options: |
ad8b4c91 |
65 | --force don't create a .new file where a file to be created exists |
66 | --mechanize use Test::WWW::Mechanize::Catalyst for tests if available |
67 | --help display this help and exits |
4ebd5ecf |
68 | |
69 | Examples: |
d3082fac |
70 | myapp_create.pl controller My::Controller |
71 | myapp_create.pl controller My::Controller BindLex |
f5325631 |
72 | myapp_create.pl --mechanize controller My::Controller |
d3082fac |
73 | myapp_create.pl view My::View |
74 | myapp_create.pl view MyView TT |
75 | myapp_create.pl view TT TT |
76 | myapp_create.pl model My::Model |
77 | myapp_create.pl model SomeDB DBIC::Schema MyApp::Schema create=dynamic\ |
4ebd5ecf |
78 | dbi:SQLite:/tmp/my.db |
d3082fac |
79 | myapp_create.pl model AnotherDB DBIC::Schema MyApp::Schema create=static\ |
4ebd5ecf |
80 | dbi:Pg:dbname=foo root 4321 |
81 | |
82 | See also: |
83 | perldoc Catalyst::Manual |
84 | perldoc Catalyst::Manual::Intro |
85 | |
86 | =head1 DESCRIPTION |
87 | |
88 | Create a new Catalyst Component. |
89 | |
90 | Existing component files are not overwritten. If any of the component files |
91 | to be created already exist the file will be written with a '.new' suffix. |
ad8b4c91 |
92 | This behavior can be suppressed with the C<--force> option. |
4ebd5ecf |
93 | |
383c5be6 |
94 | =head1 SEE ALSO |
95 | |
96 | L<Catalyst::ScriptRunner> |
97 | |
4ebd5ecf |
98 | =head1 AUTHORS |
99 | |
100 | Catalyst Contributors, see Catalyst.pm |
101 | |
102 | =head1 COPYRIGHT |
103 | |
104 | This library is free software, you can redistribute it and/or modify |
105 | it under the same terms as Perl itself. |
106 | |
107 | =cut |
4f0612fd |
108 | |