line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MooseX::Runnable; # git description: v0.09-13-gb2ccf60 |
2
|
|
|
|
|
|
|
# ABSTRACT: Tag a class as a runnable application |
3
|
|
|
|
|
|
|
# KEYWORDS: moose extension executable execute script binary run modulino |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '0.10'; |
6
|
|
|
|
|
|
|
|
7
|
5
|
|
|
5
|
|
464292
|
use Moose::Role; |
|
5
|
|
|
|
|
593899
|
|
|
5
|
|
|
|
|
19
|
|
8
|
5
|
|
|
5
|
|
18608
|
use namespace::autoclean; |
|
5
|
|
|
|
|
11600
|
|
|
5
|
|
|
|
|
24
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
requires 'run'; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
1; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
__END__ |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=pod |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=encoding UTF-8 |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=head1 NAME |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
MooseX::Runnable - Tag a class as a runnable application |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=head1 VERSION |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
version 0.10 |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=head1 SYNOPSIS |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
Create a class, tag it runnable, and provide a C<run> method: |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
package App::HelloWorld; |
33
|
|
|
|
|
|
|
use feature 'say'; |
34
|
|
|
|
|
|
|
use Moose; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
with 'MooseX::Runnable'; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub run { |
39
|
|
|
|
|
|
|
my ($self,$name) = @_; |
40
|
|
|
|
|
|
|
say "Hello, $name."; |
41
|
|
|
|
|
|
|
return 0; # success |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
Then you can run this class as an application with the included |
45
|
|
|
|
|
|
|
C<mx-run> script: |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
$ mx-run App::HelloWorld jrockway |
48
|
|
|
|
|
|
|
Hello, jrockway. |
49
|
|
|
|
|
|
|
$ |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
C<MooseX::Runnable> supports L<MooseX::Getopt|MooseX::Getopt>, and |
52
|
|
|
|
|
|
|
other similar systems (and is extensible, in case you have written |
53
|
|
|
|
|
|
|
such a system). |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=head1 DESCRIPTION |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
MooseX::Runnable is a framework for making classes runnable |
58
|
|
|
|
|
|
|
applications. This role doesn't do anything other than tell the rest |
59
|
|
|
|
|
|
|
of the framework that your class is a runnable application that has a |
60
|
|
|
|
|
|
|
C<run> method which accepts arguments and returns the process' exit |
61
|
|
|
|
|
|
|
code. |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
This is a convention that the community has been using for a while. |
64
|
|
|
|
|
|
|
This role tells the computer that your class uses this convention, and |
65
|
|
|
|
|
|
|
let's the computer abstract away some of the tedium this entails. |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=head1 REQUIRED METHODS |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=head2 run |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
Your class must implement C<run>. It accepts the command-line args |
72
|
|
|
|
|
|
|
(that were not consumed by another parser, if applicable) and returns |
73
|
|
|
|
|
|
|
an integer representing the UNIX exit value. C<return 0> means |
74
|
|
|
|
|
|
|
success. |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head1 THINGS YOU GET |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=head2 C<mx-run> |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
This is a script that accepts a C<MooseX::Runnable> class and tries to |
81
|
|
|
|
|
|
|
run it, using C<MooseX::Runnable::Run>. |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
The syntax is: |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
mx-run Class::Name |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
mx-run <args for mx-run> -- Class::Name <args for Class::Name> |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
for example: |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
mx-run -Ilib App::HelloWorld --args --go --here |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
or: |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
mx-run -Ilib +Persistent --port 8080 -- App::HelloWorld --args --go --here |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=head2 C<MooseX::Runnable::Run> |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
If you don't want to invoke your app with C<mx-run>, you can write a |
100
|
|
|
|
|
|
|
custom version using L<MooseX::Runnable::Run|MooseX::Runnable::Run>. |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=head1 ARCHITECTURE |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
C<MX::Runnable> is designed to be extensible; users can run plugins |
105
|
|
|
|
|
|
|
from the command-line, and application developers can add roles to |
106
|
|
|
|
|
|
|
their class to control behavior. |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
For example, if you consume L<MooseX::Getopt|MooseX::Getopt>, the |
109
|
|
|
|
|
|
|
command-line will be parsed with C<MooseX::Getopt>. Any recognized |
110
|
|
|
|
|
|
|
args will be used to instantiate your class, and any extra args will |
111
|
|
|
|
|
|
|
be passed to C<run>. |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=head1 CAVEATS |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
Many of the plugins shipped are unstable; they may go away, change, |
116
|
|
|
|
|
|
|
break, etc. If there is no documentation for a plugin, it is probably |
117
|
|
|
|
|
|
|
just a prototype. |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=head1 SUPPORT |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
Bugs may be submitted through L<the RT bug tracker|https://rt.cpan.org/Public/Dist/Display.html?Name=MooseX-Runnable> |
122
|
|
|
|
|
|
|
(or L<bug-MooseX-Runnable@rt.cpan.org|mailto:bug-MooseX-Runnable@rt.cpan.org>). |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
There is also a mailing list available for users of this distribution, at |
125
|
|
|
|
|
|
|
L<http://lists.perl.org/list/moose.html>. |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
There is also an irc channel available for users of this distribution, at |
128
|
|
|
|
|
|
|
L<C<#moose> on C<irc.perl.org>|irc://irc.perl.org/#moose>. |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=head1 AUTHOR |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
Jonathan Rockway <jrockway@cpan.org> |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=head1 CONTRIBUTORS |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=for stopwords Jonathan Rockway Karen Etheridge Doug Bell Duke Leto |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=over 4 |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=item * |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
Jonathan Rockway <jon@jrock.us> |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=item * |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
Karen Etheridge <ether@cpan.org> |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=item * |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
Doug Bell <doug.bell@baml.com> |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=item * |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
Duke Leto <jonathan@leto.net> |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=back |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
This software is copyright (c) 2009 by Jonathan Rockway. |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
163
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=cut |