| 1 | package Attribute::Default; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | { | ||||||||||||||||||||||||||||||||||||||||||
| 3 | 3 | $Attribute::Default::VERSION = '1.35'; | |||||||||||||||||||||||||||||||||||||||||
| 4 | } | ||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | #### | ||||||||||||||||||||||||||||||||||||||||||
| 7 | #### Attribute::Default | ||||||||||||||||||||||||||||||||||||||||||
| 8 | #### | ||||||||||||||||||||||||||||||||||||||||||
| 9 | #### $Id$ | ||||||||||||||||||||||||||||||||||||||||||
| 10 | #### | ||||||||||||||||||||||||||||||||||||||||||
| 11 | #### See perldoc for details. | ||||||||||||||||||||||||||||||||||||||||||
| 12 | #### | ||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | 3 | ▶ | use 5.0010; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | 3 | ▶ | no warnings 'redefine'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | 3 | ▶ | use attributes; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | 3 | ▶ | use Attribute::Handlers 0.79; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | 3 | ▶ | use base qw(Attribute::Handlers Exporter); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | 3 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | 3 | ▶ | use Symbol; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||
| 26 | 3 | our @EXPORT_OK = qw(exsub); | |||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | 3 | ▶ | use constant EXSUB_CLASS => ( __PACKAGE__ . '::ExSub' ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||
| 30 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 31 | ## import() | ||||||||||||||||||||||||||||||||||||||||||
| 32 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 33 | ## Apparently I found it necessary to export 'exsub' | ||||||||||||||||||||||||||||||||||||||||||
| 34 | ## by hand. I don't know why. Eventually, it may | ||||||||||||||||||||||||||||||||||||||||||
| 35 | ## be necessary to turn on some specific functionality | ||||||||||||||||||||||||||||||||||||||||||
| 36 | ## once 'exsub' is exported for compile-time speed. | ||||||||||||||||||||||||||||||||||||||||||
| 37 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 38 | 5 | ▶ | sub import { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
import: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 39 | 5 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||
| 40 | 5 | my ($subname) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 41 | 5 | my $callpkg = (caller())[0]; | |||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||
| 43 | 5 | ▶ | if (defined($subname) && $subname eq 'exsub') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $subname and $subname eq "exsub"
MC/DC50%1/2
defined $subname and $subname eq "exsub"
defined $subname
$subname eq "exsub"
Truth table66%2/3
A and B
A= defined $subnameB= $subname eq "exsub"
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | 3 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 45 | 2 | *{ "${callpkg}::exsub" } = \&exsub; | |||||||||||||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||||||||||||
| 47 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 48 | 3 | SUPER->import(@_); | |||||||||||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||
| 53 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 54 | ## exsub() | ||||||||||||||||||||||||||||||||||||||||||
| 55 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 56 | ## One specifies an expanding subroutine for Default by saying 'exsub | ||||||||||||||||||||||||||||||||||||||||||
| 57 | ## { YOUR CODE HERE }'. It's run and used as a default at runtime. | ||||||||||||||||||||||||||||||||||||||||||
| 58 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 59 | ## Exsubs are marked by being blessed into EXSUB_CLASS. | ||||||||||||||||||||||||||||||||||||||||||
| 60 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 61 | 13 | ▶ | sub exsub(&) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
exsub: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 62 | 13 | my ($sub) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 63 | 13 | ▶ | ref $sub eq 'CODE' or die "Sub '$sub' can't be blessed: must be CODE ref"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 64 | 13 | bless $sub, EXSUB_CLASS; | |||||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||
| 67 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 68 | ## _get_args() | ||||||||||||||||||||||||||||||||||||||||||
| 69 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 70 | ## Fairly close to no-op code. Discards the needless | ||||||||||||||||||||||||||||||||||||||||||
| 71 | ## arguments I get from Attribute::Handlers stuff | ||||||||||||||||||||||||||||||||||||||||||
| 72 | ## and puts single default arguments into array refs. | ||||||||||||||||||||||||||||||||||||||||||
| 73 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 74 | 10 | ▶ | sub _get_args { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_args: called CC=3 SCAR=12.5
| |||||||||||||||||||||||||||||||||||||||||||
| 75 | 10 | my ($glob, $orig, $attr, $defaults) = @_[1 .. 4]; | |||||||||||||||||||||||||||||||||||||||||
| 76 | 10 | ▶ | (ref $defaults && ref $defaults ne 'CODE') or $defaults = [$defaults]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $defaults and ref $defaults ne "CODE"
MC/DC0%0/2
ref $defaults and ref $defaults ne "CODE"
ref $defaults
ref $defaults ne "CODE"
Truth table33%1/3
A and B
A= ref $defaultsB= ref $defaults ne "CODE"
| |||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||
| 78 | 10 | return ($glob, $attr, $defaults, $orig); | |||||||||||||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||
| 81 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 82 | ## _is_method() | ||||||||||||||||||||||||||||||||||||||||||
| 83 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 84 | ## Returns true if the given reference has a ':method' attribute. | ||||||||||||||||||||||||||||||||||||||||||
| 85 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 86 | 19 | ▶ | sub _is_method { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_is_method: called CC=3 SCAR=11.1
| |||||||||||||||||||||||||||||||||||||||||||
| 87 | 19 | my ($orig) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||
| 89 | 19 | foreach ( attributes::get($orig) ) { | |||||||||||||||||||||||||||||||||||||||||
| 90 | 8 | ▶ | ($_ eq 'method') and return 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||
| 93 | 11 | return; | |||||||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||
| 96 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 97 | ## _extract_exsubs_array() | ||||||||||||||||||||||||||||||||||||||||||
| 98 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 99 | ## Arguments: | ||||||||||||||||||||||||||||||||||||||||||
| 100 | ## DEFAULTS -- arrayref : The list of default arguments | ||||||||||||||||||||||||||||||||||||||||||
| 101 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 102 | ## Returns: | ||||||||||||||||||||||||||||||||||||||||||
| 103 | ## hashref: list of exsubs we found and their array indices | ||||||||||||||||||||||||||||||||||||||||||
| 104 | ## arrayref: list of defaults without exsubs | ||||||||||||||||||||||||||||||||||||||||||
| 105 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 106 | 18 | ▶ | sub _extract_exsubs_array { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_extract_exsubs_array: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 107 | 18 | my ($defaults) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||
| 109 | 18 | my %exsubs = (); | |||||||||||||||||||||||||||||||||||||||||
| 110 | 18 | my @noexsubs = (); | |||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||
| 112 | 18 | for ( $[ .. $#$defaults ) { | |||||||||||||||||||||||||||||||||||||||||
| 113 | 26 | ▶ | if (UNIVERSAL::isa( $defaults->[$_], EXSUB_CLASS )) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 114 | 7 | $exsubs{$_} = $defaults->[$_]; | |||||||||||||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||||||||||||
| 116 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 117 | 19 | $noexsubs[$_] = $defaults->[$_]; | |||||||||||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||
| 121 | 18 | return (\%exsubs, \@noexsubs); | |||||||||||||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||
| 125 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 126 | ## _get_fill() | ||||||||||||||||||||||||||||||||||||||||||
| 127 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 128 | ## Returns an appropriate subroutine to process the given defaults. | ||||||||||||||||||||||||||||||||||||||||||
| 129 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 130 | 22 | ▶ | sub _get_fill { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_fill: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 131 | 22 | my ($defaults) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||
| 133 | 22 | ▶ | if (ref $defaults eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 134 | 6 | return _fill_array_sub($defaults); | |||||||||||||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||||||||||||
| 136 | elsif(ref $defaults eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||
| 137 | 13 | return _fill_hash_sub($defaults); | |||||||||||||||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||||||||||||||||
| 139 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 140 | 3 | return _fill_array_sub([$defaults]); | |||||||||||||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||
| 144 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 145 | ## _fill_array_sub() | ||||||||||||||||||||||||||||||||||||||||||
| 146 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 147 | ## Arguments: | ||||||||||||||||||||||||||||||||||||||||||
| 148 | ## DEFAULTS: arrayref | ||||||||||||||||||||||||||||||||||||||||||
| 149 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 150 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 151 | ## Returns: | ||||||||||||||||||||||||||||||||||||||||||
| 152 | ## coderef-- closure to fill sub with defaults | ||||||||||||||||||||||||||||||||||||||||||
| 153 | ## coderef-- closure to fill in exsubs | ||||||||||||||||||||||||||||||||||||||||||
| 154 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 155 | 18 | ▶ | sub _fill_array_sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_fill_array_sub: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 156 | 18 | my ($defaults) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||
| 158 | 18 | my ($exsubs, $plain) = _extract_exsubs_array($defaults); | |||||||||||||||||||||||||||||||||||||||||
| 159 | 18 | ▶ | my $fill_sub = sub { return _fill_arr($plain, @_) }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 160 | 18 | ▶ | if ( %$exsubs ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 161 | return ( $fill_sub, | ||||||||||||||||||||||||||||||||||||||||||
| 162 | 8 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 163 | 8 | my ($processed, $exsub_args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 164 | 8 | ▶ | while (my ($idx, $exsub) = each %$exsubs) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 165 | 8 | ▶ | defined( $processed->[$idx] ) and next; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 166 | 7 | $processed->[$idx] = &$exsub(@$exsub_args); | |||||||||||||||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||||||||||||||||
| 168 | 8 | return $processed; | |||||||||||||||||||||||||||||||||||||||||
| 169 | 7 | }); | |||||||||||||||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||||||||||||||||
| 171 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 172 | 11 | return ($fill_sub, undef); | |||||||||||||||||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||
| 176 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 177 | ## _extract_exsubs_hash() | ||||||||||||||||||||||||||||||||||||||||||
| 178 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 179 | ## Arguments: | ||||||||||||||||||||||||||||||||||||||||||
| 180 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 181 | ## DEFAULTS: hashref -- Name-value pairs of defaults | ||||||||||||||||||||||||||||||||||||||||||
| 182 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 183 | ## Returns: (array) | ||||||||||||||||||||||||||||||||||||||||||
| 184 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 185 | ## hashref -- name-value pairs of all exsubs | ||||||||||||||||||||||||||||||||||||||||||
| 186 | ## hashref -- name-value pairs of all non-exsub defaults | ||||||||||||||||||||||||||||||||||||||||||
| 187 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 188 | ## Returns the exsubs in a hash of defaults. | ||||||||||||||||||||||||||||||||||||||||||
| 189 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 190 | 13 | ▶ | sub _extract_exsubs_hash { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_extract_exsubs_hash: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 191 | 13 | my ($defaults) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||||||
| 193 | 13 | my %exsubs = (); | |||||||||||||||||||||||||||||||||||||||||
| 194 | 13 | my %noexsubs = (); | |||||||||||||||||||||||||||||||||||||||||
| 195 | 13 | ▶ | while ( my ($key, $value) = each %$defaults ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 196 | 22 | ▶ | if (UNIVERSAL::isa( $value, EXSUB_CLASS ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 197 | 6 | $exsubs{$key} = $value; | |||||||||||||||||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||||||||||||||||
| 199 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 200 | 16 | $noexsubs{$key} = $value; | |||||||||||||||||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||||||||||||||||
| 203 | 13 | return (\%exsubs, \%noexsubs); | |||||||||||||||||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||||||
| 206 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 207 | ## _fill_hash_sub() | ||||||||||||||||||||||||||||||||||||||||||
| 208 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 209 | ## Arguments | ||||||||||||||||||||||||||||||||||||||||||
| 210 | ## DEFAULTS: hashref -- name-value pairs of defaults | ||||||||||||||||||||||||||||||||||||||||||
| 211 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 212 | ## Returns: list | ||||||||||||||||||||||||||||||||||||||||||
| 213 | ## coderef -- closure to fill default values | ||||||||||||||||||||||||||||||||||||||||||
| 214 | ## coderef -- closure to fill exsubs | ||||||||||||||||||||||||||||||||||||||||||
| 215 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 216 | ## Returns the appropriate preprocessor to fill a hash | ||||||||||||||||||||||||||||||||||||||||||
| 217 | ## with defaults. | ||||||||||||||||||||||||||||||||||||||||||
| 218 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 219 | 13 | ▶ | sub _fill_hash_sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_fill_hash_sub: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 220 | 13 | my ($defaults) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||||||||||||
| 222 | 13 | my ($exsubs, $plain) = _extract_exsubs_hash($defaults); | |||||||||||||||||||||||||||||||||||||||||
| 223 | 13 | ▶ | my $fill_sub = sub { return _fill_hash($plain, @_); }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 224 | 13 | ▶ | if ( %$exsubs ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 225 | return ($fill_sub, | ||||||||||||||||||||||||||||||||||||||||||
| 226 | 8 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 227 | 8 | my ($filled, $exsub_args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 228 | 8 | my %processed = @$filled; | |||||||||||||||||||||||||||||||||||||||||
| 229 | 8 | ▶ | while (my ($key, $exsub) = each %$exsubs) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 230 | 8 | ▶ | (! defined $processed{$key}) or next; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 231 | 7 | $processed{$key} = &$exsub(@$exsub_args); | |||||||||||||||||||||||||||||||||||||||||
| 232 | } | ||||||||||||||||||||||||||||||||||||||||||
| 233 | 8 | @$filled = %processed; | |||||||||||||||||||||||||||||||||||||||||
| 234 | 8 | return $filled; | |||||||||||||||||||||||||||||||||||||||||
| 235 | 6 | }); | |||||||||||||||||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||||||||||||||||
| 237 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 238 | 7 | return ( $fill_sub, undef ); | |||||||||||||||||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||||||||||||||||
| 240 | } | ||||||||||||||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||||||||||||||
| 242 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 243 | ## _get_sub() | ||||||||||||||||||||||||||||||||||||||||||
| 244 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 245 | ## Arguments: | ||||||||||||||||||||||||||||||||||||||||||
| 246 | ## DEFAULTS: arrayref -- Array of defaults to a subroutine | ||||||||||||||||||||||||||||||||||||||||||
| 247 | ## ORIG: code ref -- The subroutine we're applying defaults to | ||||||||||||||||||||||||||||||||||||||||||
| 248 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 249 | ## Returns the appropriate subroutine wrapper that | ||||||||||||||||||||||||||||||||||||||||||
| 250 | ## will call ORIG with the given default values. | ||||||||||||||||||||||||||||||||||||||||||
| 251 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 252 | 10 | ▶ | sub _get_sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_sub: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 253 | 10 | my ($defaults, $orig) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||||||||||
| 255 | 10 | my ($fill_sub, $exsub_sub) = _get_fill($defaults); | |||||||||||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||||||||||
| 257 | 10 | ▶ | if ( _is_method($orig) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 258 | 5 | ▶ | if (defined $exsub_sub) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 259 | 4 | ▶ | return sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 260 | 4 | my ($self, @args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 261 | 4 | my @filled = &$fill_sub(@args); | |||||||||||||||||||||||||||||||||||||||||
| 262 | 4 | @_ = ($self, @{ &$exsub_sub( \@filled, [$self, @filled] ) } ); | |||||||||||||||||||||||||||||||||||||||||
| 263 | 4 | goto $orig; | |||||||||||||||||||||||||||||||||||||||||
| 264 | 4 | }; | |||||||||||||||||||||||||||||||||||||||||
| 265 | } | ||||||||||||||||||||||||||||||||||||||||||
| 266 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 267 | 1 | ▶ | return sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 268 | 1 | my ($self, @args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 269 | 1 | @_ = ($self, &$fill_sub(@args)); | |||||||||||||||||||||||||||||||||||||||||
| 270 | 1 | goto $orig; | |||||||||||||||||||||||||||||||||||||||||
| 271 | 1 | }; | |||||||||||||||||||||||||||||||||||||||||
| 272 | } | ||||||||||||||||||||||||||||||||||||||||||
| 273 | } | ||||||||||||||||||||||||||||||||||||||||||
| 274 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 275 | 5 | ▶ | if (defined $exsub_sub) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 276 | 5 | ▶ | return sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 277 | 5 | my @filled = &$fill_sub(@_); | |||||||||||||||||||||||||||||||||||||||||
| 278 | 5 | @_ = @{ &$exsub_sub( \@filled, \@filled ) }; | |||||||||||||||||||||||||||||||||||||||||
| 279 | 5 | goto $orig; | |||||||||||||||||||||||||||||||||||||||||
| 280 | 2 | }; | |||||||||||||||||||||||||||||||||||||||||
| 281 | } | ||||||||||||||||||||||||||||||||||||||||||
| 282 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 283 | 7 | ▶ | return sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 284 | 7 | @_ = &$fill_sub(@_); | |||||||||||||||||||||||||||||||||||||||||
| 285 | 7 | goto $orig; | |||||||||||||||||||||||||||||||||||||||||
| 286 | 3 | }; | |||||||||||||||||||||||||||||||||||||||||
| 287 | } | ||||||||||||||||||||||||||||||||||||||||||
| 288 | } | ||||||||||||||||||||||||||||||||||||||||||
| 289 | } | ||||||||||||||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||||||||||||||||
| 292 | 10 | ▶ | sub Default : ATTR(CODE) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
Default: called CC=4 SCAR=14.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 293 | 10 | my ($glob, $attr, $defaults_arg, $orig) = _get_args(@_); | |||||||||||||||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||||||||||||||||
| 295 | 10 | my $defaults = $defaults_arg; | |||||||||||||||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||||||||||||||||
| 297 | 10 | ▶ | if ( defined $defaults && (ref $defaults eq 'ARRAY') && ( scalar @{ $defaults } == 1 ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
defined $defaults and ref $defaults eq "ARRAY" and scalar @{$defaults;} == 1
defined $defaults and ref $defaults eq "ARRAY"
MC/DC33%1/3
defined $defaults and ref $defaults eq "ARRAY" and scalar @{$defaults;} == 1
defined $defaults
ref $defaults eq "ARRAY"
scalar @{$defaults;} == 1
Truth table50%2/4
A and B and C
A= defined $defaultsB= ref $defaults eq "ARRAY"C= scalar @{$defaults;} == 1
| |||||||||||||||||||||||||||||||||||||||||||
| 298 | 7 | $defaults = $defaults_arg->[0]; | |||||||||||||||||||||||||||||||||||||||||
| 299 | } | ||||||||||||||||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||||||||||||||||
| 301 | 10 | *$glob = _get_sub($defaults, $orig); | |||||||||||||||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||||||||||||||||
| 303 | 3 | ▶ | } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||||||||||||||||
| 306 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 307 | ## _fill_hash() | ||||||||||||||||||||||||||||||||||||||||||
| 308 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 309 | ## Arguments: | ||||||||||||||||||||||||||||||||||||||||||
| 310 | ## DEFAULTS: hashref -- Hash table of default arguments | ||||||||||||||||||||||||||||||||||||||||||
| 311 | ## ARGS: list -- The arguments to be filtered | ||||||||||||||||||||||||||||||||||||||||||
| 312 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 313 | ## Returns: | ||||||||||||||||||||||||||||||||||||||||||
| 314 | ## list -- Arguments with defaults filled in | ||||||||||||||||||||||||||||||||||||||||||
| 315 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 316 | 16 | ▶ | sub _fill_hash { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_fill_hash: called CC=4 SCAR=14.0
| |||||||||||||||||||||||||||||||||||||||||||
| 317 | 16 | my $defaults = shift; | |||||||||||||||||||||||||||||||||||||||||
| 318 | 16 | my %args = @_; | |||||||||||||||||||||||||||||||||||||||||
| 319 | 16 | ▶ | while (my ($key, $value) = each %$defaults) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 320 | 19 | ▶ | unless ( defined($args{$key}) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 321 | 14 | ▶ | if ( UNIVERSAL::isa( $value, EXSUB_CLASS ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 322 | 0 | $args{$key} = undef; | |||||||||||||||||||||||||||||||||||||||||
| 323 | } | ||||||||||||||||||||||||||||||||||||||||||
| 324 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 325 | 14 | $args{$key} = $value; | |||||||||||||||||||||||||||||||||||||||||
| 326 | } | ||||||||||||||||||||||||||||||||||||||||||
| 327 | } | ||||||||||||||||||||||||||||||||||||||||||
| 328 | } | ||||||||||||||||||||||||||||||||||||||||||
| 329 | 16 | return %args; | |||||||||||||||||||||||||||||||||||||||||
| 330 | } | ||||||||||||||||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||||||||||||||||
| 332 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 333 | ## _fill_arr() | ||||||||||||||||||||||||||||||||||||||||||
| 334 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 335 | ## Arguments: | ||||||||||||||||||||||||||||||||||||||||||
| 336 | ## DEFAULTS: arrayref -- Array of default arguments | ||||||||||||||||||||||||||||||||||||||||||
| 337 | ## ARGS: list -- The arguments to be filtered | ||||||||||||||||||||||||||||||||||||||||||
| 338 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 339 | ## Returns: | ||||||||||||||||||||||||||||||||||||||||||
| 340 | ## list -- Arguments with defaults filled in | ||||||||||||||||||||||||||||||||||||||||||
| 341 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 342 | 23 | ▶ | sub _fill_arr { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_fill_arr: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 343 | 23 | my $defaults = shift; | |||||||||||||||||||||||||||||||||||||||||
| 344 | 23 | my @filled = (); | |||||||||||||||||||||||||||||||||||||||||
| 345 | 23 | foreach (0 .. $#_) { | |||||||||||||||||||||||||||||||||||||||||
| 346 | 12 | ▶ | push @filled, ( defined( $_[$_] ) ? $_[$_] : $defaults->[$_] ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 347 | } | ||||||||||||||||||||||||||||||||||||||||||
| 348 | 23 | ▶ | if ($#$defaults > $#_) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 349 | 10 | push(@filled, @$defaults[scalar @_ .. $#$defaults]); | |||||||||||||||||||||||||||||||||||||||||
| 350 | } | ||||||||||||||||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||||||||||||||||
| 352 | 23 | return @filled; | |||||||||||||||||||||||||||||||||||||||||
| 353 | } | ||||||||||||||||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||||||||||||||||
| 355 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 356 | ## Defaults() | ||||||||||||||||||||||||||||||||||||||||||
| 357 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 358 | ## Arguments: | ||||||||||||||||||||||||||||||||||||||||||
| 359 | ## GLOB: typeglobref -- Typeglob of name of sub to wrap | ||||||||||||||||||||||||||||||||||||||||||
| 360 | ## ORIG: coderef -- Ref to original sub | ||||||||||||||||||||||||||||||||||||||||||
| 361 | ## ATTR: string -- name of the attribute (Always 'Defaults' right now) | ||||||||||||||||||||||||||||||||||||||||||
| 362 | ## DEFAULTS_LIST -- list of default arguments | ||||||||||||||||||||||||||||||||||||||||||
| 363 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 364 | ## Defaults() creates a wrapper subroutine that does a two-layer check on | ||||||||||||||||||||||||||||||||||||||||||
| 365 | ## incoming arguments. It first processes the toplevel arguments as an | ||||||||||||||||||||||||||||||||||||||||||
| 366 | ## array, then processes any reference defaults. | ||||||||||||||||||||||||||||||||||||||||||
| 367 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 368 | ## If the default and the argument are of differing reference types, the | ||||||||||||||||||||||||||||||||||||||||||
| 369 | ## argument is passed through unscathed. | ||||||||||||||||||||||||||||||||||||||||||
| 370 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 371 | ## An undef of a reference type is treated like someone passing an empty | ||||||||||||||||||||||||||||||||||||||||||
| 372 | ## array or hash. | ||||||||||||||||||||||||||||||||||||||||||
| 373 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 374 | ## Implementation note: Using huge numbers of closures like I am may | ||||||||||||||||||||||||||||||||||||||||||
| 375 | ## waste too much memory. It's a hell of a lot cleaner than what I was doing | ||||||||||||||||||||||||||||||||||||||||||
| 376 | ## before, though. | ||||||||||||||||||||||||||||||||||||||||||
| 377 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 378 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 379 | 9 | ▶ | sub Defaults : ATTR(CODE) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
Defaults: called CC=8 SCAR=20.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 380 | 9 | my ($glob, $orig, $attr, $defaults) = @_[1 .. 4]; | |||||||||||||||||||||||||||||||||||||||||
| 381 | 9 | ▶ | (ref $defaults) && (ref $defaults eq 'ARRAY') or $defaults = [$defaults]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $defaults and ref $defaults eq "ARRAY"
MC/DC0%0/2
ref $defaults and ref $defaults eq "ARRAY"
ref $defaults
ref $defaults eq "ARRAY"
Truth table33%1/3
A and B
A= ref $defaultsB= ref $defaults eq "ARRAY"
| |||||||||||||||||||||||||||||||||||||||||||
| 382 | |||||||||||||||||||||||||||||||||||||||||||
| 383 | 9 | my @ref_defaults = (); | |||||||||||||||||||||||||||||||||||||||||
| 384 | 9 | my @ref_exsubs = (); | |||||||||||||||||||||||||||||||||||||||||
| 385 | 9 | my @toplevel_defaults = (); | |||||||||||||||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||||||||||||||||
| 387 | 9 | foreach ($[ .. $#$defaults) { | |||||||||||||||||||||||||||||||||||||||||
| 388 | 18 | ▶ | if ( (my $type = ref $$defaults[$_]) && (! UNIVERSAL::isa($$defaults[$_], EXSUB_CLASS) ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
my $type = ref $defaults->[$_] and not UNIVERSAL::isa($defaults->[$_], "Attribute::Default::ExSub")
MC/DC100%2/2
my $type = ref $defaults->[$_] and not UNIVERSAL::isa($defaults->[$_], "Attribute::Default::ExSub")
my $type = ref $defaults->[$_]
not UNIVERSAL::isa($defaults->[$_], "Attribute::Default::ExSub")
Truth table100%3/3
A and not(B)
A= my $type = ref $defaults->[$_]B= not UNIVERSAL::isa($defaults->[$_], "Attribute::Default::ExSub")
| |||||||||||||||||||||||||||||||||||||||||||
| 389 | 12 | my ($fill_sub, $fill_exsub) = _get_fill($$defaults[$_]); | |||||||||||||||||||||||||||||||||||||||||
| 390 | 12 | push @ref_defaults, [$_, $type, $fill_sub]; | |||||||||||||||||||||||||||||||||||||||||
| 391 | 12 | ▶ | defined $fill_exsub and push @ref_exsubs, [$_, $type, $fill_exsub]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 392 | } | ||||||||||||||||||||||||||||||||||||||||||
| 393 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 394 | 6 | $toplevel_defaults[$_] = $$defaults[$_]; | |||||||||||||||||||||||||||||||||||||||||
| 395 | } | ||||||||||||||||||||||||||||||||||||||||||
| 396 | } | ||||||||||||||||||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||||||||||||||||
| 398 | 9 | my ($toplevel_sub, $toplevel_exsub) = _fill_array_sub(\@toplevel_defaults); | |||||||||||||||||||||||||||||||||||||||||
| 399 | |||||||||||||||||||||||||||||||||||||||||||
| 400 | 9 | ▶ | if ( _is_method($orig) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 401 | *$glob = | ||||||||||||||||||||||||||||||||||||||||||
| 402 | 2 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||
| 403 | 2 | my @filled = &$toplevel_sub(@_[ ($[ + 1) .. $#_ ]); | |||||||||||||||||||||||||||||||||||||||||
| 404 | 2 | _fill_sublevel(\@filled, \@ref_defaults); | |||||||||||||||||||||||||||||||||||||||||
| 405 | 2 | ▶ | defined ($toplevel_exsub) && &$toplevel_exsub(\@filled, [$_[0], @filled]); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 406 | 2 | _fill_exsubs(\@filled, \@ref_exsubs, [$_[0], @filled]); | |||||||||||||||||||||||||||||||||||||||||
| 407 | 2 | @_ = ($_[0], @filled); | |||||||||||||||||||||||||||||||||||||||||
| 408 | 2 | goto $orig; | |||||||||||||||||||||||||||||||||||||||||
| 409 | } | ||||||||||||||||||||||||||||||||||||||||||
| 410 | 3 | } | |||||||||||||||||||||||||||||||||||||||||
| 411 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 412 | *$glob = | ||||||||||||||||||||||||||||||||||||||||||
| 413 | 8 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 414 | |||||||||||||||||||||||||||||||||||||||||||
| 415 | # First, fill toplevel arguments | ||||||||||||||||||||||||||||||||||||||||||
| 416 | 8 | my @filled = &$toplevel_sub(@_); | |||||||||||||||||||||||||||||||||||||||||
| 417 | |||||||||||||||||||||||||||||||||||||||||||
| 418 | # Next, fill all sublevel arguments | ||||||||||||||||||||||||||||||||||||||||||
| 419 | 8 | _fill_sublevel(\@filled, \@ref_defaults); | |||||||||||||||||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||||||||||||||||
| 421 | 8 | ▶ | defined ($toplevel_exsub) && &$toplevel_exsub(\@filled, \@filled); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 422 | 8 | _fill_exsubs(\@filled, \@ref_exsubs, \@filled); | |||||||||||||||||||||||||||||||||||||||||
| 423 | 8 | @_ = @filled; | |||||||||||||||||||||||||||||||||||||||||
| 424 | 8 | goto $orig; | |||||||||||||||||||||||||||||||||||||||||
| 425 | } | ||||||||||||||||||||||||||||||||||||||||||
| 426 | |||||||||||||||||||||||||||||||||||||||||||
| 427 | 6 | } | |||||||||||||||||||||||||||||||||||||||||
| 428 | |||||||||||||||||||||||||||||||||||||||||||
| 429 | |||||||||||||||||||||||||||||||||||||||||||
| 430 | 3 | ▶ | } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 431 | |||||||||||||||||||||||||||||||||||||||||||
| 432 | 10 | ▶ | sub _fill_exsubs { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_fill_exsubs: called CC=6 SCAR=21.6
| |||||||||||||||||||||||||||||||||||||||||||
| 433 | 10 | my ($args, $ref_exsubs, $exsub_args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 434 | |||||||||||||||||||||||||||||||||||||||||||
| 435 | 10 | foreach (@$ref_exsubs) { | |||||||||||||||||||||||||||||||||||||||||
| 436 | 4 | my ($idx, $type, $exsub_sub) = @$_; | |||||||||||||||||||||||||||||||||||||||||
| 437 | 4 | ▶ | ($type eq ref $$args[$idx]) || (! defined $$args[$idx]) or next; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$type eq ref $args->[$idx] or not defined $args->[$idx]
MC/DC0%0/2
$type eq ref $args->[$idx] or not defined $args->[$idx]
$type eq ref $args->[$idx]
not defined $args->[$idx]
Truth table33%1/3
A or not(B)
A= $type eq ref $args->[$idx]B= not defined $args->[$idx]
| |||||||||||||||||||||||||||||||||||||||||||
| 438 | 4 | ▶ | if ($type eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 439 | 4 | $$args[$idx] = { @{ &$exsub_sub( [%{ $$args[$idx] } ], $exsub_args ) } }; | |||||||||||||||||||||||||||||||||||||||||
| 440 | } | ||||||||||||||||||||||||||||||||||||||||||
| 441 | elsif ($type eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||
| 442 | 0 | $$args[$idx] = &$exsub_sub( $$args[$idx], $exsub_args ); | |||||||||||||||||||||||||||||||||||||||||
| 443 | } | ||||||||||||||||||||||||||||||||||||||||||
| 444 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 445 | 0 | die "Exsub expansion cannot handle '$type'"; | |||||||||||||||||||||||||||||||||||||||||
| 446 | } | ||||||||||||||||||||||||||||||||||||||||||
| 447 | } | ||||||||||||||||||||||||||||||||||||||||||
| 448 | } | ||||||||||||||||||||||||||||||||||||||||||
| 449 | |||||||||||||||||||||||||||||||||||||||||||
| 450 | |||||||||||||||||||||||||||||||||||||||||||
| 451 | |||||||||||||||||||||||||||||||||||||||||||
| 452 | 10 | ▶ | sub _fill_sublevel { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_fill_sublevel: called CC=8 SCAR=21.2
| |||||||||||||||||||||||||||||||||||||||||||
| 453 | 10 | my ($filled, $ref_defaults) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 454 | |||||||||||||||||||||||||||||||||||||||||||
| 455 | 10 | foreach (@$ref_defaults) { | |||||||||||||||||||||||||||||||||||||||||
| 456 | 12 | my ($idx, $type, $fill_sub) = @$_; | |||||||||||||||||||||||||||||||||||||||||
| 457 | 12 | ▶ | ($type eq ref $$filled[$idx]) || (! defined $$filled[$idx]) or next; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$type eq ref $filled->[$idx] or not defined $filled->[$idx]
MC/DC0%0/2
$type eq ref $filled->[$idx] or not defined $filled->[$idx]
$type eq ref $filled->[$idx]
not defined $filled->[$idx]
Truth table66%2/3
A or not(B)
A= $type eq ref $filled->[$idx]B= not defined $filled->[$idx]
| |||||||||||||||||||||||||||||||||||||||||||
| 458 | 12 | ▶ | if ($type eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 459 | 9 | ▶ | $$filled[$idx] = { &$fill_sub( defined $$filled[$idx] ? %{ $$filled[$idx] } : () ) }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 460 | } elsif ($type eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||
| 461 | 3 | ▶ | $$filled[$idx] = [ &$fill_sub( defined $$filled[$idx] ? @{ $$filled[$idx] } : () ) ]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 462 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 463 | 0 | die "I don't know what to do with '$type'"; | |||||||||||||||||||||||||||||||||||||||||
| 464 | } | ||||||||||||||||||||||||||||||||||||||||||
| 465 | |||||||||||||||||||||||||||||||||||||||||||
| 466 | } | ||||||||||||||||||||||||||||||||||||||||||
| 467 | |||||||||||||||||||||||||||||||||||||||||||
| 468 | } | ||||||||||||||||||||||||||||||||||||||||||
| 469 | |||||||||||||||||||||||||||||||||||||||||||
| 470 | 3 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 471 | __END__ | ||||||||||||||||||||||||||||||||||||||||||