From: Jonathan Rockway Date: Thu, 25 Jun 2009 19:26:06 +0000 (-0700) Subject: add friendly error message when giving argless plugins args X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=gitmo%2FMooseX-Runnable.git;a=commitdiff_plain;h=86c248d88a17d0e3a2a4a492231a5315a44ddbbb add friendly error message when giving argless plugins args --- diff --git a/lib/MooseX/Runnable/Invocation.pm b/lib/MooseX/Runnable/Invocation.pm index 644d246..2fb34b7 100644 --- a/lib/MooseX/Runnable/Invocation.pm +++ b/lib/MooseX/Runnable/Invocation.pm @@ -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, diff --git a/t/invocation-plugin-initargs.t b/t/invocation-plugin-initargs.t index 376335d..e8f5996 100644 --- a/t/invocation-plugin-initargs.t +++ b/t/invocation-plugin-initargs.t @@ -1,7 +1,7 @@ use strict; use warnings; use Test::Exception; -use Test::More tests => 4; +use Test::More tests => 6; use MooseX::Runnable::Invocation; @@ -26,6 +26,10 @@ my $initargs; } } +{ package Argless; + use Moose::Role; +} + my $i; lives_ok { $i = MooseX::Runnable::Invocation->new( @@ -40,5 +44,20 @@ ok $i, 'created invocation ok'; ok $i->run, 'ran ok'; is $initargs, 'foo,bar,baz', 'got initargs'; +throws_ok { + MooseX::Runnable::Invocation->new( + class => 'Class', + plugins => { + '+Argless' => ['args go here'], + }, + ); +} qr/Perhaps/, 'argless + args = error'; - +lives_ok { + MooseX::Runnable::Invocation->new( + class => 'Class', + plugins => { + '+Argless' => [], + }, + ); +} 'argless + no args = ok';