blib/lib/Plugins/Factory.pm

filter: Statementstmt 57.7% 26 / 45 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 70.0% 7 / 10 Podpod n/a totaltotal 42.8% 33 / 77 CC 10 SCAR 28.6
CC
10
Cov
41%
import
35.6
__ANON__
12.0
__ANON__
2.0
CRAP 17.4
↑ Summary
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
BranchTrueFalseTotal
if exists $opts{$pl_name}{"plugin_namespace"} 0 0 0
23 0 ▶ next unless (ref $opts{$pl_name} eq 'HASH' and $namespace);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $opts{$pl_name} eq "HASH" and $namespace 0 0 0
Condition0%0/3
ref $opts{$pl_name} eq "HASH" and $namespace
!ll&&!rl&&r
000
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
ABresult
0X0
100
111
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
BranchTrueFalseTotal
$method && $pkg->can($method) ? : 0 0 0
Condition0%0/3
$method and $pkg->can($method)
!ll&&!rl&&r
000
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)
ABresult
0X0
100
111
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
BranchTrueFalseTotal
unless $name 0 0 0
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
BranchTrueFalseTotal
if exists $Plugins::Factory::ref_code->{$call_pkg}{$pl_name}{$name} 0 0 0
43 0 ▶ } if exists $Plugins::Factory::ref_code->{$call_pkg}->{$pl_name};
Branch: 1 branch
BranchTrueFalseTotal
if exists $Plugins::Factory::ref_code->{$call_pkg}{$pl_name} 0 0 0
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__
↑ Summary