| 1 | package Plugins::Factory; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 1 | our $VERSION = '0.01'; | |||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use Module::Load; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 1 | require Module::Pluggable; | |||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | # save all plugin and package | ||||||||||||||||||||||||||||
| 12 | 1 | $Plugins::Factory::job_name = {}; | |||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | # save all code ref | ||||||||||||||||||||||||||||
| 15 | 1 | $Plugins::Factory::ref_code = {}; | |||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 1 | ▶ | sub import { | ||||||||||||||||||||||||||
|
Subroutine
import: called CC=8 SCAR=35.7
| |||||||||||||||||||||||||||||
| 18 | 1 | my ($class,%opts) = @_; | |||||||||||||||||||||||||||
| 19 | 1 | my ($call_pkg) = caller; | |||||||||||||||||||||||||||
| 20 | map { | ||||||||||||||||||||||||||||
| 21 | 0 | my $pl_name = $_; | |||||||||||||||||||||||||||
| 22 | 0 | ▶ | my $namespace = $opts{$pl_name}->{'plugin_namespace'} if exists $opts{$pl_name}->{'plugin_namespace'}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 23 | 0 | ▶ | next unless (ref $opts{$pl_name} eq 'HASH' and $namespace); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $opts{$pl_name} eq "HASH" and $namespace
MC/DC0%0/2
ref $opts{$pl_name} eq "HASH" and $namespace
ref $opts{$pl_name} eq "HASH"
$namespace
Truth table0%0/3
A and B
A= ref $opts{$pl_name} eq "HASH"B= $namespace
| |||||||||||||||||||||||||||||
| 24 | 0 | my $method = $opts{$pl_name}->{'init_method'}; | |||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 0 | Module::Pluggable->import(search_path => [$namespace]); | |||||||||||||||||||||||||||
| 27 | 0 | foreach my $pkg (__PACKAGE__->plugins) { | |||||||||||||||||||||||||||
| 28 | 0 | load $pkg; | |||||||||||||||||||||||||||
| 29 | 0 | (my $short_name = $pkg) =~ s/^${namespace}:://; | |||||||||||||||||||||||||||
| 30 | 0 | push @{$Plugins::Factory::job_name->{$call_pkg}->{$pl_name}},$pkg; | |||||||||||||||||||||||||||
| 31 | $Plugins::Factory::ref_code->{$call_pkg}->{$pl_name}->{$short_name} = | ||||||||||||||||||||||||||||
| 32 | $Plugins::Factory::ref_code->{$call_pkg}->{$pl_name}->{$pkg} = | ||||||||||||||||||||||||||||
| 33 | 0 | ▶ | ($method and $pkg->can($method)) ? sub {$pkg->$method(@_)} : sub {$pkg}; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
Subroutine
__ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
Condition0%0/3
$method and $pkg->can($method)
MC/DC0%0/2
$method and $pkg->can($method)
$method
$pkg->can($method)
Truth table0%0/3
A and B
A= $methodB= $pkg->can($method)
| |||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 1 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 37 | 1 | ▶ | no warnings qw(redefine prototype); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 38 | # add function in traget package | ||||||||||||||||||||||||||||
| 39 | 0 | ▶ | *{"$call_pkg\::$pl_name"} = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 40 | 0 | my ($class,$name,@init) = @_; | |||||||||||||||||||||||||||
| 41 | 0 | ▶ | return $Plugins::Factory::job_name->{$call_pkg}->{$pl_name} unless $name; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 42 | 0 | ▶ | return $Plugins::Factory::ref_code->{$call_pkg}->{$pl_name}->{$name}->(@init) if exists $Plugins::Factory::ref_code->{$call_pkg}->{$pl_name}->{$name}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 43 | 0 | ▶ | } if exists $Plugins::Factory::ref_code->{$call_pkg}->{$pl_name}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 44 | 1 | ▶ | use strict 'refs'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 45 | 0 | 1; | |||||||||||||||||||||||||||
| 46 | } keys %opts; | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 1 | 1; | |||||||||||||||||||||||||||
| 52 | __END__ | ||||||||||||||||||||||||||||