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