Move to aggregate
[catagits/Catalyst-Runtime.git] / lib / Catalyst / ScriptRole.pm
CommitLineData
d3082fac 1package Catalyst::ScriptRole;
2use Moose::Role;
3use MooseX::Types::Moose qw/Str Bool/;
4use Pod::Usage;
5use namespace::autoclean;
6
d3082fac 7with 'MooseX::Getopt';
8
9has application_name => (
10 traits => ['NoGetopt'],
11 isa => Str,
12 is => 'ro',
13 required => 1,
14);
15
16has help => (
17 traits => ['Getopt'],
18 cmd_aliases => 'h',
19 isa => Bool,
20 is => 'ro',
21 documentation => q{Display this help and exit},
22);
23
24sub _display_help {
25 my $self = shift;
26 pod2usage();
27 exit 0;
28}
29
30before run => sub {
31 my $self = shift;
32 $self->_display_help if $self->help;
33};
34
35sub run {
36 my $self = shift;
37 $self->_run_application;
38}
39
40sub _application_args {
41 ()
42}
43
44sub _run_application {
45 my $self = shift;
46 my $app = $self->application_name;
47 Class::MOP::load_class($app);
48 $app->run($self->_application_args);
49}
50
511;
1628b022 52
53=head1 NAME
54
55Catalyst::ScriptRole - Common functionality for Catalyst scripts.
56
57=head1 SYNOPSIS
58
59 FIXME
60
61=head1 DESCRIPTION
62
63 FIXME
64
65=head1 AUTHORS
66
67Catalyst Contributors, see Catalyst.pm
68
69=head1 COPYRIGHT
70
71This library is free software, you can redistribute it and/or modify
72it under the same terms as Perl itself.
73
74=cut
75