add friendly error message when giving argless plugins args
[gitmo/MooseX-Runnable.git] / lib / MooseX / Runnable / Invocation.pm
index 644d246..2fb34b7 100644 (file)
@@ -45,8 +45,11 @@ sub BUILD {
 
         Class::MOP::load_class( $plugin );
 
+        my $does_cmdline = $plugin->meta->
+          does_role('MooseX::Runnable::Invocation::Plugin::Role::CmdlineArgs');
+
         my $args;
-        if($plugin->meta->does_role('MooseX::Runnable::Invocation::Plugin::Role::CmdlineArgs')){
+        if($does_cmdline){
             $args = eval {
                 $plugin->_build_initargs_from_cmdline(
                     @{$self->plugins->{$orig}},
@@ -57,6 +60,13 @@ sub BUILD {
                 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(
             $self,