doc fixes; 0.01 release
[gitmo/MooseX-Runnable.git] / lib / MooseX / Runnable.pm
CommitLineData
d42333d2 1package MooseX::Runnable;
2use Moose::Role;
3
fc5720d5 4our $VERSION = '0.01';
6a6431d0 5
d42333d2 6requires 'run';
7
c527660e 81;
9
10__END__
11
12=head1 NAME
13
14MooseX::Runnable - tag a class as a runnable application
15
16=head1 SYNOPSIS
d42333d2 17
c527660e 18Create a class, tag it runnable, and provide a C<run> method:
19
20 package App::HelloWorld;
05e7b5d0 21 use feature 'say';
c527660e 22 use Moose;
23
24 with 'MooseX::Runnable';
25
26 sub run {
05e7b5d0 27 my ($self,$name) = @_;
c527660e 28 say "Hello, $name.";
00d7989a 29 return 0; # success
d42333d2 30 }
31
c527660e 32Then you can run this class as an application with the included
33C<mx-run> script:
d42333d2 34
c527660e 35 $ mx-run App::HelloWorld jrockway
36 Hello, jrockway.
37 $
38
39C<MooseX::Runnable> supports L<MooseX::Getopt|MooseX::Getopt>, and
40other similar systems (and is extensible, in case you have written
41such a system).
42
43=head1 DESCRIPTION
44
45MooseX::Runnable is a framework for making classes runnable
46applications. This role doesn't do anything other than tell the rest
47of the framework that your class is a runnable application that has a
48C<run> method which accepts arguments and returns the process' exit
49code.
50
51This is a convention that the community has been using for a while.
52This role tells the computer that your class uses this convention, and
53let's the computer abstract away some of the tedium this entails.
54
55=head1 REQUIRED METHODS
56
fc5720d5 57=head2 run
58
59Your class must implement C<run>. It accepts the commandline args
60(that were not consumed by another parser, if applicable) and returns
61an integer representing the UNIX exit value. C<return 0> means
62success.
63
c527660e 64=head1 THINGS YOU GET
65
66=head2 C<mx-run>
67
68This is a script that accepts a C<MooseX::Runnable> class and tries to
69run it, using C<MooseX::Runnable::Run>.
70
71The syntax is:
72
6c3ff9ca 73 mx-run Class::Name
74
2503822b 75 mx-run <args for mx-run> -- Class::Name <args for Class::Name>
c527660e 76
77for example:
78
6c3ff9ca 79 mx-run -Ilib App::HelloWorld --args --go --here
c527660e 80
2503822b 81or:
82
6c3ff9ca 83 mx-run -Ilib +Persistent --port 8080 -- App::HelloWorld --args --go --here
84
c527660e 85=head2 C<MooseX::Runnable::Run>
86
87If you don't want to invoke your app with C<mx-run>, you can write a
88custom version using L<MooseX::Runnable::Run|MooseX::Runnable::Run>.
fc5720d5 89
90=head1 ARCHITECTURE
91
92C<MX::Runnable> is designed to be extensible; users can run plugins
93from the command-line, and application developers can add roles to
94their class to control behavior.
95
96For example, if you consume L<MooseX::Getopt|MooseX::Getopt>, the
97command-line will be parsed with C<MooseX::Getopt>. Any recognized
98args will be used to instantiate your class, and any extra args will
99be passed to C<run>.
100
101=head1 BUGS
102
103Many of the plugins shipped are unstable; they may go away, change,
104break, etc. If there is no documentation for a plugin, it is probably
105just a prototype.
106
107=head1 REPOSITORY
108
109L<http://github.com/jrockway/moosex-runnable>
110
111=head1 AUTHOR
112
113Jonathan Rockway C<< <jrockway@cpan.org> >>
114
115=head1 COPYRIGHT
116
117Copyright (c) 2009 Jonathan Rockway
118
119This module is Free Software, you can redistribute it under the same
120terms as Perl itself.