forked from OfferKaye/moosex-app-cmd
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add MouseX wrapper classes and tests
- Loading branch information
Showing
9 changed files
with
200 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
use 5.006; | ||
|
||
package MouseX::App::Cmd; | ||
use Mouse; | ||
|
||
# VERSION | ||
use namespace::clean -except => 'meta'; | ||
extends 'MooseX::App::Cmd'; | ||
__PACKAGE__->meta->make_immutable(); ## no critic (RequireExplicitInclusion) | ||
no Mouse; | ||
1; | ||
|
||
# ABSTRACT: Mashes up MouseX::Getopt and App::Cmd | ||
|
||
=head1 SYNOPSIS | ||
package YourApp::Cmd; | ||
use Mouse; | ||
extends qw(MouseX::App::Cmd); | ||
package YourApp::Cmd::Command::blort; | ||
use Mouse; | ||
extends qw(MouseX::App::Cmd::Command); | ||
has blortex => ( | ||
traits => [qw(Getopt)], | ||
isa => 'Bool', | ||
is => 'rw', | ||
cmd_aliases => 'X', | ||
documentation => 'use the blortext algorithm', | ||
); | ||
has recheck => ( | ||
traits => [qw(Getopt)], | ||
isa => 'Bool', | ||
is => 'rw', | ||
cmd_aliases => 'r', | ||
documentation => 'recheck all results', | ||
); | ||
sub execute { | ||
my ( $self, $opt, $args ) = @_; | ||
# you may ignore $opt, it's in the attributes anyway | ||
my $result = $self->blortex ? blortex() : blort(); | ||
recheck($result) if $self->recheck; | ||
print $result; | ||
} | ||
=head1 DESCRIPTION | ||
This module marries L<App::Cmd|App::Cmd> with L<MouseX::Getopt|MouseX::Getopt>. | ||
It extends L<MooseX::App::Cmd|MooseX::App::Cmd> which uses | ||
L<Any::Moose|Any::Moose> to work with either L<Moose|Moose> or | ||
L<Mouse|Mouse>. Consult those modules' documentation for full | ||
usage information. | ||
=head1 SEE ALSO | ||
=over | ||
=item L<MooseX::App::Cmd|MooseX::App::Cmd> | ||
=item L<App::Cmd|App::Cmd> | ||
=item L<App::Cmd::Tutorial|App::Cmd::Tutorial> | ||
=item L<MouseX::Getopt|MouseX::Getopt> | ||
=item L<MouseX::App::Cmd::Command|MouseX::App::Cmd::Command> | ||
=back |
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,52 @@ | ||
use 5.006; | ||
|
||
package MouseX::App::Cmd::Command; | ||
use Mouse; | ||
|
||
# VERSION | ||
use namespace::clean -except => 'meta'; | ||
extends 'MooseX::App::Cmd::Command'; | ||
__PACKAGE__->meta->make_immutable(); ## no critic (RequireExplicitInclusion) | ||
no Mouse; | ||
1; | ||
|
||
# ABSTRACT: Base class for MouseX::Getopt based App::Cmd::Commands | ||
|
||
=head1 SYNOPSIS | ||
use Mouse; | ||
extends qw(MouseX::App::Cmd::Command); | ||
# no need to set opt_spec | ||
# see MouseX::Getopt for documentation on how to specify options | ||
has option_field => ( | ||
isa => 'Str', | ||
is => 'rw', | ||
required => 1, | ||
); | ||
sub execute { | ||
my ( $self, $opts, $args ) = @_; | ||
print $self->option_field; # also available in $opts->{option_field} | ||
} | ||
=head1 DESCRIPTION | ||
This is a replacement base class for L<App::Cmd::Command|App::Cmd::Command> | ||
classes that includes | ||
L<MouseX::Getopt|MooseX::Getopt> and the glue to combine the two. | ||
It extends C<MouseX::App::Cmd::Command> which uses | ||
L<Any::Moose|Any::Moose> to work with either L<Moose|Moose> or | ||
L<Mouse|Mouse>. Consult those modules' documentation for full | ||
usage information. | ||
=head1 SEE ALSO | ||
=over | ||
=item L<MooseX::App::Cmd::Command|MooseX::App::Cmd::Command> | ||
=back |
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 Test::MyAny::Moose; | ||
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,19 @@ | ||
package Test::MyAny::Moose::Command::foo; | ||
use Moose; | ||
|
||
extends 'MooseX::App::Cmd::Command'; | ||
|
||
has bar => ( | ||
isa => 'Str', | ||
is => 'ro', | ||
required => 1, | ||
documentation => 'required option field', | ||
); | ||
|
||
sub execute { | ||
my ( $self, $opt, $arg ) = @_; | ||
|
||
die 'my Moose bar is ', $self->bar . "\n"; | ||
} | ||
|
||
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,6 @@ | ||
package Test::MyAny::Mouse; | ||
use Mouse; | ||
|
||
extends qw(MouseX::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,19 @@ | ||
package Test::MyAny::Mouse::Command::foo; | ||
use Mouse; | ||
|
||
extends 'MouseX::App::Cmd::Command'; | ||
|
||
has bar => ( | ||
isa => 'Str', | ||
is => 'ro', | ||
required => 1, | ||
documentation => 'required option field', | ||
); | ||
|
||
sub execute { | ||
my ( $self, $opt, $arg ) = @_; | ||
|
||
die 'my Mouse bar is ', $self->bar . "\n"; | ||
} | ||
|
||
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,8 @@ | ||
#!perl -T | ||
|
||
use strict; | ||
use warnings; | ||
use Test::More tests => 1; | ||
use lib 't/lib'; | ||
use Test::MyAny::Moose; | ||
my $cmd = new_ok('Test::MyAny::Moose'); |
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,8 @@ | ||
#!perl -T | ||
|
||
use strict; | ||
use warnings; | ||
use Test::More tests => 1; | ||
use lib 't/lib'; | ||
use Test::MyAny::Mouse; | ||
my $cmd = new_ok('Test::MyAny::Mouse'); |