From 80a7021141e81bf3d6e202ec887df10dc6ceee23 Mon Sep 17 00:00:00 2001 From: Diab Jerius Date: Wed, 21 Nov 2018 17:40:41 -0500 Subject: [PATCH] add _osprey_{options,config,subcommands} to the command class via CLI::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. --- lib/CLI/Osprey.pm | 20 -------------------- lib/CLI/Osprey/Role.pm | 17 +++++++++++++++-- 2 files changed, 15 insertions(+), 22 deletions(-) diff --git a/lib/CLI/Osprey.pm b/lib/CLI/Osprey.pm index d353a62..f77823d 100644 --- a/lib/CLI/Osprey.pm +++ b/lib/CLI/Osprey.pm @@ -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, diff --git a/lib/CLI/Osprey/Role.pm b/lib/CLI/Osprey/Role.pm index d300a3c..8c15a77 100644 --- a/lib/CLI/Osprey/Role.pm +++ b/lib/CLI/Osprey/Role.pm @@ -120,8 +120,6 @@ sub _osprey_fix_argv { use Moo::Role; -requires qw(_osprey_config _osprey_options _osprey_subcommands); - has 'parent_command' => ( is => 'ro', ); @@ -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;