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