| 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.35'; | |||||||||||||||||||||||||||
| 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
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 10 | '""' => sub { | ||||||||||||||||||||||||||||
| 11 | 0 | ▶ | $_[0] = $_[0]->{service}->get; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 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 | '%{}' => sub { | ||||||||||||||||||||||||||||
| 19 | 19 | ▶ | return $_[0] if (caller)[0] eq 'Bread::Board::Service::Deferred'; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=10.5
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 | nomethod => sub { | ||||||||||||||||||||||||||||
| 29 | 2 | ▶ | $_[0] = $_[0]->{service}->get; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=16.4
| |||||||||||||||||||||||||||||
| 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 | ▶ | ; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | sub new { | ||||||||||||||||||||||||||||
| 39 | 5 | ▶ | my ($class, %params) = @_; | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=12.5
Pod
undocumented
| |||||||||||||||||||||||||||||
| 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 | sub meta { | ||||||||||||||||||||||||||||
| 46 | 0 | ▶ | if ($_[0]->{service}->can('class')) { | ||||||||||||||||||||||||||
|
Subroutine
meta: not called CC=2 SCAR=17.9
Pod
undocumented
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 | sub can { | ||||||||||||||||||||||||||||
| 55 | 0 | ▶ | if ($_[0]->{service}->can('class')) { | ||||||||||||||||||||||||||
|
Subroutine
can: not called CC=2 SCAR=17.9
Pod
undocumented
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 | sub isa { | ||||||||||||||||||||||||||||
| 64 | 7 | ▶ | if ($_[0]->{service}->can('class')) { | ||||||||||||||||||||||||||
|
Subroutine
isa: called CC=3 SCAR=14.2
Pod
undocumented
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 | sub AUTOLOAD { | ||||||||||||||||||||||||||||
| 76 | 0 | ▶ | my ($subname) = our $AUTOLOAD =~ /([^:]+)$/; | ||||||||||||||||||||||||||
|
Subroutine
AUTOLOAD: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | =pod | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | =encoding UTF-8 | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | =head1 NAME | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | Bread::Board::Service::Deferred - Helper for holding a service that is not quite constructed yet | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | =head1 VERSION | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | version 0.35 | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | Class for proxy objects used when L<resolving circular | ||||||||||||||||||||||||||||
| 103 | dependencies|Bread::Board::Service::WithDependencies/resolve_dependencies>. | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | This class uses a few nasty tricks: replacing C<$_[0]>, using | ||||||||||||||||||||||||||||
| 106 | C<AUTOLOAD>, overriding C<isa> C<meta> and C<can>, heavy operator | ||||||||||||||||||||||||||||
| 107 | overloading... you should probably not take inspiration from this code | ||||||||||||||||||||||||||||
| 108 | unless you really know what you're doing. | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | In practice, a variable containing an instance of | ||||||||||||||||||||||||||||
| 111 | C<Bread::Board::Service::Deferred> will have its value changed to the | ||||||||||||||||||||||||||||
| 112 | actual value instantiated by the service at the first opportunity, and | ||||||||||||||||||||||||||||
| 113 | you should not notice that this class was ever there. | ||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | =for Pod::Coverage can isa meta new | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | Stevan Little <stevan@iinteractive.com> | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | =head1 BUGS | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | Please report any bugs or feature requests on the bugtracker website | ||||||||||||||||||||||||||||
| 124 | https://github.com/stevan/BreadBoard/issues | ||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | When submitting a bug or request, please include a test-file or a | ||||||||||||||||||||||||||||
| 127 | patch to an existing test-file that illustrates the bug or desired | ||||||||||||||||||||||||||||
| 128 | feature. | ||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | This software is copyright (c) 2017, 2016, 2015, 2014, 2013, 2011, 2009 by Infinity Interactive. | ||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||
| 135 | the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | =cut | ||||||||||||||||||||||||||||