Factor stuff out into a script role, clean up all the script code
[catagits/Catalyst-Runtime.git] / lib / Catalyst / ScriptRunner.pm
1 package Catalyst::ScriptRunner;
2 use Moose;
3 use namespace::autoclean;
4
5 sub run {
6     my ($self, $class, $scriptclass) = @_;
7     my $classtoload = "${class}::Script::$scriptclass";
8
9     # FIXME - Error handling / reporting
10     if ( eval { Class::MOP::load_class($classtoload) } ) {
11     }
12     else {
13         $classtoload = "Catalyst::Script::$scriptclass";
14         Class::MOP::load_class($classtoload);
15     }
16     $classtoload->new_with_options( app => $class )->run;
17 }
18
19 __PACKAGE__->meta->make_immutable;
20
21 =head1 NAME
22
23 Catalyst::ScriptRunner - The Catalyst Framework Script runner
24
25 =head1 SYNOPSIS
26
27 See L<Catalyst>.
28
29 =head1 DESCRIPTION
30
31 This class is responsible for running scripts, either in the application specific namespace
32 (e.g. C<MyApp::Script::Server>), or the Catalyst namespace (e.g. C<Catalyst::Script::Server>)
33
34 =head1 AUTHORS
35
36 Catalyst Contributors, see Catalyst.pm
37
38 =head1 COPYRIGHT
39
40 This library is free software. You can redistribute it and/or modify it under
41 the same terms as Perl itself.
42
43 =cut