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