Tidy up help and TODO tests
[catagits/Catalyst-Runtime.git] / lib / Catalyst / Script / Create.pm
1 package Catalyst::Script::Create;
2 use Moose;
3 use MooseX::Types::Moose qw/Bool/;
4 use namespace::autoclean;
5
6 with 'Catalyst::ScriptRole';
7
8 has force => (
9     traits => [qw(Getopt)],
10     cmd_aliases => 'nonew',
11     isa => Bool,
12     is => 'ro',
13     documentation => 'Force new scripts',
14 );
15
16 has debug => (
17     traits => [qw(Getopt)],
18     cmd_aliases => 'd',
19     isa => Bool,
20     is => 'ro',
21     documentation => 'Force debug mode',
22 );
23
24 has mechanize => (
25     traits => [qw(Getopt)],
26     cmd_aliases => 'mech',
27     isa => Bool,
28     is => 'ro',
29     documentation => 'use WWW::Mechanize',
30 );
31
32 has helper_class => ( isa => 'Str', is => 'ro', default => 'Catalyst::Helper' );
33
34 sub run {
35     my ($self) = @_;
36
37     $self->_exit_with_usage if !$ARGV[0];
38
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 } );
42
43     $self->_exit_with_usage unless $helper->mk_component( $self->application_name, @ARGV );
44
45 }
46
47 __PACKAGE__->meta->make_immutable;
48
49 =head1 NAME
50
51 Catalyst::Script::Create - Create a new Catalyst Component
52
53 =head1 SYNOPSIS
54
55  myapp_create.pl [options] model|view|controller name [helper] [options]
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:
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\
71    dbi:SQLite:/tmp/my.db
72    myapp_create.pl model AnotherDB DBIC::Schema MyApp::Schema create=static\
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
81 Create a new Catalyst Component.
82
83 Existing component files are not overwritten.  If any of the component files
84 to be created already exist the file will be written with a '.new' suffix.
85 This behavior can be suppressed with the C<-force> option.
86
87 =head1 AUTHORS
88
89 Catalyst Contributors, see Catalyst.pm
90
91 =head1 COPYRIGHT
92
93 This library is free software, you can redistribute it and/or modify
94 it under the same terms as Perl itself.
95
96 =cut
97