| 1 | package Poet::App::Command::new; | ||||||||||
| 2 | 1 | $Poet::App::Command::new::VERSION = '0.16'; | |||||||||
| 3 | 1 | ▶ | use Poet::Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use Poet::Types; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 1 | extends 'Poet::App::Command'; | |||||||||
| 7 | |||||||||||
| 8 | 1 | has 'app_name' => ( isa => 'Poet::Types::AppName', is => 'rw', traits => [ 'NoGetopt' ] ); | |||||||||
| 9 | 1 | has 'dir' => ( isa => 'Str', traits => ['Getopt'], cmd_aliases => 'd', lazy_build => 1, documentation => 'Directory to create; will adapt from app-name if ommitted' ); | |||||||||
| 10 | 1 | has 'quiet' => ( isa => 'Bool', traits => ['Getopt'], cmd_aliases => 'q', documentation => 'Suppress most messages' ); | |||||||||
| 11 | |||||||||||
| 12 | 1 | my $description = 'Generates a new Poet environment for an app with the provided name, which | |||||||||
| 13 | should be suitable for use in Perl classnames (e.g. "MyFirstApp"). If not | ||||||||||
| 14 | provided, a directory is chosen by lowercasing and underscoring the app | ||||||||||
| 15 | name. | ||||||||||
| 16 | |||||||||||
| 17 | % poet new MyApp | ||||||||||
| 18 | my_app/.poet_root | ||||||||||
| 19 | my_app/bin/app.psgi | ||||||||||
| 20 | my_app/bin/get.pl | ||||||||||
| 21 | ... | ||||||||||
| 22 | Now run \'my_app/bin/run.pl\' to start your server. | ||||||||||
| 23 | |||||||||||
| 24 | Options:'; | ||||||||||
| 25 | |||||||||||
| 26 | 0 | ▶ | method abstract () { "Create a new Poet installation" } | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=2.0
Subroutine
abstract: not called CC=1 SCAR=2.0
| |||||||||||
| 27 | 0 | ▶ | method description () { $description } | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=2.0
Subroutine
__ANON__: not called CC=1 SCAR=2.0
| |||||||||||
| 28 | 0 | ▶ | method usage_desc () { "poet new [-d dir] [-q] <AppName>" } | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=2.0
Subroutine
__ANON__: not called CC=1 SCAR=2.0
| |||||||||||
| 29 | |||||||||||
| 30 | 0 | ▶ | method _build_dir () { | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
Subroutine
_build_dir: not called CC=1 SCAR=3.5
| |||||||||||
| 31 | 0 | return $self->app_name_to_dir( $self->app_name ); | |||||||||
| 32 | 1 | } | |||||||||
| 33 | |||||||||||
| 34 | 1 | ▶ | method app_name_to_dir ($app_name) { | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
app_name_to_dir: called CC=2 SCAR=6.9
| |||||||||||
| 35 | 3 | my $dir; | |||||||||
| 36 | 3 | ▶ | if ( $app_name =~ /^[A-Z]+$/ ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 37 | 1 | $dir = lc($app_name); | |||||||||
| 38 | } | ||||||||||
| 39 | else { | ||||||||||
| 40 | 2 | $dir = lcfirst($app_name); | |||||||||
| 41 | 2 | $dir =~ s/([A-Z])/"_" . lc($1)/ge; | |||||||||
| 42 | } | ||||||||||
| 43 | 3 | return $dir; | |||||||||
| 44 | 1 | } | |||||||||
| 45 | |||||||||||
| 46 | 0 | ▶ | method execute ($opt, $args) { | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=3.5
Subroutine
__ANON__: not called CC=2 SCAR=16.4
| |||||||||||
| 47 | 0 | ▶ | $self->usage_error("takes one argument (app name)") unless @$args == 1; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 48 | |||||||||||
| 49 | 0 | my $app_name = ucfirst( $args->[0] ); | |||||||||
| 50 | 0 | $app_name =~ s/_([a-z])/uc($1)/ge; | |||||||||
| 51 | 0 | $self->app_name($app_name); | |||||||||
| 52 | |||||||||||
| 53 | 0 | require Poet::Environment::Generator; | |||||||||
| 54 | 0 | Poet::Environment::Generator->generate_environment_directory( | |||||||||
| 55 | root_dir => $self->dir, | ||||||||||
| 56 | app_name => $self->app_name, | ||||||||||
| 57 | quiet => $self->quiet | ||||||||||
| 58 | ); | ||||||||||
| 59 | 1 | } | |||||||||
| 60 | |||||||||||
| 61 | 1 | 1; | |||||||||