Skip to content

Commit

Permalink
add MouseX wrapper classes and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mjgardner committed Dec 1, 2013
1 parent 8e675be commit 601e072
Show file tree
Hide file tree
Showing 9 changed files with 200 additions and 3 deletions.
79 changes: 79 additions & 0 deletions lib/MouseX/App/Cmd.pm
@@ -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
52 changes: 52 additions & 0 deletions lib/MouseX/App/Cmd/Command.pm
@@ -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
6 changes: 3 additions & 3 deletions perlcritic.rc
Expand Up @@ -16,13 +16,13 @@ lib_sections = NAME | VERSION | DESCRIPTION | SYNOPSIS | COPYRIGHT AND LICENS
script_sections = NAME | USAGE | OPTIONS | EXIT STATUS | COPYRIGHT AND LICENSE

[Subroutines::ProhibitCallsToUndeclaredSubs]
exempt_subs = Any::Moose::any_moose Any::Moose::blessed Any::Moose::extends Any::Moose::has Any::Moose::override Any::Moose::with
exempt_subs = Any::Moose::any_moose Any::Moose::blessed Any::Moose::extends Any::Moose::has Any::Moose::override Any::Moose::with Mouse::extends

[Subroutines::ProhibitUnusedPrivateSubroutines]
private_name_regex = _(?!build_)\w+

[TestingAndDebugging::RequireUseStrict]
equivalent_modules = Any::Moose
equivalent_modules = Any::Moose Mouse

[TestingAndDebugging::RequireUseWarnings]
equivalent_modules = Any::Moose
equivalent_modules = Any::Moose Mouse
6 changes: 6 additions & 0 deletions t/lib/Test/MyAny/Moose.pm
@@ -0,0 +1,6 @@
package Test::MyAny::Moose;
use Moose;

extends qw(MooseX::App::Cmd);

1;
19 changes: 19 additions & 0 deletions t/lib/Test/MyAny/Moose/Command/foo.pm
@@ -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;
6 changes: 6 additions & 0 deletions t/lib/Test/MyAny/Mouse.pm
@@ -0,0 +1,6 @@
package Test::MyAny::Mouse;
use Mouse;

extends qw(MouseX::App::Cmd);

1;
19 changes: 19 additions & 0 deletions t/lib/Test/MyAny/Mouse/Command/foo.pm
@@ -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;
8 changes: 8 additions & 0 deletions t/moose.t
@@ -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');
8 changes: 8 additions & 0 deletions t/mouse.t
@@ -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');

0 comments on commit 601e072

Please sign in to comment.