fixed spelling errors
[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, %args) = @_;
10     my $classtoload = "${class}::Script::$scriptclass";
11
12     lib->import(File::Spec->catdir($FindBin::Bin, '..', 'lib'));
13
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/;
17         $classtoload = "Catalyst::Script::$scriptclass";
18         Class::MOP::load_class($classtoload);
19     }
20     $classtoload->new_with_options( application_name => $class, %args )->run;
21 }
22
23 __PACKAGE__->meta->make_immutable;
24
25 =head1 NAME
26
27 Catalyst::ScriptRunner - The Catalyst Framework script runner
28
29 =head1 SYNOPSIS
30
31     # Will run MyApp::Script::Server if it exists, otherwise
32     # will run Catalyst::Script::Server.
33     Catalyst::ScriptRunner->run('MyApp', 'Server');
34
35 =head1 DESCRIPTION
36
37 This 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
40 =head1 METHODS
41
42 =head2 run ($application_class, $scriptclass)
43
44 Called with two parameters, the application class (e.g. MyApp)
45 and the script class, (i.e. one of Server/FastCGI/CGI/Create/Test)
46
47 =head1 AUTHORS
48
49 Catalyst Contributors, see Catalyst.pm
50
51 =head1 COPYRIGHT
52
53 This library is free software. You can redistribute it and/or modify it under
54 the same terms as Perl itself.
55
56 =cut