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 $args;
+ if($plugin->meta->does_role('MooseX::Runnable::Invocation::Plugin::Role::CmdlineArgs')){
+ $args = eval {
+ $plugin->_build_initargs_from_cmdline(
+ @{$self->plugins->{$orig}},
+ );
+ };
+
+ if($@) {
+ confess "Error building initargs for $plugin: $@";
+ }
}
$plugin->meta->apply(
package MooseX::Runnable::Invocation::Plugin::Debug;
use Moose::Role;
+with 'MooseX::Runnable::Invocation::Plugin::Role::CmdlineArgs';
+
# this is an example to cargo-cult, rather than a useful feature :)
has 'debug_prefix' => (
is => 'ro',
use AnyEvent;
use namespace::autoclean;
-with 'MooseX::Runnable::Invocation::Plugin::Restart::Base';
+with 'MooseX::Runnable::Invocation::Plugin::Restart::Base',
+ 'MooseX::Runnable::Invocation::Plugin::Role::CmdlineArgs';
has 'completion_condvar' => (
is => 'ro',
use MooseX::Types::Moose qw(ArrayRef RegexpRef Any Str);
use MooseX::Types::Path::Class qw(Dir);
use File::ChangeNotify;
+use namespace::autoclean;
# coerce ArrayRef[Dir], from ArrayRef[Any], via {[
# map { warn $_; Path::Class::dir($_) } @$_,
coerce RegexpRef, from Str, via { qr/$_/i };
-use namespace::autoclean;
-with 'MooseX::Runnable::Invocation::Plugin::Restart::Base';
+with 'MooseX::Runnable::Invocation::Plugin::Restart::Base',
+ 'MooseX::Runnable::Invocation::Plugin::Role::CmdlineArgs';
has 'watch_regexp' => (
is => 'ro',
while(1){
my @events = $self->watcher->wait_for_events();
$self->restart;
- sleep .5; # "debounce" the notifier
}
}
--- /dev/null
+package MooseX::Runnable::Invocation::Plugin::Role::CmdlineArgs;
+use Moose::Role;
+
+requires '_build_initargs_from_cmdline';
+
+1;
--- /dev/null
+use strict;
+use warnings;
+use Test::Exception;
+use Test::More tests => 4;
+
+use MooseX::Runnable::Invocation;
+
+my $initargs;
+
+{ package Class;
+ use Moose;
+ with 'MooseX::Runnable';
+ sub run { 42 }
+}
+
+{ package Plugin;
+ use Moose::Role;
+ with 'MooseX::Runnable::Invocation::Plugin::Role::CmdlineArgs';
+
+ has 'init' => ( is => 'ro', required => 1 );
+
+ sub _build_initargs_from_cmdline {
+ my $class = shift;
+ $initargs = join ',', @_;
+ return { init => 'args' };
+ }
+}
+
+my $i;
+lives_ok {
+ $i = MooseX::Runnable::Invocation->new(
+ class => 'Class',
+ plugins => {
+ '+Plugin' => [qw/foo bar baz/],
+ },
+ );
+} 'created invocation without dying';
+
+ok $i, 'created invocation ok';
+ok $i->run, 'ran ok';
+is $initargs, 'foo,bar,baz', 'got initargs';
+
+
+