| 1 | package Object::InsideOut::Util; { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 44 | require 5.006; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 44 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 44 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 44 | our $VERSION = '4.03'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 44 | $VERSION = eval $VERSION; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 44 | ▶ | use Object::InsideOut::Metadata 4.03; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | ### Module Initialization ### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | BEGIN { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | # 1. Install our own 'no-op' version of Internals::SvREADONLY for Perl < 5.8 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 44 | ▶ | if (! Internals->can('SvREADONLY')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=3 SCAR=15.1
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 0 | ▶ | *Internals::SvREADONLY = sub (\$;$) { return; }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | # Import 'share' and 'bless' if threads::shared | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 44 | ▶ | if ($threads::shared::threads_shared) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 0 | import threads::shared; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | # 2. Export requested subroutines | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | sub import | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 45 | ▶ | my $class = shift; # Not used | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
import: called CC=4 SCAR=14.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | # Exportable subroutines | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 45 | my %EXPORT_OK; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 45 | @EXPORT_OK{qw(create_object hash_re is_it make_shared shared_copy)} = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | # Handle entries in the import list | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 45 | my $caller = caller(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 45 | my %meta; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 45 | ▶ | while (my $sym = shift) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 177 | ▶ | if (exists($EXPORT_OK{lc($sym)})) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | # Export subroutine name | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 44 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 177 | *{$caller.'::'.$sym} = \&{lc($sym)}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 177 | $meta{$sym}{'hidden'} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | OIO::Code->die( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 'message' => "Symbol '$sym' is not exported by Object::InsideOut::Util", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 'Info' => 'Exportable symbols: ' . join(' ', keys(%EXPORT_OK)), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 'ignore_package' => 'Object::InsideOut::Util'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 45 | ▶ | if (%meta) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 45 | add_meta($caller, \%meta); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | ### Subroutines ### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | # Returns a blessed (optional), readonly (Perl 5.8) anonymous scalar reference | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | # containing either: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | # the value returned by a user-specified subroutine; or | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | # a user-supplied scalar | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | sub create_object | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 183 | ▶ | my ($class, $id) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
create_object: called CC=5 SCAR=17.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | # Create the object from an anonymous scalar reference | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 183 | my $obj = \do{ my $scalar; }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | # Set the scalar equal to ... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 183 | ▶ | if (my $ref_type = ref($id)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 183 | ▶ | if ($ref_type eq 'CODE') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | # ... the value returned by the user-specified subroutine | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 183 | local $SIG{__DIE__} = 'OIO::trap'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 183 | $$obj = $id->($class); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | # Complain if something other than code ref | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | OIO::Args->die( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 'message' => q/2nd argument to create_object() is not a code ref or scalar/, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 'Usage' => 'create_object($class, $scalar) or create_object($class, $code_ref, ...)', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 'ignore_package' => 'Object::InsideOut::Util'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | # ... the user-supplied scalar | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | $$obj = $id; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | # Bless the object into the specified class (optional) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 183 | ▶ | if ($class) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 183 | bless($obj, $class); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | # Make the object 'readonly' (Perl 5.8) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 183 | ▶ | Internals::SvREADONLY($$obj, 1) if ($] >= 5.008003); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | # Done - return the object | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 183 | return ($obj); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | # Make a thread-shared version of a complex data structure or object | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | sub make_shared | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | ▶ | my $in = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
make_shared: not called CC=19 SCAR=59.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | ▶ | my $cloned = shift || {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
shift() || {}
MC/DC0%0/1
shift() || {}
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | # If not sharing or already thread-shared, then just return the input | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | ▶ | if (! ref($in) || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/9
not ref $in && $threads::threads && $threads::shared::threads_shared or threads::shared::is_shared($in)
ref $in && $threads::threads && $threads::shared::threads_shared
ref $in and $threads::threads
MC/DC0%0/4
not ref $in && $threads::threads && $threads::shared::threads_shared or threads::shared::is_shared($in)
ref $in
$threads::threads
$threads::shared::threads_shared
threads::shared::is_shared($in)
Truth table0%0/5
not(A and B && C) or D
A= ref $inB= $threads::threadsC= $threads::shared::threads_sharedD= threads::shared::is_shared($in)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | ! $threads::threads || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | ! $threads::shared::threads_shared || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | threads::shared::is_shared($in)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | return ($in); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | # Check for previously cloned references | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | # (this takes care of circular refs as well) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | my $addr = Scalar::Util::refaddr($in); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | ▶ | if (exists($cloned->{$addr})) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | # Return the already existing clone | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | return $cloned->{$addr}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | # Make copies of array, hash and scalar refs | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | my $out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 0 | my $ref_type = Scalar::Util::reftype($in); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | # Copy an array ref | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 0 | ▶ | if ($ref_type eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | # Make empty shared array ref | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 0 | $out = &threads::shared::share([]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | # Add to clone checking hash | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 0 | $cloned->{$addr} = $out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | # Recursively copy and add contents | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | push(@$out, map { make_shared($_, $cloned) } @$in); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | # Copy a hash ref | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | elsif ($ref_type eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | # Make empty shared hash ref | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | $out = &threads::shared::share({}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | # Add to clone checking hash | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 0 | $cloned->{$addr} = $out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | # Recursively copy and add contents | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 0 | foreach my $key (keys(%{$in})) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 0 | $out->{$key} = make_shared($in->{$key}, $cloned); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | # Copy a scalar ref | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | elsif ($ref_type eq 'SCALAR') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 0 | $out = \do{ my $scalar = $$in; }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 0 | threads::shared::share($out); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | # Add to clone checking hash | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 0 | $cloned->{$addr} = $out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | # Copy of a ref of a ref | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | elsif ($ref_type eq 'REF') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | # Special handling for $x = \$x | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 0 | ▶ | if ($addr == Scalar::Util::refaddr($$in)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 0 | $out = \$out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 0 | threads::shared::share($out); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 0 | $cloned->{$addr} = $out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 0 | my $tmp; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 0 | $out = \$tmp; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 0 | threads::shared::share($out); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | # Add to clone checking hash | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 0 | $cloned->{$addr} = $out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | # Recursively copy and add contents | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 0 | $tmp = make_shared($$in, $cloned); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | # Just return anything else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | # NOTE: This will end up generating an error | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 0 | return ($in); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | # Return blessed copy, if applicable | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 0 | ▶ | if (my $class = Scalar::Util::blessed($in)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 0 | bless($out, $class); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | # Clone READONLY flag | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 0 | ▶ | if ($ref_type eq 'SCALAR') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 0 | ▶ | if (Internals::SvREADONLY($$in)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 0 | ▶ | Internals::SvREADONLY($$out, 1) if ($] >= 5.008003); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 0 | ▶ | if (Internals::SvREADONLY($in)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 0 | ▶ | Internals::SvREADONLY($out, 1) if ($] >= 5.008003); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | # Return clone | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 0 | return ($out); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | # Make a copy of a complex data structure or object. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | # If thread-sharing, then make the copy thread-shared. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | sub shared_copy | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 0 | ▶ | return (($threads::shared::threads_shared) ? clone_shared(@_) : clone(@_)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
shared_copy: not called CC=2 SCAR=17.9
Pod
undocumented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | # Recursively make a copy of a complex data structure or object that is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | # thread-shared | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | sub clone_shared | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 0 | ▶ | my $in = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
clone_shared: not called CC=17 SCAR=57.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 0 | ▶ | my $cloned = shift || {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
shift() || {}
MC/DC0%0/1
shift() || {}
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | # Just return the item if not a ref or if it's an object | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 0 | ▶ | return $in if (! ref($in) || Scalar::Util::blessed($in)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not ref $in or builtin::blessed($in)
MC/DC0%0/2
not ref $in or builtin::blessed($in)
not ref $in
builtin::blessed($in)
Truth table0%0/3
not(A) or B
A= not ref $inB= builtin::blessed($in)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | # Check for previously cloned references | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | # (this takes care of circular refs as well) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 0 | my $addr = Scalar::Util::refaddr($in); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 0 | ▶ | if (exists($cloned->{$addr})) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | # Return the already existing clone | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 0 | return $cloned->{$addr}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | # Make copies of array, hash and scalar refs | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 0 | my $out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 0 | my $ref_type = Scalar::Util::reftype($in); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | # Copy an array ref | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 0 | ▶ | if ($ref_type eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | # Make empty shared array ref | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 0 | $out = &threads::shared::share([]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | # Add to clone checking hash | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 0 | $cloned->{$addr} = $out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | # Recursively copy and add contents | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 0 | push(@$out, map { clone_shared($_, $cloned) } @$in); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | # Copy a hash ref | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | elsif ($ref_type eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | # Make empty shared hash ref | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 0 | $out = &threads::shared::share({}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | # Add to clone checking hash | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 0 | $cloned->{$addr} = $out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | # Recursively copy and add contents | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 0 | foreach my $key (keys(%{$in})) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 0 | $out->{$key} = clone_shared($in->{$key}, $cloned); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | # Copy a scalar ref | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | elsif ($ref_type eq 'SCALAR') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 0 | $out = \do{ my $scalar = $$in; }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 0 | threads::shared::share($out); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | # Add to clone checking hash | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 0 | $cloned->{$addr} = $out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | # Copy of a ref of a ref | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | elsif ($ref_type eq 'REF') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | # Special handling for $x = \$x | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 0 | ▶ | if ($addr == Scalar::Util::refaddr($$in)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 0 | $out = \$out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 0 | threads::shared::share($out); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 0 | $cloned->{$addr} = $out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 0 | my $tmp; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 0 | $out = \$tmp; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 0 | threads::shared::share($out); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | # Add to clone checking hash | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 0 | $cloned->{$addr} = $out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | # Recursively copy and add contents | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 0 | $tmp = clone_shared($$in, $cloned); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | # Just return anything else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | # NOTE: This will end up generating an error | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 0 | return ($in); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | # Return blessed copy, if applicable | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 0 | ▶ | if (my $class = Scalar::Util::blessed($in)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 0 | bless($out, $class); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | # Clone READONLY flag | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 0 | ▶ | if ($ref_type eq 'SCALAR') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 0 | ▶ | if (Internals::SvREADONLY($$in)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 0 | ▶ | Internals::SvREADONLY($$out, 1) if ($] >= 5.008003); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 0 | ▶ | if (Internals::SvREADONLY($in)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 0 | ▶ | Internals::SvREADONLY($out, 1) if ($] >= 5.008003); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | # Return clone | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 0 | return ($out); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | # Recursively make a copy of a complex data structure or object | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | sub clone | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 46 | ▶ | my $in = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
clone: called CC=16 SCAR=38.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | 46 | ▶ | my $cloned = shift || {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
shift() || {}
MC/DC100%1/1
shift() || {}
shift()
Truth table100%2/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | # Just return the item if not a ref or if it's an object | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 46 | ▶ | return $in if (! ref($in) || Scalar::Util::blessed($in)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not ref $in or builtin::blessed($in)
MC/DC100%2/2
not ref $in or builtin::blessed($in)
not ref $in
builtin::blessed($in)
Truth table100%3/3
not(A) or B
A= not ref $inB= builtin::blessed($in)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | # Check for previously cloned references | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | # (this takes care of circular refs as well) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | 9 | my $addr = Scalar::Util::refaddr($in); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 9 | ▶ | if (exists($cloned->{$addr})) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | # Return the already existing clone | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 0 | return $cloned->{$addr}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | # Make copies of array, hash and scalar refs | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 9 | my $out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | 9 | my $ref_type = Scalar::Util::reftype($in); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | # Copy an array ref | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 9 | ▶ | if ($ref_type eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | # Make empty shared array ref | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | 3 | $out = []; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | # Add to clone checking hash | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | 3 | $cloned->{$addr} = $out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | # Recursively copy and add contents | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | 3 | push(@$out, map { clone($_, $cloned) } @$in); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | # Copy a hash ref | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | elsif ($ref_type eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | # Make empty shared hash ref | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 6 | $out = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | # Add to clone checking hash | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | 6 | $cloned->{$addr} = $out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | # Recursively copy and add contents | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | 6 | foreach my $key (keys(%{$in})) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 4 | $out->{$key} = clone($in->{$key}, $cloned); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | # Copy a scalar ref | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | elsif ($ref_type eq 'SCALAR') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | 0 | $out = \do{ my $scalar = $$in; }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | # Add to clone checking hash | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 0 | $cloned->{$addr} = $out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | # Copy of a ref of a ref | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | elsif ($ref_type eq 'REF') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | # Special handling for $x = \$x | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | 0 | ▶ | if ($addr == Scalar::Util::refaddr($$in)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | 0 | $out = \$out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | 0 | $cloned->{$addr} = $out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | 0 | my $tmp; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | 0 | $out = \$tmp; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | # Add to clone checking hash | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | 0 | $cloned->{$addr} = $out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | # Recursively copy and add contents | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | 0 | $tmp = clone($$in, $cloned); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | # Just return anything else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | # NOTE: This will end up generating an error | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | 0 | return ($in); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | # Clone READONLY flag | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | 9 | ▶ | if ($ref_type eq 'SCALAR') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | 0 | ▶ | if (Internals::SvREADONLY($$in)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | 0 | ▶ | Internals::SvREADONLY($$out, 1) if ($] >= 5.008003); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | 9 | ▶ | if (Internals::SvREADONLY($in)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | 0 | ▶ | Internals::SvREADONLY($out, 1) if ($] >= 5.008003); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | # Return clone | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | 9 | return ($out); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | # Access hash value using regex | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | sub hash_re | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | 53 | ▶ | my $hash = $_[0]; # Hash ref to search through | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
hash_re: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | 53 | my $re = $_[1]; # Regex to match keys against | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | 53 | foreach (keys(%{$hash})) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | 51 | ▶ | if (/$re/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | 34 | ▶ | return ($hash->{$_}, $_) if wantarray(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | 23 | return ($hash->{$_}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | 19 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | # Checks if a scalar is a specified type | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | sub is_it | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | 57 | ▶ | my ($thing, $what) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_it: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | 57 | ▶ | return ((Scalar::Util::blessed($thing)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | ? $thing->isa($what) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | : (ref($thing) eq $what)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | } # End of package's lexical scope | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | 44 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||