convert to Dist::Zilla
[gitmo/MooseX-Runnable.git] / lib / MooseX / Runnable / Run.pm
CommitLineData
d42333d2 1package MooseX::Runnable::Run;
d1de1498 2# ABSTRACT: Run a MooseX::Runnable class as an application
d42333d2 3use strict;
4use warnings;
5
c527660e 6use MooseX::Runnable::Invocation;
d42333d2 7
c527660e 8sub run_application($;@) {
d42333d2 9 my ($app, @args) = @_;
10
c527660e 11 exit MooseX::Runnable::Invocation->new(
12 class => $app,
13 )->run(@args);
14}
15
406bfd3a 16sub 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 24sub 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
381;
c527660e 39
40__END__
41
d1de1498 42=pod
c527660e 43
44=head1 SYNOPSIS
45
46Write an app:
47
48 package MyApp;
49 use Moose; with 'MooseX::Runnable';
50 sub run { say 'Hello, world.'; return 0 } # (UNIX exit code)
51
52Write a wrapper script, C<myapp.pl>. With sugar:
53
54 #!/usr/bin/env perl
55 use MooseX::Runnable::Run 'MyApp';
56
57Or without:
58
59 #!/usr/bin/env perl
60 use MooseX::Runnable::Run;
61
62 run_application 'MyApp', @ARGV;
63
64Then, run your app:
65
66 $ ./myapp.pl
67 Hello, world.
68 $ echo $?
69 0
70
71=head1 DESCRIPTION
72
73This is a utility module that runs a L<MooseX::Runnable|MooseX::Runnable> class with
74L<MooseX::Runnable::Invocation|MooseX::Runnable::Invocation>.
75
76=head1 SEE ALSO
77
78L<mx-run>, a script that will run MooseX::Runnable apps, saving you
79valuable seconds!
fc5720d5 80
81L<MooseX::Runnable>
d1de1498 82
83=cut