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