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