| 1 | package PerlActor::CommandFactory; | ||||||||||
| 2 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 1 | ▶ | use base 'PerlActor::Object'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | |||||||||||
| 5 | #=============================================================================================== | ||||||||||
| 6 | # Public Methods | ||||||||||
| 7 | #=============================================================================================== | ||||||||||
| 8 | |||||||||||
| 9 | sub create | ||||||||||
| 10 | 19 | ▶ | { | ||||||||
|
Subroutine
create: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||
| 11 | 19 | my $self = shift; | |||||||||
| 12 | 19 | my $commandName = shift; | |||||||||
| 13 | |||||||||||
| 14 | 19 | ▶ | return $self->create('Null') | ||||||||
|
Branch: 1 branch
| |||||||||||
| 15 | unless $commandName; | ||||||||||
| 16 | |||||||||||
| 17 | 18 | my @commandArgs = @_; | |||||||||
| 18 | 18 | my $error = ''; | |||||||||
| 19 | |||||||||||
| 20 | #TODO Refactor by extracting standard namespaces | ||||||||||
| 21 | 18 | foreach my $class ("PerlActor::Command::$commandName", "PerlActor::Command::Web::$commandName", $commandName) | |||||||||
| 22 | { | ||||||||||
| 23 | 22 | ▶ | unless ($error = $self->_compile($class)) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 24 | { | ||||||||||
| 25 | 16 | return $class->new(@commandArgs) | |||||||||
| 26 | } | ||||||||||
| 27 | 6 | ▶ | last unless ($error =~ /Can't locate/); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 28 | } | ||||||||||
| 29 | |||||||||||
| 30 | 2 | return $self->create('Unknown', $error); | |||||||||
| 31 | |||||||||||
| 32 | } | ||||||||||
| 33 | |||||||||||
| 34 | #=============================================================================================== | ||||||||||
| 35 | # Protected Methods - Don't even think about calling these from outside the class. | ||||||||||
| 36 | #=============================================================================================== | ||||||||||
| 37 | |||||||||||
| 38 | sub _compile | ||||||||||
| 39 | 22 | ▶ | { | ||||||||
|
Subroutine
_compile: called CC=2 SCAR=6.9
| |||||||||||
| 40 | 22 | my $self = shift; | |||||||||
| 41 | 22 | my $class = shift; | |||||||||
| 42 | 22 | ▶ | return if (eval "require $class"); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 43 | 6 | return $@; | |||||||||
| 44 | } | ||||||||||
| 45 | |||||||||||
| 46 | # Keep Perl happy. | ||||||||||
| 47 | 1 | 1; | |||||||||