| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
Condition33%1/3
$_[3] eq "\"\"" and not overload::Method($_[0], $_[3])
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])
| |||||||||||||||||||||||||||||
| 31 | 2 | ▶ | if (my $func = overload::Method($_[0], $_[3])) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
Condition33%1/3
builtin::blessed($params{"service"}) and $params{"service"}->does("Bread::Board::Service")
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")
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 65 | 7 | my $class = $_[0]->{service}->class; | |||||||||||||||||||||||||||
| 66 | 7 | ▶ | return 1 if $class eq $_[1]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 80 | || Carp::confess "You cannot call '$subname'"; | ||||||||||||||||||||||||||||
| 81 | 0 | goto &$func; | |||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 70 | 1; | |||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | __END__ | ||||||||||||||||||||||||||||