Commit | Line | Data |
d42333d2 |
1 | package MooseX::Runnable::Run; |
2 | use strict; |
3 | use warnings; |
4 | |
c527660e |
5 | use MooseX::Runnable::Invocation; |
d42333d2 |
6 | |
c527660e |
7 | sub run_application($;@) { |
d42333d2 |
8 | my ($app, @args) = @_; |
9 | |
c527660e |
10 | exit MooseX::Runnable::Invocation->new( |
11 | class => $app, |
12 | )->run(@args); |
13 | } |
14 | |
15 | sub import { |
16 | my ($class, $app) = @_; |
d42333d2 |
17 | |
c527660e |
18 | if($app){ |
19 | run_application $app, @ARGV; |
20 | } |
21 | else { |
22 | my $c = caller; |
23 | no strict 'refs'; |
24 | *{ $c. '::run_application' } = \&run_application; |
25 | } |
d42333d2 |
26 | } |
27 | |
28 | 1; |
c527660e |
29 | |
30 | __END__ |
31 | |
32 | =head1 NAME |
33 | |
34 | MooseX::Runnable::Run - run a MooseX::Runnable class as an application |
35 | |
36 | =head1 SYNOPSIS |
37 | |
38 | Write an app: |
39 | |
40 | package MyApp; |
41 | use Moose; with 'MooseX::Runnable'; |
42 | sub run { say 'Hello, world.'; return 0 } # (UNIX exit code) |
43 | |
44 | Write a wrapper script, C<myapp.pl>. With sugar: |
45 | |
46 | #!/usr/bin/env perl |
47 | use MooseX::Runnable::Run 'MyApp'; |
48 | |
49 | Or without: |
50 | |
51 | #!/usr/bin/env perl |
52 | use MooseX::Runnable::Run; |
53 | |
54 | run_application 'MyApp', @ARGV; |
55 | |
56 | Then, run your app: |
57 | |
58 | $ ./myapp.pl |
59 | Hello, world. |
60 | $ echo $? |
61 | 0 |
62 | |
63 | =head1 DESCRIPTION |
64 | |
65 | This is a utility module that runs a L<MooseX::Runnable|MooseX::Runnable> class with |
66 | L<MooseX::Runnable::Invocation|MooseX::Runnable::Invocation>. |
67 | |
68 | =head1 SEE ALSO |
69 | |
70 | L<mx-run>, a script that will run MooseX::Runnable apps, saving you |
71 | valuable seconds! |