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