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