sugaryify mx-run
[gitmo/MooseX-Runnable.git] / bin / mx-run
CommitLineData
c527660e 1#!/usr/bin/env perl
2
3use strict;
4use warnings;
5
441297a7 6use MooseX::Runnable::Run; # incidentally, we don't actually use this...
7
8exit run();
9
10sub run {
11 my ($includes, $plugins, $app, $argv) = parse_argv();
12
13 unshift @INC, $_ for @$includes;
14 help() unless $app;
15
16 return MooseX::Runnable::Invocation->new(
17 class => $app,
18 plugins => $plugins || [],
19 )->run(@$argv);
20}
21
22sub parse_argv {
23 # we need to parse "incrementally" so we can identify:
24 # - our args (-Ilib, and --help, -h, and -?)
25 # - plugins to load (+Plugin)
26 # - the class name
27 # - the class' args
28 # code that's better than this is welcome!
29
30 my (@include, @plugins, $app);
31
32 while( my $arg = shift @ARGV ){
33 if ($arg =~ /^-I([^-]+)/){ # XXX: handle -I"quoted string" ?
34 push @include, $1;
35 }
36 elsif ($arg =~ /^\+\+?([A-Za-z:_]+)$/){ # second + is for +Foo::Bar
37 push @plugins, $1;
38 }
39 elsif ($arg =~ /^--([^-]+)$/){
40 help();
41 }
42 else {
43 if($arg =~ /^([A-Za-z:_]+)$/){
44 $app = $arg;
45 last;
46 }
47 else {
48 help();
49 }
50 }
51 }
52
53 return \@include, \@plugins, $app, \@ARGV;
54}
55
56sub help {
57 print <<'END';
58
59This is mx-run, a utility for running MooseX::Runnable classes.
60usage: mx-run <mx-run options> Class::Name <options for Class::Name>
61mx-run options:
62
63 --help -? -h Print this message
64 +PluginName Load PluginName (see MooseX::Runnable::Invocation)
65 -I<path> Add <path> to @INC before loading Class::Name
66
67To get help for Class::Name, run:
68
69 mx-run Class::Name --help
70END
71
72 exit 1;
73}
c527660e 74
75__END__
76
77=head1 NAME
78
79mx-run - script to run MooseX::Runnable classes