}
}
+
+sub _convert_role_to_scheme {
+ my ($self, $role) = @_;
+
+ my $name = $role->name;
+ return if $name =~ /\|/;
+ $name = "MooseX::Runnable::Invocation::Scheme::$name";
+
+ return eval {
+ Class::MOP::load_class($name);
+ warn "$name was loaded OK, but it's not a role!" and return
+ unless $name->meta->isa('Moose::Meta::Role');
+ return $name->meta;
+ };
+}
+
+
sub validate_class {
my ($self, $class) = @_;
return; # return value is meaningless
}
-sub _convert_role_to_scheme {
- my ($self, $role) = @_;
-
- my $name =
-
- return;
-}
-
sub create_instance {
my ($self, $class, @args) = @_;
return ($class->name->new, @args);
--- /dev/null
+package MooseX::Runnable::Invocation::Scheme::MooseX::Getopt;
+use Moose::Role;
+
+around validate_class => sub {
+ return; # always valid
+};
+
+around create_instance => sub {
+ my ($next, $self, $class, @args) = @_;
+
+ local @ARGV = @args; # ugly!
+ my $instance = $class->name->new_with_options();
+
+ my $more_args = $instance->extra_argv;
+
+ return ($instance, @$more_args);
+};
+
+1;
--- /dev/null
+use strict;
+use warnings;
+use Test::Exception;
+use Test::More tests => 5;
+
+use MooseX::Runnable::Invocation;
+use ok 'MooseX::Runnable::Invocation::Scheme::MooseX::Getopt';
+
+my $foo;
+
+{ package Class;
+ use Moose;
+ with 'MooseX::Runnable', 'MooseX::Getopt';
+
+ has 'foo' => (
+ is => 'ro',
+ isa => 'Str',
+ required => 1,
+ );
+
+ sub run {
+ my ($self, $code) = @_;
+ $foo = $self->foo;
+ return $code;
+ }
+}
+
+my $invocation = MooseX::Runnable::Invocation->new(
+ class => 'Class',
+);
+
+ok $invocation;
+
+my $code;
+lives_ok {
+ $code = $invocation->run('--foo', '42', 0);
+} 'run lived';
+
+is $foo, '42', 'got foo from cmdline';
+
+is $code, 0, 'exit status ok';