Tie.pm

filter: Statementstmt 90.7% 49 / 54 Branchbran 66.6% 4 / 6 Conditioncond 50.0% 5 / 10 MC/DCmcdc 16.6% 1 / 6 Subroutinesub 76.9% 10 / 13 Podpod 16.6% 1 / 6 totaltotal 73.6% 70 / 95 SCAR 25.4
CC
12
Cov
83%
build_context
8.5
build_methods
4.4
clone
2.0
CRAP 12.7
↑ Summary Tie/Plugin/List.pm »
1 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 package Pad::Tie;
5  
6 2 ▶use Pad::Tie::LP;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use Data::OptList;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use Module::Pluggable require => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 2 our $VERSION = '0.002_02';
12 2 my %METHOD;
13  
14 sub new {
15 1 ▶ my $class = shift;
Subroutine new: called CC=1 SCAR=0.0
Pod documented
16 1 my ($invocant, $methods) = @_;
17 1 $methods = Data::OptList::mkopt($methods);
18 1 my $self = bless {
19 invocant => $invocant,
20 methods => $methods,
21 persist => Pad::Tie::LP->new,
22 pre_call => [],
23 } => $class;
24 1 $self->build_context;
25 #tie %{ $self->{context} }, 'Pad::Tie::Context', $self;
26 1 $self->{persist}->set_context(_ => $self->{context});
27 1 return $self;
28 }
29  
30 sub build_methods {
31 1 ▶ my $class = ref($_[0]) || $_[0];
Subroutine build_methods: called CC=4 SCAR=14.8
Pod undocumented
Condition33%1/3
ref $_[0] || $_[0]
l!l&&r!l&&!r
100
MC/DC0%0/2
ref $_[0] || $_[0]
ref $_[0] $_[0]
Truth table33%1/3
A || B
A= ref $_[0]B= $_[0]
ABresult
1X1
011
000
32 1 for my $plugin ($class->plugins) {
33 6 for my $provided ($plugin->provides) {
34 #warn "$plugin provides $provided\n";
35 6 $METHOD{$provided} = $plugin;
36 }
37 }
38 }
39  
40 sub build_context {
41 1 ▶ my $self = shift;
Subroutine build_context: called CC=8 SCAR=21.3
Pod undocumented
42 1 ▶ my $methods = shift || $self->{methods};
Condition33%1/3
shift() || $self->{'methods'}
l!l&&r!l&&!r
010
MC/DC0%0/2
shift() || $self->{'methods'}
shift() $self->{'methods'}
Truth table33%1/3
A || B
A= shift()B= $self->{'methods'}
ABresult
1X1
011
000
43 1 ▶ $self->{context} ||= {};
Condition50%1/2
$self->{"context"} ||= {}
l!l
01
MC/DC0%0/1
$self->{"context"} ||= {}
$self->{"context"}
Truth table50%1/2
A
A= $self->{"context"}
Aresult
11
00
44 1 ▶ $self->build_methods unless %METHOD;
Branch: 1 branch
BranchTrueFalseTotal
unless %METHOD 1 0 1
45 1 for (@$methods) {
46 6 my ($method_personality, $plugin_arg) = @$_;
47 Carp::confess "unhandled method personality: $method_personality"
48 6 ▶ unless $METHOD{$method_personality};
Branch: 1 branch
BranchTrueFalseTotal
unless $METHOD{$method_personality} 0 6 6
49 6 my $plugin = $METHOD{$method_personality};
50 my $rv = $plugin->$method_personality(
51 $self->{context},
52 6 ▶ $self->{invocant}, $plugin_arg,
Condition100%2/2
$plugin->$method_personality($self->{'context'}, $self->{'invocant'}, $plugin_arg) || {}
l!l
24
MC/DC100%1/1
$plugin->$method_personality($self->{'context'}, $self->{'invocant'}, $plugin_arg) || {}
$plugin->$method_personality($self->{'context'}, $self->{'invocant'}, $plugin_arg)
Truth table100%2/2
A
A= $plugin->$method_personality($self->{'context'}, $self->{'invocant'}, $plugin_arg)
Aresult
11
00
53 ) || {};
54 # XXX I hate this but I can't think of a better way to do it offhand.
55 # if you aren't me, don't use this; talk to me about it instead. -- hdp,
56 # 2007-04-24
57 6 ▶ if ($rv->{pre_call}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rv->{"pre_call"}) 1 5 6
58 1 push @{ $self->{pre_call} }, @{ $rv->{pre_call} };
59 }
60 }
61 }
62  
63 sub clone {
64 0 ▶ my ($self, $invocant) = @_;
Subroutine clone: not called CC=1 SCAR=6.9
Pod undocumented
65 # XXX validate $invocant?
66 # XXX does 'persist' need to be duplicated also?
67 # I don't think it has any permanent state that is interesting
68 0 return bless {
69 %$self,
70 invocant => $invocant,
71 } => ref($self),
72 }
73  
74 sub call {
75 6 ▶ my ($self, $code, @args) = @_;
Subroutine call: called CC=2 SCAR=6.9
Pod undocumented
76 6 $_->($self, $code, \@args) for @{ $self->{pre_call} };
77 6 return $self->{persist}->call($code, @args);
78 }
79  
80 sub wrap {
81 0 ▶ my ($self, $code) = @_;
Subroutine wrap: not called CC=1 SCAR=6.9
Pod undocumented
82 0 ▶ return sub { $self->call($code, @_) };
Subroutine __ANON__: not called CC=1 SCAR=6.9
83 }
84  
85 2 1;
86  
87 __END__
↑ Summary Tie/Plugin/List.pm »