Commit | Line | Data |
d42333d2 |
1 | package MooseX::Runnable; |
2 | use Moose::Role; |
3 | |
6c3ff9ca |
4 | our $VERSION = '0.00_02'; |
6a6431d0 |
5 | |
d42333d2 |
6 | requires 'run'; |
7 | |
c527660e |
8 | 1; |
9 | |
10 | __END__ |
11 | |
12 | =head1 NAME |
13 | |
14 | MooseX::Runnable - tag a class as a runnable application |
15 | |
16 | =head1 SYNOPSIS |
d42333d2 |
17 | |
c527660e |
18 | Create 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 |
32 | Then you can run this class as an application with the included |
33 | C<mx-run> script: |
d42333d2 |
34 | |
c527660e |
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 | |
6c3ff9ca |
66 | mx-run Class::Name |
67 | |
2503822b |
68 | mx-run <args for mx-run> -- Class::Name <args for Class::Name> |
c527660e |
69 | |
70 | for example: |
71 | |
6c3ff9ca |
72 | mx-run -Ilib App::HelloWorld --args --go --here |
c527660e |
73 | |
2503822b |
74 | or: |
75 | |
6c3ff9ca |
76 | mx-run -Ilib +Persistent --port 8080 -- App::HelloWorld --args --go --here |
77 | |
c527660e |
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>. |