| 1 | package Devel::WatchVars::Tie::Scalar; | ||||||||||||||||||||||||||||||||
| 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 qw(shortmess); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||
| 14 | 15 | our $VERSION = "v1.0.5"; | |||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||
| 16 | 15 | (my $PKG = __PACKAGE__) =~ s/::Tie::Scalar//; | |||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||
| 18 | 15 | push our @CARP_NOT => $PKG, qw( | |||||||||||||||||||||||||||||||
| 19 | Data::Dump | ||||||||||||||||||||||||||||||||
| 20 | Data::Dumper | ||||||||||||||||||||||||||||||||
| 21 | ); | ||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||
| 23 | 15 | ▶ | use Devel::GlobalDestruction; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||
| 25 | 72 | ▶ | sub mycarp { | ||||||||||||||||||||||||||||||
|
Subroutine
mycarp: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 26 | 72 | local $\; | |||||||||||||||||||||||||||||||
| 27 | 72 | print STDERR &mymess; | |||||||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||
| 30 | 73 | ▶ | sub mymess { | ||||||||||||||||||||||||||||||
|
Subroutine
mymess: called CC=2 SCAR=7.2
| |||||||||||||||||||||||||||||||||
| 31 | 73 | ▶ | local $Carp::Verbose = $ENV{DEVEL_WATCHVARS_VERBOSE} ? 1 : 0; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 32 | 73 | return &shortmess; | |||||||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||
| 35 | 72 | ▶ | sub redef($) { | ||||||||||||||||||||||||||||||
|
Subroutine
redef: called CC=2 SCAR=7.6
| |||||||||||||||||||||||||||||||||
| 36 | 72 | ▶ | return $_[0] // "undef"; | ||||||||||||||||||||||||||||||
|
Condition50%1/2
$_[0] // "undef"
MC/DC0%0/1
$_[0] // "undef"
$_[0]
Truth table50%1/2
A
A= $_[0]
| |||||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||
| 39 | 15 | ▶ | use namespace::clean; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||
| 41 | ########################################################### | ||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||
| 43 | 10 | ▶ | sub TIESCALAR { | ||||||||||||||||||||||||||||||
|
Subroutine
TIESCALAR: called CC=2 SCAR=9.2
| |||||||||||||||||||||||||||||||||
| 44 | 0 | ▶ | my($class, $name, $value) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
TIESCALAR: not called CC=2 SCAR=9.2
| |||||||||||||||||||||||||||||||||
| 45 | 0 | ▶ | unless ($name) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 46 | 0 | $name = mymess "some scalar variable"; | |||||||||||||||||||||||||||||||
| 47 | 0 | $name =~ s/ at (\S.*) (line \d+)[.]?\n\z/ watched at $2 of $1/; | |||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||
| 49 | 0 | mycarp "WATCH $name = ", redef $value; | |||||||||||||||||||||||||||||||
| 50 | 0 | return bless { | |||||||||||||||||||||||||||||||
| 51 | name => $name, | ||||||||||||||||||||||||||||||||
| 52 | value => $value, | ||||||||||||||||||||||||||||||||
| 53 | }, $class; | ||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||
| 56 | 37 | ▶ | sub FETCH { | ||||||||||||||||||||||||||||||
|
Subroutine
FETCH: called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||
| 57 | 0 | my($self) = @_; | |||||||||||||||||||||||||||||||
| 58 | 0 | mycarp "FETCH $$self{name} --> ", redef $$self{value}; | |||||||||||||||||||||||||||||||
| 59 | 0 | return $$self{value}; | |||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||
| 62 | 16 | ▶ | sub STORE { | ||||||||||||||||||||||||||||||
|
Subroutine
STORE: called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||
| 63 | 0 | my($self, $new_value) = @_; | |||||||||||||||||||||||||||||||
| 64 | 0 | mycarp "STORE $$self{name} <-- ", redef $new_value; | |||||||||||||||||||||||||||||||
| 65 | 0 | return $$self{value} = $new_value; | |||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||
| 68 | 9 | ▶ | sub DESTROY { | ||||||||||||||||||||||||||||||
|
Subroutine
DESTROY: called CC=6 SCAR=21.0
| |||||||||||||||||||||||||||||||||
| 69 | 0 | my($self) = @_; | |||||||||||||||||||||||||||||||
| 70 | 9 | ▶ | my $action = | ||||||||||||||||||||||||||||||
|
Branch: 4 branches
Condition100%2/2
(caller 2)[3] // ""
MC/DC100%1/1
(caller 2)[3] // ""
(caller 2)[3]
Truth table100%2/2
A
A= (caller 2)[3]
| |||||||||||||||||||||||||||||||||
| 71 | in_global_destruction ? "DESTROY (during global destruction)" | ||||||||||||||||||||||||||||||||
| 72 | : ((caller 2)[3] // "") eq "${PKG}::unwatch" ? "UNWATCH" | ||||||||||||||||||||||||||||||||
| 73 | : "DESTROY"; | ||||||||||||||||||||||||||||||||
| 74 | 9 | mycarp "$action $$self{name} = ", redef $$self{value}; | |||||||||||||||||||||||||||||||
| 75 | 9 | ▶ | if (my $sref = $$self{sref}) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 76 | 7 | ▶ | $$sref = $$self{value} unless in_global_destruction; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||
| 78 | 9 | delete @$self{keys %$self}; | |||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||
| 81 | 15 | 1; | |||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||
| 83 | __END__ | ||||||||||||||||||||||||||||||||