Skip to content

Commit

Permalink
add _osprey_{options,config,subcommands} to the command class via CLI…
Browse files Browse the repository at this point in the history
…::Osprey::Role

The CLI::Osprey::Role is already getting applied to the command class,
so the application of the _osprey_options, _osprey_config, and
_osprey_subcommands methods can done more naturally there instead of
in an eval() in CLI::Osprey::import.
  • Loading branch information
djerius committed Nov 21, 2018
1 parent 0ad1e54 commit 80a7021
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 22 deletions.
20 changes: 0 additions & 20 deletions lib/CLI/Osprey.pm
Original file line number Diff line number Diff line change
Expand Up @@ -27,26 +27,6 @@ sub import {
or croak "Can't find the method '$_' in package '$target'. CLI::Osprey requires a Role::Tiny-compatible object system like Moo or Moose.";
} qw[ with around has ];

if ( ! Moo::Role->is_role( $target ) ) { # not in a role
eval "package $target;\n" . q{
sub _osprey_options {
my $class = shift;
return $class->maybe::next::method(@_);
}
sub _osprey_config {
my $class = shift;
return $class->maybe::next::method(@_);
}
sub _osprey_subcommands {
my $class = shift;
return $class->maybe::next::method(@_);
}
1;
} || croak($@);
}

my $osprey_config = {
preserve_argv => 1,
abbreviate => 1,
Expand Down
17 changes: 15 additions & 2 deletions lib/CLI/Osprey/Role.pm
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,6 @@ sub _osprey_fix_argv {

use Moo::Role;

requires qw(_osprey_config _osprey_options _osprey_subcommands);

has 'parent_command' => (
is => 'ro',
);
Expand All @@ -130,6 +128,21 @@ has 'invoked_as' => (
is => 'ro',
);

sub _osprey_options {
my $class = shift;
return $class->maybe::next::method(@_);
}

sub _osprey_config {
my $class = shift;
return $class->maybe::next::method(@_);
}

sub _osprey_subcommands {
my $class = shift;
return $class->maybe::next::method(@_);
}

sub new_with_options {
my ($class, %params) = @_;
my %config = $class->_osprey_config;
Expand Down

0 comments on commit 80a7021

Please sign in to comment.