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