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