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