1586e63bf797d6216291294cf3fb82917a29ff0f
[gitmo/MooseX-Runnable.git] / bin / mx-run
1 #!/usr/bin/env perl
2
3 use strict;
4 use warnings;
5
6 use MooseX::Runnable::Util::ArgParser;
7 use MooseX::Runnable::Run; # incidentally, we don't actually use this...
8
9 exit run();
10
11 sub run {
12     my $args = MooseX::Runnable::Util::ArgParser->new(
13         argv => \@ARGV,
14     );
15
16     help() if $args->is_help;
17
18     # set @INC from -I...
19     unshift @INC, $_->stringify for $args->include_paths;
20
21     # load -M... modules
22     do { eval "require $_"; die $@ if $@ }
23       for $args->modules;
24
25     my $app = $args->class_name;
26     local $0 = "mx-run ... $app";
27
28     return MooseX::Runnable::Invocation->new(
29         class   => $app,
30         plugins => [ keys %{$args->plugins} ], # XXX: fixme
31     )->run($args->app_args);
32 }
33
34 sub help {
35     print <<'END';
36
37 This is mx-run, a utility for running MooseX::Runnable classes.
38
39 usage: mx-run <mx-run options> -- Class::Name <options for Class::Name>
40
41 mx-run options:
42
43     --help -? -h     Print this message
44     -I<path>         Add <path> to @INC before loading modules
45     -M<module>       use <module> immediately
46     +PluginName      Load PluginName (see MooseX::Runnable::Invocation)
47
48 Note that as soon as +PluginName is seen, all following -[IM] options
49 are ignored by mx-run, and are instead processed by PluginName.  So
50 put them at the very beginning.
51
52 In the simplest cases, where you use only -I or -M (no plugins), you
53 may omit the -- before the class name.
54
55 To get help for Class::Name, run:
56
57     mx-run Class::Name --help
58
59 Syntax examples:
60
61     mx-run -Ilib Class::Name                          # Local Class::Name
62     mx-run -Ilib -MCarp::Always +Debug -- Class::Name # Debugging
63
64 END
65
66     exit 1;
67 }
68
69 __END__
70
71 =head1 NAME
72
73 mx-run - script to run MooseX::Runnable classes