Fix warnings from ScriptRunner
[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
1beae7ed 14 warn("load $classtoload or Catalyst::Script::$scriptclass");
15
c1c59374 16 # FIXME - Error handling / reporting
1beae7ed 17 unless ( eval { Class::MOP::load_class($classtoload) } ) {
18 warn("Could not load $classtoload - falling back to Catalyst::Script::$scriptclass : $@\n")
19 if $@ !~ /Can't locate/;
d24d92d9 20 $classtoload = "Catalyst::Script::$scriptclass";
c1c59374 21 Class::MOP::load_class($classtoload);
d24d92d9 22 }
ab7eb5a9 23 $classtoload->new_with_options( application_name => $class )->run;
cc999ce2 24}
d3082fac 25
26__PACKAGE__->meta->make_immutable;
27
28=head1 NAME
29
1628b022 30Catalyst::ScriptRunner - The Catalyst Framework script runner
d3082fac 31
32=head1 SYNOPSIS
33
1628b022 34 # Will run MyApp::Script::Server if it exists, otherwise
35 # will run Catalyst::Script::Server.
36 Catalyst::ScriptRunner->run('MyApp', 'Server');
d3082fac 37
38=head1 DESCRIPTION
39
40This class is responsible for running scripts, either in the application specific namespace
41(e.g. C<MyApp::Script::Server>), or the Catalyst namespace (e.g. C<Catalyst::Script::Server>)
42
12aa6ca4 43=head1 METHODS
44
45=head2 run ($application_class, $scriptclass)
46
47Called with two parameters, the application classs (e.g. MyApp)
48and the script class, (i.e. one of Server/FastCGI/CGI/Create/Test)
49
d3082fac 50=head1 AUTHORS
51
52Catalyst Contributors, see Catalyst.pm
53
54=head1 COPYRIGHT
55
56This library is free software. You can redistribute it and/or modify it under
57the same terms as Perl itself.
58
59=cut