add prototype Profile plugin
[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
15sub 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
281;
c527660e 29
30__END__
31
32=head1 NAME
33
34MooseX::Runnable::Run - run a MooseX::Runnable class as an application
35
36=head1 SYNOPSIS
37
38Write an app:
39
40 package MyApp;
41 use Moose; with 'MooseX::Runnable';
42 sub run { say 'Hello, world.'; return 0 } # (UNIX exit code)
43
44Write a wrapper script, C<myapp.pl>. With sugar:
45
46 #!/usr/bin/env perl
47 use MooseX::Runnable::Run 'MyApp';
48
49Or without:
50
51 #!/usr/bin/env perl
52 use MooseX::Runnable::Run;
53
54 run_application 'MyApp', @ARGV;
55
56Then, run your app:
57
58 $ ./myapp.pl
59 Hello, world.
60 $ echo $?
61 0
62
63=head1 DESCRIPTION
64
65This is a utility module that runs a L<MooseX::Runnable|MooseX::Runnable> class with
66L<MooseX::Runnable::Invocation|MooseX::Runnable::Invocation>.
67
68=head1 SEE ALSO
69
70L<mx-run>, a script that will run MooseX::Runnable apps, saving you
71valuable seconds!