Board/Service/Deferred.pm

filter: Statementstmt 38.1% 21 / 55 Branchbran 30.0% 6 / 20 Conditioncond 33.3% 2 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 43.7% 7 / 16 Podpod 0.0% 0 / 4 totaltotal 34.2% 36 / 105 CC 13 SCAR 13.7
CC
13
Cov
36%
__ANON__
6.0
meta
6.0
can
6.0
CRAP 3.9
« Board/Service/WithDependencies.pm ↑ Summary Board/Container/Parameterized.pm »
1 package Bread::Board::Service::Deferred;
2 70 our $AUTHORITY = 'cpan:STEVAN';
3 # ABSTRACT: Helper for holding a service that is not quite constructed yet
4 70 $Bread::Board::Service::Deferred::VERSION = '0.37';
5 70 ▶use Moose ();
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 use overload
8 # cover your basic operatins ...
9 0 ▶ 'bool' => sub { 1 },
Subroutine BEGIN: called CC=1 SCAR=2.5
Subroutine __ANON__: not called CC=1 SCAR=6.9
10 0 ▶ '""' => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
11 0 $_[0] = $_[0]->{service}->get;
12 0 ▶ if (my $func = overload::Method($_[0], '""')) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $func = overload::Method($_[0], "\"\"")) 0 0 0
13 0 return $_[0]->$func();
14 }
15 0 return overload::StrVal($_[0]);
16 },
17 # cover your basic dereferncers
18 19 ▶ '%{}' => sub {
Subroutine __ANON__: called CC=2 SCAR=10.5
19 19 ▶ return $_[0] if (caller)[0] eq 'Bread::Board::Service::Deferred';
Branch: 1 branch
BranchTrueFalseTotal
if (caller)[0] eq "Bread::Board::Service::Deferred" 19 0 19
20 0 $_[0] = $_[0]->{service}->get;
21 0 $_[0]
22 },
23 0 ▶ '@{}' => sub { $_[0] = $_[0]->{service}->get; $_[0] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
24 0 ▶ '${}' => sub { $_[0] = $_[0]->{service}->get; $_[0] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
25 0 ▶ '&{}' => sub { $_[0] = $_[0]->{service}->get; $_[0] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
26 0 ▶ '*{}' => sub { $_[0] = $_[0]->{service}->get; $_[0] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
27 ## and as a last ditch resort ...
28 2 ▶ nomethod => sub {
Subroutine __ANON__: called CC=4 SCAR=16.4
29 2 $_[0] = $_[0]->{service}->get;
30 2 ▶ return overload::StrVal($_[0]) if $_[3] eq '""' && !overload::Method($_[0], $_[3]);
Branch: 1 branch
BranchTrueFalseTotal
if $_[3] eq "\"\"" and not overload::Method($_[0], $_[3]) 0 2 2
Condition33%1/3
$_[3] eq "\"\"" and not overload::Method($_[0], $_[3])
!ll&&!rl&&r
200
MC/DC0%0/2
$_[3] eq "\"\"" and not overload::Method($_[0], $_[3])
$_[3] eq "\"\"" not overload::Method($_[0], $_[3])
Truth table33%1/3
A and not(B)
A= $_[3] eq "\"\""B= not overload::Method($_[0], $_[3])
ABresult
0X0
100
111
31 2 ▶ if (my $func = overload::Method($_[0], $_[3])) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $func = overload::Method($_[0], $_[3])) 0 2 2
32 0 return $_[0]->$func($_[1]);
33 }
34 2 return $_[0]; # if all else fails, just return the object
35 },
36 70 ;
37  
38 5 ▶sub new {
Subroutine new: called CC=3 SCAR=12.5
Pod undocumented
39 5 my ($class, %params) = @_;
40 5 ▶ (Scalar::Util::blessed($params{service}) && $params{service}->does('Bread::Board::Service'))
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($params{"service"}) and $params{"service"}->does("Bread::Board::Service") or Carp::confess("You can only defer Bread::Board::Service instances") 5 0 5
Condition33%1/3
builtin::blessed($params{"service"}) and $params{"service"}->does("Bread::Board::Service")
!ll&&!rl&&r
005
MC/DC0%0/2
builtin::blessed($params{"service"}) and $params{"service"}->does("Bread::Board::Service")
builtin::blessed($params{"service"}) $params{"service"}->does("Bread::Board::Service")
Truth table33%1/3
A and B
A= builtin::blessed($params{"service"})B= $params{"service"}->does("Bread::Board::Service")
ABresult
0X0
100
111
41 || Carp::confess "You can only defer Bread::Board::Service instances";
42 5 bless { service => $params{service} } => $class;
43 }
44  
45 0 ▶sub meta {
Subroutine meta: not called CC=2 SCAR=17.9
Pod undocumented
46 0 ▶ if ($_[0]->{service}->can('class')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0]{"service"}->can("class")) 0 0 0
47 0 my $class = $_[0]->{service}->class;
48 0 return $class->meta;
49 }
50 0 $_[0] = $_[0]->{service}->get;
51 0 (shift)->meta;
52 }
53  
54 0 ▶sub can {
Subroutine can: not called CC=2 SCAR=17.9
Pod undocumented
55 0 ▶ if ($_[0]->{service}->can('class')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0]{"service"}->can("class")) 0 0 0
56 0 my $class = $_[0]->{service}->class;
57 0 return $class->can($_[1]);
58 }
59 0 $_[0] = $_[0]->{service}->get;
60 0 (shift)->can(shift);
61 }
62  
63 7 ▶sub isa {
Subroutine isa: called CC=3 SCAR=14.2
Pod undocumented
64 7 ▶ if ($_[0]->{service}->can('class')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0]{"service"}->can("class")) 7 0 7
65 7 my $class = $_[0]->{service}->class;
66 7 ▶ return 1 if $class eq $_[1];
Branch: 1 branch
BranchTrueFalseTotal
if $class eq $_[1] 7 0 7
67 0 return $class->isa($_[1]);
68 }
69 0 $_[0] = $_[0]->{service}->get;
70 0 (shift)->isa(shift);
71 }
72  
73 3 ▶sub DESTROY { (shift)->{service} = undef }
Subroutine DESTROY: called CC=1 SCAR=0.0
74  
75 0 ▶sub AUTOLOAD {
Subroutine AUTOLOAD: not called CC=2 SCAR=17.9
76 0 my ($subname) = our $AUTOLOAD =~ /([^:]+)$/;
77 0 $_[0] = $_[0]->{service}->get;
78 0 my $func = $_[0]->can($subname);
79 0 ▶ (ref($func) eq 'CODE')
Branch: 1 branch
BranchTrueFalseTotal
ref $func eq "CODE" or Carp::confess("You cannot call '${subname}'") 0 0 0
80 || Carp::confess "You cannot call '$subname'";
81 0 goto &$func;
82 }
83  
84 70 1;
85  
86 __END__
« Board/Service/WithDependencies.pm ↑ Summary Board/Container/Parameterized.pm »