| 1 | package Tie::SecureHash; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 4 | our ($VERSION, $strict, $fast, $dangerous, $loud); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 4 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 4 | $VERSION = '1.10'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 4 | ▶ | sub import { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
import: called CC=4 SCAR=14.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 4 | my ($pkg, @args) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 4 | my $args = join(' ', @args); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 4 | $strict = $args =~ /\bstrict\b/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 4 | $fast = $args =~ /\bfast\b/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 4 | $dangerous = $args =~ /\bdangerous\b/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 4 | $loud = $args =~ /\bloud\b/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 4 | ▶ | croak qq{$pkg can't be both "strict" and "fast"} if $strict && $fast; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$Tie::SecureHash::strict and $Tie::SecureHash::fast
MC/DC0%0/2
$Tie::SecureHash::strict and $Tie::SecureHash::fast
$Tie::SecureHash::strict
$Tie::SecureHash::fast
Truth table66%2/3
A and B
A= $Tie::SecureHash::strictB= $Tie::SecureHash::fast
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 4 | ▶ | $strict = 1 if $loud; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | # TAKE A LIST OF POSSIBLE CLASSES FOR AN IMPLICIT KEY AND REMOVE NON-CONTENDERS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 64 | ▶ | sub _winnow { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_winnow: called CC=10 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 64 | my ($caller, $nonpublic, @classes) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | # REMOVE CLASSES NOT IN HIERARCHY FOR NON-PUBLIC KEY | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 64 | ▶ | @classes = grep { $caller->isa($_) } @classes if $nonpublic; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | # COMPARE REMAINING KEYS PAIRWISE, ELIMINATING "SHADOWED" KEYS... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 64 | ▶ | I: for(my $i=0; $i<$#classes; ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 34 | ▶ | J: for(my $j=$i+1; $j<@classes; ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 46 | ▶ | if ($classes[$j]->isa($classes[$i])) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | # CLASS J SHADOWS I FROM $caller | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 26 | ▶ | if ($caller->isa($classes[$j])) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 18 | splice @classes,$i,1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 18 | next I; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | # CLASS J BELOW CALLING PACKAGE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | # (SO CALLING PACKAGE COULDN'T INHERIT IT) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | elsif ($classes[$j]->isa($caller)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 2 | splice @classes,$j,1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 2 | next J; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | } elsif ($classes[$i]->isa($classes[$j])) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | # CLASS I SHADOWS J FROM $caller | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | ▶ | if ($caller->isa($classes[$i])) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | splice @classes,$j,1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | next J; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | # CLASS I BELOW CALLING PACKAGE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | # (SO CALLING PACKAGE COULDN'T INHERIT IT) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | elsif ($classes[$i]->isa($caller)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | splice @classes,$i,1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | next I; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 26 | $j++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 16 | $i++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 64 | return @classes; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | # DETERMINE IF A KEY IS ACCESSIBLE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 1302 | ▶ | sub _access { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_access: called CC=32 SCAR=35.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 1302 | my ($self, $key, $caller, $file, $delete) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | # EXPLICIT KEYS... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 1302 | ▶ | if ($key =~ /\A([\w:]*)::((_{0,2})[^:]+)\Z/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 1156 | my ($classname, $shortkey, $mode) = ($1,$2,$3); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 1156 | ▶ | unless ($classname) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 36 | $classname = 'main'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 36 | $key = $classname.$key; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 1156 | ▶ | if ($mode eq '__') # PRIVATE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 248 | ▶ | croak "Private key $key of tied securehash inaccessible from package $caller" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | unless $classname eq $caller; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 116 | ▶ | if (exists $self->{fullkeys}{$key}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | croak "Private key $key of tied securehash inaccessible from file $file" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 96 | ▶ | if $self->{file}{$key} ne $file; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 20 | ▶ | if ($delete) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | delete $self->{file}{$key}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 20 | $self->{file}{$key} = $file; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | } elsif ($mode eq '_') # PROTECTED | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 318 | ▶ | croak "Protected key $key of tied securehash inaccessible from package $caller" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | unless $caller->isa($classname); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 848 | ▶ | if (!exists $self->{fullkeys}{$key}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 88 | ▶ | croak "Entry for key $key of tied securehash cannot be created " . | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$classname ne $caller and not $delete
MC/DC100%2/2
$classname ne $caller and not $delete
$classname ne $caller
not $delete
Truth table100%3/3
A and not(B)
A= $classname ne $callerB= not $delete
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | "from package $caller" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | if $classname ne $caller && !$delete; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 80 | ▶ | if ($delete) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 4 | @{$self->{keylist}{$shortkey}} = | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | grep { $_ !~ /$classname/ } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 4 | @{$self->{keylist}{$shortkey}} | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 76 | push @{$self->{keylist}{$shortkey}}, $classname; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | # IMPLICIT PRIVATE KEY (MUST BE IN CALLING CLASS) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | elsif ($key =~ /\A(__[^:]+)\Z/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | carp qq{Accessing securehash via unqualified key {"$key"}\n}. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | qq{will be unsafe in 'fast' mode. Use {"${caller}::$key"}} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 36 | ▶ | if $strict && $ENV{UNSAFE_WARN}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$Tie::SecureHash::strict and $ENV{"UNSAFE_WARN"}
MC/DC0%0/2
$Tie::SecureHash::strict and $ENV{"UNSAFE_WARN"}
$Tie::SecureHash::strict
$ENV{"UNSAFE_WARN"}
Truth table66%2/3
A and B
A= $Tie::SecureHash::strictB= $ENV{"UNSAFE_WARN"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 36 | ▶ | if (!exists $self->{fullkeys}{"${caller}::$key"}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | croak "Private key '$key' of tied securehash is inaccessible from package $caller" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 22 | ▶ | if exists $self->{keylist}{$key}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 12 | croak "Private key '${caller}::$key' does not exist in tied securehash" | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 14 | $key = "${caller}::$key"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 14 | ▶ | if (exists $self->{fullkeys}{$key}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | croak "Private key $key of tied securehash inaccessible from file $file" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 14 | ▶ | if $self->{file}{$key} ne $file; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | # IMPLICIT PROTECTED OR PUBLIC KEY | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | # (PROTECTED KEY MUST BE IN ANCESTRAL HIERARCHY OF CALLING CLASS) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | elsif ($key =~ /\A((_?)[^:]+)\Z/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 110 | my $fullkey = "${caller}::$key"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | carp qq{Accessing securehash via unqualified key {"$key"}\n}. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | qq{will be unsafe in 'fast' mode. Use {"${caller}::$key"}} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 110 | ▶ | if $strict && $ENV{UNSAFE_WARN}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$Tie::SecureHash::strict and $ENV{"UNSAFE_WARN"}
MC/DC0%0/2
$Tie::SecureHash::strict and $ENV{"UNSAFE_WARN"}
$Tie::SecureHash::strict
$ENV{"UNSAFE_WARN"}
Truth table66%2/3
A and B
A= $Tie::SecureHash::strictB= $ENV{"UNSAFE_WARN"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 110 | ▶ | if (exists $self->{fullkeys}{$fullkey}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 46 | $key = $fullkey; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | my @classes = _winnow($caller, $2, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 64 | ▶ | @{$self->{keylist}{$key}||[]}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->{'keylist'}{$key} || []
MC/DC100%1/1
$self->{'keylist'}{$key} || []
$self->{'keylist'}{$key}
Truth table100%2/2
A
A= $self->{'keylist'}{$key}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 64 | ▶ | if (@classes) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | # TOO MANY CHOICES | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | croak "Ambiguous key '$key' (when accessed " | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | . "from package $caller).\nCould be:\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 32 | ▶ | . join("", map {"\t${_}::$key\n"} @classes) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | . " " | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | if @classes > 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 22 | $key = $classes[0]."::$key"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | } else # NOT ENOUGH CHOICES | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | croak +($2?"Protected":"Public")." key '$key' of tied securehash is inaccessible from package $caller" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 32 | ▶ | if exists $self->{keylist}{$key}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 24 | ▶ | croak +($2?"Protected":"Public")." key '${caller}::$key' does not exist in tied securehash"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | } else # INVALID KEY | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 0 | croak "Invalid key '$key'"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 922 | ▶ | if ($delete) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 4 | return delete $self->{fullkeys}{$key}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 918 | return \$self->{fullkeys}{$key}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 74 | ▶ | sub _dangerous_access { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_dangerous_access: called CC=8 SCAR=21.7
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 74 | my ($self,$key,$caller, $action) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 74 | ▶ | _complain(@_) if $strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 74 | require mro; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 74 | my @isa = @{mro::get_linear_isa($caller)}; # mro seems to return a weird read only arrayref | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 74 | ▶ | pop @isa if $isa[-1] eq 'Exporter'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 74 | my @candidate_keys = map { "$_::$key" } @isa; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 74 | my $val; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 74 | foreach my $k (@candidate_keys) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 131 | ▶ | if ($action eq 'DELETE') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 1 | my $deleted; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 1 | ▶ | if (exists $self->{fullkeys}->{$k}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 0 | delete $self->{fullkeys}->{$k}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 0 | $deleted = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 1 | ▶ | last if $deleted; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 130 | $val = $self->{fullkeys}->{$k}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 130 | ▶ | last if $val; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 74 | return \$val; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 83 | ▶ | sub _complain { # override complain with Role::Tiny to customise dump. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_complain: called CC=3 SCAR=11.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 83 | my ($self, $key, $caller, $action) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 83 | $DB::single=1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 83 | ▶ | carp "Ran an expensive dangerous $action due to unqualified key $key being sent in to hash for $caller" if $strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 83 | ▶ | if ($loud) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 83 | require Data::Dumper; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 83 | Data::Dumper->import; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 83 | carp Dumper ($self->{fullkeys}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | # NOTE THAT NEW MAY TIE AND BLESS INTO THE SAME CLASS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | # IF NOTHING MORE APPROPRIATE IS SPECIFIED | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 4 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=13 SCAR=43.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 4 | my %self = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 4 | ▶ | my $class = ref($_[0])||$_[0]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
ref $_[0] || $_[0]
MC/DC0%0/2
ref $_[0] || $_[0]
ref $_[0]
$_[0]
Truth table33%1/3
A || B
A= ref $_[0]B= $_[0]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 4 | ▶ | my $blessclass = ref($_[1])||$_[1]||$class; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%2/6
ref $_[1] || $_[1] || $class
ref $_[1] or $_[1]
MC/DC0%0/3
ref $_[1] || $_[1] || $class
ref $_[1]
$_[1]
$class
Truth table25%1/4
A or B || C
A= ref $_[1]B= $_[1]C= $class
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 4 | ▶ | my $impl = tie %self, $class unless $fast; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 4 | my $self = bless \%self, $blessclass; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 4 | splice(@_,0,2); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 4 | ▶ | if (@_) # INITIALIZATION ARGUMENTS PRESENT | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 0 | my ($ancestor, $file); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 0 | my $i = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 0 | ▶ | while ( ($ancestor,$file) = caller($i++) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 0 | ▶ | last if $ancestor eq $blessclass; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 0 | ▶ | $file = "" if ! defined $file; # dms 14 Mar 2000: satisfy -w switch | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 0 | my ($key, $value); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 0 | ▶ | while (($key,$value) = splice(@_,0,2)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 0 | ▶ | my $fullkey = $key=~/::/ ? $key : "${blessclass}::$key"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 0 | ▶ | if ($fast) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 0 | $self->{$fullkey} = $value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 0 | $impl->{fullkeys}{$fullkey} = $value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 0 | push @{$impl->{keylist}{$key}}, $blessclass; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 0 | ▶ | $impl->{file}{$fullkey} = $file | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | if $key =~ /\A__/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 4 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | # USEFUL METHODS TO DUMP INFORMATION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 0 | ▶ | sub debug { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
debug: not called CC=13 SCAR=52.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 0 | my $self = tied %{$_[0]}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 0 | ▶ | my ($caller, $file, $line, $sub) = (caller,(caller(1))[3]||"(none)"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
(caller 1)[3] || '(none)'
MC/DC0%0/1
(caller 1)[3] || '(none)'
(caller 1)[3]
Truth table0%0/2
A
A= (caller 1)[3]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 0 | ▶ | return _simple_debug($_[0],$caller, $file, $line, $sub) unless $self; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 0 | my ($key, $val); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 0 | my %sorted = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 0 | ▶ | while ($key = CORE::each %{$self->{fullkeys}}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 0 | $key =~ m/\A(.*?)([^:]*)\Z/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 0 | push @{$sorted{$1}}, $key; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 0 | print STDERR "\nIn subroutine '$sub' called from package '$caller' ($file, line $line):\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 0 | foreach my $class (CORE::keys %sorted) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 0 | print STDERR "\n\t$class\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 0 | foreach $key ( @{$sorted{$class}} ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 0 | print STDERR "\t\t"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 0 | my ($shortkey) = $key =~ /.*::(.*)/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 0 | my $explanation = ""; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 0 | ▶ | if (eval { _access($self,$shortkey,$caller, $file); 1 }) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 0 | print STDERR '(+)'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | } elsif ($@ =~ /\AAmbiguous key/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 0 | print STDERR '(?)'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 0 | ($explanation = $@) =~ s/.*\n//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 0 | $explanation =~ s/.*\n\Z//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 0 | $explanation =~ s/\ACould/Ambiguous unless fully qualified. Could/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 0 | $explanation =~ s/^(?!\Z)/\t\t\t>>> /gm; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 0 | print STDERR '(-)'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 0 | ▶ | if ($shortkey =~ /\A__/ && $@ =~ /file/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
$shortkey =~ /\A__/ and $@ =~ /file/
MC/DC0%0/2
$shortkey =~ /\A__/ and $@ =~ /file/
$shortkey =~ /\A__/
$@ =~ /file/
Truth table0%0/3
A and B
A= $shortkey =~ /\A__/B= $@ =~ /file/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 0 | $explanation = "\t\t\t>>> Private entry of $class\n\t\t\t>>> declared in file $self->{file}{$key}\n\t\t\t>>> is inaccessable from file $file.\n" | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | } elsif ($shortkey =~ /\A__/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 0 | $explanation = "\t\t\t>>> Private entry of $class\n\t\t\t>>> is inaccessable from package $caller.\n" | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 0 | $explanation = "\t\t\t>>> Protected entry of $class\n\t\t\t>>> is inaccessible outside its hierarchy (i.e. from $caller).\n" | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 0 | my $val = $self->{fullkeys}{$key}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 0 | ▶ | if (defined $val) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | 0 | $val = "'$val'"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 0 | $val = "undef"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 0 | print STDERR " '$shortkey'\t=> $val"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 0 | ▶ | print STDERR "\n$explanation" if $explanation; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | 0 | print STDERR "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 0 | ▶ | sub _simple_debug { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_simple_debug: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 0 | my ($self,$caller, $file, $line, $sub) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 0 | my ($key, $val); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 0 | my %sorted = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 0 | ▶ | while ($key = CORE::each %{$self}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 0 | $key =~ m/\A(.*?)([^:]*)\Z/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 0 | push @{$sorted{$1}}, $key; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | 0 | print "\nIn subroutine '$sub' called from package '$caller' ($file, line $line):\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 0 | foreach my $class (CORE::keys %sorted) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 0 | print "\n\t$class\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | 0 | foreach $key ( @{$sorted{$class}} ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 0 | print "\t\t"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 0 | print " '$key'\t=> '$self->{$key}'\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 35 | ▶ | sub each($) { CORE::each %{$_[0]} } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
each: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 0 | ▶ | sub keys($) { CORE::keys %{$_[0]} } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
keys: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | 4 | ▶ | sub values($) { CORE::values %{$_[0]} } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
values: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 0 | ▶ | sub exists($$) { CORE::exists $_[0]->{$_[1]} } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
exists: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 3 | ▶ | sub TIEHASH { # ($class, @args) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
TIEHASH: called CC=8 SCAR=27.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 3 | ▶ | my $class = ref($_[0]) || $_[0]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
ref $_[0] || $_[0]
MC/DC0%0/2
ref $_[0] || $_[0]
ref $_[0]
$_[0]
Truth table33%1/3
A || B
A= ref $_[0]B= $_[0]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 3 | ▶ | if ($strict) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | carp qq{Tie'ing a securehash directly will be unsafe in 'fast' mode.\n}. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | qq{Use Tie::SecureHash::new instead} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | unless (caller 1)[3] =~ /\A(.*?)::([^:]*)\Z/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | && $2 eq "new" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | 2 | ▶ | && "$1"->isa('Tie::SecureHash') && $ENV{UNSAFE_WARN}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%3/9
(caller 1)[3] =~ /\A(.*?)::([^:]*)\Z/ and $2 eq "new" and "$1"->isa("Tie::SecureHash") and $ENV{"UNSAFE_WARN"}
(caller 1)[3] =~ /\A(.*?)::([^:]*)\Z/ and $2 eq "new" and "$1"->isa("Tie::SecureHash")
(caller 1)[3] =~ /\A(.*?)::([^:]*)\Z/ and $2 eq "new"
MC/DC0%0/4
(caller 1)[3] =~ /\A(.*?)::([^:]*)\Z/ and $2 eq "new" and "$1"->isa("Tie::SecureHash") and $ENV{"UNSAFE_WARN"}
(caller 1)[3] =~ /\A(.*?)::([^:]*)\Z/
$2 eq "new"
"$1"->isa("Tie::SecureHash")
$ENV{"UNSAFE_WARN"}
Truth table20%1/5
A and B and C and D
A= (caller 1)[3] =~ /\A(.*?)::([^:]*)\Z/B= $2 eq "new"C= "$1"->isa("Tie::SecureHash")D= $ENV{"UNSAFE_WARN"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | } elsif ($fast) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | 0 | carp qq{Tie'ing a securehash directly should never happen in 'fast' mode.\n}. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | qq{Use Tie::SecureHash::new instead} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | 3 | bless {}, $class; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | 595 | ▶ | sub FETCH { # ($self, $key) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
FETCH: called CC=4 SCAR=14.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | 595 | my ($self, $key) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | 595 | my $entry; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 595 | ▶ | if (! $dangerous) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | 460 | $entry = _access($self,$key,(caller)[0..1]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | } elsif ($key =~ /::/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | 72 | $entry = \$self->{fullkeys}->{$key}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 63 | my $caller = (caller)[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | 63 | $entry = $self->_dangerous_access($key, $caller, 'FETCH'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | 555 | ▶ | return $$entry if $entry; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | 151 | ▶ | sub STORE { # ($self, $key, $value) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
STORE: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | 151 | my ($self, $key, $value) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | 151 | my $entry; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 151 | ▶ | if (! $dangerous) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | 100 | $entry = _access($self,$key,(caller)[0..1]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | } elsif ($key =~ /::/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | 41 | $self->{fullkeys}->{$key} = $value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | 41 | $entry = \$self->{fullkeys}->{$key}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | 10 | my $caller = (caller)[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | 10 | $entry = $self->_dangerous_access($key,$caller, 'STORE'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | 115 | ▶ | return $$entry = $value if $entry; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | 9 | ▶ | sub DELETE { # ($self, $key) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
DELETE: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | 9 | my ($self, $key) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | 9 | ▶ | if (! $dangerous) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | 6 | return _access($self,$key,(caller)[0..1],'DELETE'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | elsif ($key =~ /::/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | 2 | delete $self->{fullkeys}->{$key}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | 1 | my $caller = (caller)[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | 1 | return $self->_dangerous_access($key, $caller, 'DELETE'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | 6 | ▶ | sub CLEAR { # ($self) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
CLEAR: called CC=3 SCAR=11.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | 6 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | 6 | ▶ | if ($dangerous) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | 2 | %$self = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | 4 | my ($caller, $file) = caller; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | my @inaccessibles = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | 152 | grep { ! eval { _access($self,$_,$caller,$file); 1 } } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | 4 | CORE::keys %{$self->{fullkeys}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | croak "Unable to assign to securehash because the following existing keys\nare inaccessible from package $caller and cannot be deleted:\n" . | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | 4 | ▶ | join("\n", map {"\t$_"} @inaccessibles) . "\n " | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | if @inaccessibles; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | 0 | %{$self} = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | sub EXISTS # ($self, $key) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | 146 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
EXISTS: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | 146 | my ($self, $key) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | 146 | ▶ | if (! $dangerous) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | 128 | my @context = (caller)[0..1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | 128 | ▶ | eval { _access($self,$key,@context); 1 } ? 1 : ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | elsif ($key =~ /::/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | 9 | return exists $self->{fullkeys}->{$key}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | 9 | my $caller = (caller)[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | 9 | ▶ | _complain($self, $key, $caller, 'EXISTS') if $strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | 9 | return exists $self->{fullkeys}->{"$caller::$key"}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | sub FIRSTKEY # ($self) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | 18 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
FIRSTKEY: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | 18 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | 18 | CORE::keys %{$self->{fullkeys}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | 18 | goto &NEXTKEY; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | sub NEXTKEY # ($self) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | 246 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
NEXTKEY: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | 246 | my $self = $_[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | 246 | ▶ | if ($dangerous) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | 6 | return CORE::each %{$self->{fullkeys}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | 240 | my $key; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | 240 | my @context = (caller)[0..1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | 240 | ▶ | while (defined($key = CORE::each %{$self->{fullkeys}})) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | 456 | ▶ | last if eval { _access($self,$key,@context) }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | 228 | ▶ | carp "Attempt to iterate inaccessible key '$key' will be unsafe in 'fast' mode. Use explicit keys" if $ENV{UNSAFE_WARN}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | 240 | return $key; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | 0 | ▶ | sub DESTROY { # ($self) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
DESTROY: not called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | # NOTHING TO DO | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | # (BE CAREFUL SINCE IT DOES DOUBLE DUTY FOR tie AND bless) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | 4 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||