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