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