#!/usr/bin/env perl use strict; use warnings; use MooseX::Runnable::Run; # incidentally, we don't actually use this... exit run(); sub run { my ($includes, $plugins, $app, $argv) = parse_argv(); unshift @INC, $_ for @$includes; help() unless $app; local $0 = "mx-run ... $app"; return MooseX::Runnable::Invocation->new( class => $app, plugins => $plugins || [], )->run(@$argv); } sub parse_argv { # we need to parse "incrementally" so we can identify: # - our args (-Ilib, and --help, -h, and -?) # - plugins to load (+Plugin) # - the class name # - the class' args # code that's better than this is welcome! my (@include, @plugins, $app); while( my $arg = shift @ARGV ){ if ($arg =~ /^-I([^-]+)/){ # XXX: handle -I"quoted string" ? push @include, $1; } elsif ($arg =~ /^-M([^-]+)/){ my $module = $1; eval "use $module"; die $@ if $@; } elsif ($arg =~ /^\+\+?([A-Za-z:_]+)$/){ # second + is for +Foo::Bar push @plugins, $1; } elsif ($arg =~ /^--([^-]+)$/){ help(); } else { if($arg =~ /^([A-Za-z:_]+)$/){ $app = $arg; last; } else { help(); } } } return \@include, \@plugins, $app, \@ARGV; } sub help { print <<'END'; This is mx-run, a utility for running MooseX::Runnable classes. usage: mx-run Class::Name mx-run options: --help -? -h Print this message -I Add to @INC before loading Class::Name -M use immediately +PluginName Load PluginName (see MooseX::Runnable::Invocation) Note that as soon as +PluginName is seen, all -[IM] options are ignored by mx-run, and are instead processed by PluginName. To get help for Class::Name, run: mx-run Class::Name --help END exit 1; } __END__ =head1 NAME mx-run - script to run MooseX::Runnable classes