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