Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
allow subcommands for poet via MooseX::App::Cmd
- Loading branch information
Showing
7 changed files
with
78 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package Poet::App; | ||
use Moose; | ||
|
||
extends qw(MooseX::App::Cmd); | ||
|
||
1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package Poet::App::Command::new; | ||
use Poet::Moose; | ||
use Poet::Types; | ||
|
||
extends 'MooseX::App::Cmd::Command'; | ||
|
||
has 'app_name' => ( required => 1, isa => 'Poet::Types::AppName', traits => ['Getopt'], cmd_flag => 'app-name', cmd_aliases => 'a', documentation => 'Name of app, e.g. MyApp or ABC (required)' ); | ||
has 'dir' => ( isa => 'Str', traits => ['Getopt'], cmd_aliases => 'd', lazy_build => 1, documentation => 'Directory to create; will adapt from app-name if ommitted' ); | ||
has 'quiet' => ( isa => 'Bool', traits => ['Getopt'], cmd_aliases => 'q', documentation => 'Suppress most messages' ); | ||
|
||
method _build_dir () { | ||
return $self->app_name_to_dir( $self->app_name ); | ||
} | ||
|
||
method app_name_to_dir ($app_name) { | ||
my $dir; | ||
if ( $app_name =~ /^[A-Z]+$/ ) { | ||
$dir = lc($app_name); | ||
} | ||
else { | ||
$dir = lcfirst($app_name); | ||
$dir =~ s/([A-Z])/"_" . lc($1)/ge; | ||
} | ||
return $dir; | ||
} | ||
|
||
method abstract () { | ||
"Create a new Poet installation"; | ||
} | ||
|
||
method execute () { | ||
require Poet::Environment::Generator; | ||
Poet::Environment::Generator->generate_environment_directory( | ||
root_dir => $self->dir, | ||
app_name => $self->app_name, | ||
quiet => $self->quiet | ||
); | ||
} | ||
|
||
1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package Poet::Types; | ||
use Moose::Util::TypeConstraints; | ||
use strict; | ||
use warnings; | ||
|
||
subtype | ||
'Poet::Types::AppName' => as 'Str', | ||
where { /^[[:alpha:]_]\w*$/ }, | ||
message { "The app name you provided, '$_', was not a valid identifier" }; | ||
|
||
1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package Poet::t::App; | ||
use Poet::Test::Util; | ||
use Test::Most; | ||
use strict; | ||
use warnings; | ||
use base qw(Test::Class); | ||
|
||
sub test_app_name_to_dir : Tests { | ||
require Poet::App::Command::new; | ||
|
||
my $try = sub { | ||
return Poet::App::Command::new->app_name_to_dir( $_[0] ); | ||
}; | ||
is( $try->("FooBar"), "foo_bar" ); | ||
is( $try->("HM"), "hm" ); | ||
} | ||
|
||
1; |