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 CC 12 SCAR 14.5
CC
12
Cov
83%
build_context
8.5
build_methods
4.4
clone
2.0
CRAP 4.3
↑ Summary Tie/Plugin.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 (
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 require => 1,
10 except => qr/^Pad::Tie::Plugin::Base::/,
11 2 );
12 2 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 2 our $VERSION = '0.006';
15 2 my %METHOD;
16  
17 1 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
18 1 my $class = shift;
19 1 my ($invocant, $methods) = @_;
20 1 $methods = Data::OptList::mkopt($methods);
21 1 my $self = bless {
22 invocant => $invocant,
23 methods => $methods,
24 persist => Pad::Tie::LP->new,
25 pre_call => [],
26 } => $class;
27 1 $self->build_context;
28 #tie %{ $self->{context} }, 'Pad::Tie::Context', $self;
29 1 $self->{persist}->set_context(_ => $self->{context});
30 1 return $self;
31 }
32  
33 1 ▶sub build_methods {
Subroutine build_methods: called CC=4 SCAR=14.8
Pod undocumented
34 1 ▶ my $class = ref($_[0]) || $_[0];
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
35 1 for my $plugin ($class->plugins) {
36 8 for my $provided ($plugin->provides) {
37 #warn "$plugin provides $provided\n";
38 8 $METHOD{$provided} = $plugin;
39 }
40 }
41 }
42  
43 1 ▶sub build_context {
Subroutine build_context: called CC=8 SCAR=21.3
Pod undocumented
44 1 my $self = shift;
45 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
46 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
47 1 ▶ $self->build_methods unless %METHOD;
Branch: 1 branch
BranchTrueFalseTotal
unless %METHOD 1 0 1
48 1 for (@$methods) {
49 8 my ($method_personality, $plugin_arg) = @$_;
50 Carp::confess "unhandled method personality: $method_personality"
51 8 ▶ unless $METHOD{$method_personality};
Branch: 1 branch
BranchTrueFalseTotal
unless $METHOD{$method_personality} 0 8 8
52 8 my $plugin = $METHOD{$method_personality};
53 my $rv = $plugin->$method_personality(
54 $self->{context},
55 8 ▶ $self->{invocant}, $plugin_arg,
Condition100%2/2
$plugin->$method_personality($self->{'context'}, $self->{'invocant'}, $plugin_arg) || {}
l!l
44
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
56 ) || {};
57 # XXX I hate this but I can't think of a better way to do it offhand.
58 # if you aren't me, don't use this; talk to me about it instead. -- hdp,
59 # 2007-04-24
60 8 ▶ if ($rv->{pre_call}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rv->{"pre_call"}) 3 5 8
61 3 push @{ $self->{pre_call} }, @{ $rv->{pre_call} };
62 }
63 }
64 }
65  
66 0 ▶sub clone {
Subroutine clone: not called CC=1 SCAR=6.9
Pod undocumented
67 0 my ($self, $invocant) = @_;
68 # XXX validate $invocant?
69 # XXX does 'persist' need to be duplicated also?
70 # I don't think it has any permanent state that is interesting
71 0 return bless {
72 %$self,
73 invocant => $invocant,
74 } => ref($self),
75 }
76  
77 9 ▶sub call {
Subroutine call: called CC=2 SCAR=6.9
Pod undocumented
78 9 my ($self, $code, @args) = @_;
79 9 $_->($self, $code, \@args) for @{ $self->{pre_call} };
80 9 return $self->{persist}->call($code, @args);
81 }
82  
83 0 ▶sub wrap {
Subroutine wrap: not called CC=1 SCAR=6.9
Pod undocumented
84 0 my ($self, $code) = @_;
85 0 ▶ return sub { $self->call($code, @_) };
Subroutine __ANON__: not called CC=1 SCAR=6.9
86 }
87  
88 2 1;
89  
90 __END__
↑ Summary Tie/Plugin.pm »