lib/Devel/WatchVars.pm

filter: Statementstmt 75.4% 46 / 61 Branchbran 36.6% 11 / 30 Conditioncond 40.0% 4 / 10 MC/DCmcdc 33.3% 2 / 6 Subroutinesub 83.3% 10 / 12 Podpod 100% 4 / 4 totaltotal 62.6% 77 / 123 CC 19 SCAR 21.6
CC
19
Cov
60%
watch
13.1
watch
13.1
unwatch
9.4
CRAP 8.7
↑ Summary lib/Devel/WatchVars/Tie/Scalar.pm »
1 package Devel::WatchVars;
2  
3 =encoding utf8
4  
5 =cut
6  
7 15 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 15 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 15 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 15 ▶no overloading;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 15 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 15 ▶use Scalar::Util qw(weaken readonly reftype);
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 15 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 ###########################################################
18  
19 15 our $VERSION = "v1.0.5";
20  
21 15 ▶use Exporter qw(import);
Subroutine BEGIN: called CC=1 SCAR=0.0
22 15 our @EXPORT = qw(watch unwatch);
23  
24 ###########################################################
25  
26 15 my $TIE_PACKAGE = __PACKAGE__ . "::Tie::Scalar";
27 {
28 15 local $@;
29 15 ▶ die unless eval "require $TIE_PACKAGE; 1";
Branch: 1 branch
BranchTrueFalseTotal
unless eval "require $TIE_PACKAGE; 1" 0 15 15
30 }
31  
32 ###########################################################
33  
34 13 ▶sub watch(\$;$) {
Subroutine watch: called CC=6 SCAR=25.8
Pod documented
35 0 ▶ my($sref, $name) = @_;
Subroutine watch: not called CC=6 SCAR=25.8
Pod documented
36 0 ▶ my $reftype = ref($sref) && reftype($sref);
Condition33%2/6
ref $sref && builtin::reftype($sref)
!ll&&!rl&&r
1012
ref $sref && builtin::reftype($sref)
!ll&&!rl&&r
000
MC/DC50%1/2
ref $sref && builtin::reftype($sref)
ref $sref builtin::reftype($sref)
MC/DC0%0/2
ref $sref && builtin::reftype($sref)
ref $sref builtin::reftype($sref)
Truth table66%2/3
A && B
A= ref $srefB= builtin::reftype($sref)
ABresult
0X0
100
111
Truth table0%0/3
A && B
A= ref $srefB= builtin::reftype($sref)
ABresult
0X0
100
111
37  
38 0 ▶ $reftype =~ /^(?:SCALAR|REF)\z/ ||
Branch: 6 branches
BranchTrueFalseTotal
$reftype =~ /^(?:SCALAR|REF)\z/ or croak("You didn't pass a SCALAR (by reference), you passed a ", $reftype ? "$reftype (by reference)" : (defined $sref ? "non-reference" : "undef")) 12 1 13
$reftype ? : 0 1 1
defined $sref ? : 0 1 1
$reftype =~ /^(?:SCALAR|REF)\z/ or croak("You didn't pass a SCALAR (by reference), you passed a ", $reftype ? "$reftype (by reference)" : (defined $sref ? "non-reference" : "undef")) 0 0 0
$reftype ? : 0 0 0
defined $sref ? : 0 0 0
39 croak "You didn't pass a SCALAR (by reference), you passed a ",
40 $reftype ? "$reftype (by reference)"
41 : defined($sref) ? "non-reference"
42 : "undef";
43  
44 0 ▶ !readonly($$sref) || croak "Can't watch a readonly scalar";
Branch: 2 branches
BranchTrueFalseTotal
&readonly($$sref) and croak("Can't watch a readonly scalar") 2 10 12
&readonly($$sref) and croak("Can't watch a readonly scalar") 0 0 0
45  
46 0 my $value = $$sref;
47 0 my $self = tie $$sref, $TIE_PACKAGE, $name, $value;
48 0 weaken($$self{sref} = $sref);
49 }
50  
51 ###########################################################
52  
53 9 ▶sub unwatch(\$) {
Subroutine unwatch: called CC=5 SCAR=22.5
Pod documented
54 0 ▶ my($tref) = @_;
Subroutine unwatch: not called CC=5 SCAR=22.5
Pod documented
55 0 ▶ ref($tref) eq "SCALAR" || croak "You didn't pass a scalar (by reference)";
Branch: 2 branches
BranchTrueFalseTotal
ref $tref eq "SCALAR" or croak("You didn't pass a scalar (by reference)") 9 0 9
ref $tref eq "SCALAR" or croak("You didn't pass a scalar (by reference)") 0 0 0
56 0 ▶ my $self = tied $$tref || croak "Can't unwatch something that isn't tied";
Condition50%2/4
tied $$tref || croak(q[Can't unwatch something that isn't tied])
l!l
81
tied $$tref || croak(q[Can't unwatch something that isn't tied])
l!l
00
MC/DC100%1/1
tied $$tref || croak(q[Can't unwatch something that isn't tied])
tied $$tref
MC/DC0%0/1
tied $$tref || croak(q[Can't unwatch something that isn't tied])
tied $$tref
Truth table100%2/2
A
A= tied $$tref
Aresult
11
00
Truth table0%0/2
A
A= tied $$tref
Aresult
11
00
57 0 ▶ $self->isa($TIE_PACKAGE) || croak "Can't unwatch something that isn't watched";
Branch: 2 branches
BranchTrueFalseTotal
$self->isa($TIE_PACKAGE) or croak("Can't unwatch something that isn't watched") 7 1 8
$self->isa($TIE_PACKAGE) or croak("Can't unwatch something that isn't watched") 0 0 0
58 0 my($sref, $value) = @$self{sref => "value"};
59 0 undef $self;
60 0 untie $$tref;
61 0 ▶ $$sref = $value if ref($sref) eq "SCALAR";
Branch: 2 branches
BranchTrueFalseTotal
if ref $sref eq "SCALAR" 7 0 7
if ref $sref eq "SCALAR" 0 0 0
62 }
63  
64 ###########################################################
65  
66 15 1;
67  
68 __END__
↑ Summary lib/Devel/WatchVars/Tie/Scalar.pm »