bugfix; bump to 0.02
[gitmo/MooseX-Runnable.git] / lib / MooseX / Runnable / Invocation.pm
index 8ff092d..3ebc1b1 100644 (file)
@@ -2,6 +2,7 @@ package MooseX::Runnable::Invocation;
 use Moose;
 use MooseX::Types -declare => ['RunnableClass'];
 use MooseX::Types::Moose qw(Str HashRef ArrayRef);
+use List::MoreUtils qw(uniq);
 use namespace::autoclean;
 
 require Class::MOP;
@@ -45,13 +46,27 @@ sub BUILD {
 
         Class::MOP::load_class( $plugin );
 
-        my $args = eval {
-            $plugin->_build_initargs_from_cmdline(
-                @{$self->plugins->{$orig}},
-            );
-        };
-        if($@ && $plugin->can('_build_initargs_from_cmdline')){
-            confess "Error building initargs for $plugin: $@";
+        my $does_cmdline = $plugin->meta->
+          does_role('MooseX::Runnable::Invocation::Plugin::Role::CmdlineArgs');
+
+        my $args;
+        if($does_cmdline){
+            $args = eval {
+                $plugin->_build_initargs_from_cmdline(
+                    @{$self->plugins->{$orig}},
+                );
+            };
+
+            if($@) {
+                confess "Error building initargs for $plugin: $@";
+            }
+        }
+        elsif(!$does_cmdline && scalar @{$self->plugins->{$orig}} > 0){
+            confess "You supplied arguments to the $orig plugin, but it".
+              " does not know how to accept them.  Perhaps the plugin".
+              " should consume the".
+              " 'MooseX::Runnable::Invocation::Plugin::Role::CmdlineArgs'".
+              " role?";
         }
 
         $plugin->meta->apply(
@@ -86,11 +101,13 @@ sub apply_scheme {
     my ($self, $class) = @_;
 
     my @schemes = grep { defined } map {
-        $self->_convert_role_to_scheme($_)
-    } $class->calculate_all_roles;
+        eval { $self->_convert_role_to_scheme($_) }
+    } map {
+        eval { $_->meta->calculate_all_roles };
+    } $class->linearized_isa;
 
     eval {
-        foreach my $scheme (@schemes) {
+        foreach my $scheme (uniq @schemes) {
             $scheme->apply($self);
         }
     };