parse the args to mx-run sanely
[gitmo/MooseX-Runnable.git] / lib / MooseX / Runnable.pm
CommitLineData
d42333d2 1package MooseX::Runnable;
2use Moose::Role;
3
d42333d2 4requires 'run';
5
c527660e 61;
7
8__END__
9
10=head1 NAME
11
12MooseX::Runnable - tag a class as a runnable application
13
14=head1 SYNOPSIS
d42333d2 15
c527660e 16Create a class, tag it runnable, and provide a C<run> method:
17
18 package App::HelloWorld;
19 use Moose;
20
21 with 'MooseX::Runnable';
22
23 sub run {
24 my $name = shift;
25 say "Hello, $name.";
00d7989a 26 return 0; # success
d42333d2 27 }
28
c527660e 29Then you can run this class as an application with the included
30C<mx-run> script:
d42333d2 31
c527660e 32 $ mx-run App::HelloWorld jrockway
33 Hello, jrockway.
34 $
35
36C<MooseX::Runnable> supports L<MooseX::Getopt|MooseX::Getopt>, and
37other similar systems (and is extensible, in case you have written
38such a system).
39
40=head1 DESCRIPTION
41
42MooseX::Runnable is a framework for making classes runnable
43applications. This role doesn't do anything other than tell the rest
44of the framework that your class is a runnable application that has a
45C<run> method which accepts arguments and returns the process' exit
46code.
47
48This is a convention that the community has been using for a while.
49This role tells the computer that your class uses this convention, and
50let's the computer abstract away some of the tedium this entails.
51
52=head1 REQUIRED METHODS
53
54=head1 THINGS YOU GET
55
56=head2 C<mx-run>
57
58This is a script that accepts a C<MooseX::Runnable> class and tries to
59run it, using C<MooseX::Runnable::Run>.
60
61The syntax is:
62
2503822b 63 mx-run <args for mx-run> -- Class::Name <args for Class::Name>
c527660e 64
65for example:
66
2503822b 67 mx-run -Ilib -- App::HelloWorld --args --go --here
c527660e 68
2503822b 69or:
70
71 mx-run -Ilib +Persistent --port 8080 -Persistent -- App::HelloWorld --args --go --here
c527660e 72=head2 C<MooseX::Runnable::Run>
73
74If you don't want to invoke your app with C<mx-run>, you can write a
75custom version using L<MooseX::Runnable::Run|MooseX::Runnable::Run>.