| 1 | ##---------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 2 | ## MIME Email Builder - ~/lib/MM/Table.pm | ||||||||||||||||||||||||||||
| 3 | ## Version v0.5.0 | ||||||||||||||||||||||||||||
| 4 | ## Copyright(c) 2026 DEGUEST Pte. Ltd. | ||||||||||||||||||||||||||||
| 5 | ## Author: Jacques Deguest <jack@deguest.jp> | ||||||||||||||||||||||||||||
| 6 | ## Created 2026/03/03 | ||||||||||||||||||||||||||||
| 7 | ## Modified 2026/03/04 | ||||||||||||||||||||||||||||
| 8 | ## All rights reserved | ||||||||||||||||||||||||||||
| 9 | ## | ||||||||||||||||||||||||||||
| 10 | ## | ||||||||||||||||||||||||||||
| 11 | ## This program is free software; you can redistribute it and/or modify it | ||||||||||||||||||||||||||||
| 12 | ## under the same terms as Perl itself. | ||||||||||||||||||||||||||||
| 13 | ##---------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 14 | package MM::Table; | ||||||||||||||||||||||||||||
| 15 | BEGIN | ||||||||||||||||||||||||||||
| 16 | 10 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | 10 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | 10 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | 10 | ▶ | use vars qw( $VERSION ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | 10 | ▶ | use Scalar::Util qw( blessed ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | 10 | ▶ | use Mail::Make::Exception; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 22 | 10 | ▶ | use overload ( | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 23 | 10 | '%{}' => '_as_hashref', | |||||||||||||||||||||||||||
| 24 | fallback => 1 | ||||||||||||||||||||||||||||
| 25 | 10 | ); | |||||||||||||||||||||||||||
| 26 | 10 | our $VERSION = 'v0.5.0'; | |||||||||||||||||||||||||||
| 27 | }; | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 10 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 30 | 10 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | sub make | ||||||||||||||||||||||||||||
| 33 | 298 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
make: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 34 | 298 | my( $class ) = @_; | |||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 298 | my $state = | |||||||||||||||||||||||||||
| 37 | { | ||||||||||||||||||||||||||||
| 38 | _entries => [], # array of { key => original, lkey => lc, val => string } | ||||||||||||||||||||||||||||
| 39 | _error => undef, | ||||||||||||||||||||||||||||
| 40 | _tied_href => undef, | ||||||||||||||||||||||||||||
| 41 | }; | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 298 | my $self = bless( \$state, $class ); | |||||||||||||||||||||||||||
| 44 | 298 | return( $self ); | |||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | sub add | ||||||||||||||||||||||||||||
| 48 | 1183 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
add: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 49 | 1183 | my( $self, $key, $val ) = @_; | |||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 1183 | ▶ | $self->_validate_key( $key ) || return( $self->pass_error ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 52 | 1183 | $val = $self->_stringify_value( $val ); | |||||||||||||||||||||||||||
| 53 | 1183 | my $lkey = lc( $key ); | |||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 1183 | my $st = $self->_state(); | |||||||||||||||||||||||||||
| 56 | 1183 | push( @{$st->{_entries}}, { key => $key, lkey => $lkey, val => $val } ); | |||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 1183 | $self->_invalidate_tie_cache(); | |||||||||||||||||||||||||||
| 59 | 1183 | return( $self ); | |||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | sub clear | ||||||||||||||||||||||||||||
| 63 | 5 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
clear: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 64 | 5 | my( $self ) = @_; | |||||||||||||||||||||||||||
| 65 | 5 | my $st = $self->_state(); | |||||||||||||||||||||||||||
| 66 | 5 | $st->{_entries} = []; | |||||||||||||||||||||||||||
| 67 | 5 | $self->_invalidate_tie_cache(); | |||||||||||||||||||||||||||
| 68 | 5 | return( $self ); | |||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | sub compress | ||||||||||||||||||||||||||||
| 72 | 2 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
compress: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||||
| 73 | 2 | my( $self, $flags ) = @_; | |||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 2 | ▶ | $self->_validate_overlap_flags( $flags, 'compress' ) || return( $self->pass_error ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 76 | 2 | ▶ | $flags //= 0; | ||||||||||||||||||||||||||
|
Condition50%1/2
$flags //= 0
MC/DC0%0/1
$flags //= 0
$flags
Truth table50%1/2
A
A= $flags
| |||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 2 | my $st = $self->_state(); | |||||||||||||||||||||||||||
| 79 | 2 | ▶ | my $src = $st->{_entries} || []; | ||||||||||||||||||||||||||
|
Condition50%1/2
$st->{'_entries'} || []
MC/DC0%0/1
$st->{'_entries'} || []
$st->{'_entries'}
Truth table50%1/2
A
A= $st->{'_entries'}
| |||||||||||||||||||||||||||||
| 80 | 2 | my @out; | |||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | my %seen_idx; | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 2 | ▶ | for( my $i = 0; $i < scalar( @$src ); $i++ ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 85 | { | ||||||||||||||||||||||||||||
| 86 | 8 | my $e = $src->[ $i ]; | |||||||||||||||||||||||||||
| 87 | 8 | my $lkey = $e->{lkey}; | |||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 8 | ▶ | if( !exists( $seen_idx{ $lkey } ) ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 90 | { | ||||||||||||||||||||||||||||
| 91 | push( @out, | ||||||||||||||||||||||||||||
| 92 | { | ||||||||||||||||||||||||||||
| 93 | key => $e->{key}, | ||||||||||||||||||||||||||||
| 94 | lkey => $lkey, | ||||||||||||||||||||||||||||
| 95 | val => $e->{val}, | ||||||||||||||||||||||||||||
| 96 | 4 | }); | |||||||||||||||||||||||||||
| 97 | 4 | $seen_idx{ $lkey } = scalar( @out ) - 1; | |||||||||||||||||||||||||||
| 98 | 4 | next; | |||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 4 | my $idx = $seen_idx{ $lkey }; | |||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | 4 | ▶ | if( $flags ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 104 | { | ||||||||||||||||||||||||||||
| 105 | 2 | $out[ $idx ]->{val} = $out[$idx]->{val} . ', ' . $e->{val}; | |||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||
| 107 | else | ||||||||||||||||||||||||||||
| 108 | { | ||||||||||||||||||||||||||||
| 109 | 2 | $out[ $idx ]->{key} = $e->{key}; | |||||||||||||||||||||||||||
| 110 | 2 | $out[ $idx ]->{val} = $e->{val}; | |||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | 2 | $st->{_entries} = \@out; | |||||||||||||||||||||||||||
| 115 | 2 | $self->_invalidate_tie_cache(); | |||||||||||||||||||||||||||
| 116 | 2 | return( $self ); | |||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | sub copy | ||||||||||||||||||||||||||||
| 120 | 6 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
copy: called CC=4 SCAR=14.1
Pod
documented
| |||||||||||||||||||||||||||||
| 121 | 6 | my( $self ) = @_; | |||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | 6 | ▶ | my $class = ref( $self ) || $self; | ||||||||||||||||||||||||||
|
Condition33%1/3
ref $self || $self
MC/DC0%0/2
ref $self || $self
ref $self
$self
Truth table33%1/3
A || B
A= ref $selfB= $self
| |||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | 6 | my $state = | |||||||||||||||||||||||||||
| 126 | { | ||||||||||||||||||||||||||||
| 127 | _entries => [], | ||||||||||||||||||||||||||||
| 128 | _error => undef, | ||||||||||||||||||||||||||||
| 129 | _tied_href => undef, | ||||||||||||||||||||||||||||
| 130 | }; | ||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | 6 | my $new = bless( \$state, $class ); | |||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | 6 | ▶ | my $src = $self->_state()->{_entries} || []; | ||||||||||||||||||||||||||
|
Condition50%1/2
$self->_state->{'_entries'} || []
MC/DC0%0/1
$self->_state->{'_entries'} || []
$self->_state->{'_entries'}
Truth table50%1/2
A
A= $self->_state->{'_entries'}
| |||||||||||||||||||||||||||||
| 135 | 6 | my $dst = $new->_state()->{_entries}; | |||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | 6 | ▶ | for( my $i = 0; $i < scalar( @$src ); $i++ ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 138 | { | ||||||||||||||||||||||||||||
| 139 | 16 | my $e = $src->[ $i ]; | |||||||||||||||||||||||||||
| 140 | push( @$dst, | ||||||||||||||||||||||||||||
| 141 | { | ||||||||||||||||||||||||||||
| 142 | key => $e->{key}, | ||||||||||||||||||||||||||||
| 143 | lkey => $e->{lkey}, | ||||||||||||||||||||||||||||
| 144 | val => $e->{val}, | ||||||||||||||||||||||||||||
| 145 | 16 | }); | |||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | 6 | return( $new ); | |||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | sub do | ||||||||||||||||||||||||||||
| 152 | 155 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
do: called CC=14 SCAR=30.6
Pod
documented
| |||||||||||||||||||||||||||||
| 153 | 155 | my( $self, $sub, @filter ) = @_; | |||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | 155 | ▶ | return( $self->error( "MM::Table->do: missing callback." ) ) if( !defined( $sub ) ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | 155 | my $cb; | |||||||||||||||||||||||||||
| 158 | 155 | ▶ | if( ref( $sub ) eq 'CODE' ) | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 159 | { | ||||||||||||||||||||||||||||
| 160 | 155 | $cb = $sub; | |||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||
| 162 | elsif( !ref( $sub ) ) | ||||||||||||||||||||||||||||
| 163 | { | ||||||||||||||||||||||||||||
| 164 | 0 | my $name = $sub; | |||||||||||||||||||||||||||
| 165 | 0 | ▶ | if( $name !~ /::/ ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 166 | { | ||||||||||||||||||||||||||||
| 167 | 0 | my $pkg = (caller())[0]; | |||||||||||||||||||||||||||
| 168 | 0 | $name = $pkg . '::' . $name; | |||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | 10 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 172 | 0 | my $code = *{$name}{CODE}; | |||||||||||||||||||||||||||
| 173 | 0 | ▶ | return( $self->error( "MM::Table->do: could not resolve callback '$sub'." ) ) if( !$code ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 174 | 0 | $cb = $code; | |||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||
| 176 | else | ||||||||||||||||||||||||||||
| 177 | { | ||||||||||||||||||||||||||||
| 178 | 0 | return( $self->error( "MM::Table->do: callback must be a CODE reference or a sub name." ) ); | |||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||
| 181 | 155 | my %filter; | |||||||||||||||||||||||||||
| 182 | 155 | ▶ | if( scalar( @filter ) ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 183 | { | ||||||||||||||||||||||||||||
| 184 | 1 | ▶ | for( my $i = 0; $i < scalar( @filter ); $i++ ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 185 | { | ||||||||||||||||||||||||||||
| 186 | 2 | my $k = $filter[ $i ]; | |||||||||||||||||||||||||||
| 187 | 2 | ▶ | next if( !defined( $k ) ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 188 | 2 | $filter{ lc( "$k" ) } = 1; | |||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||
| 192 | 155 | ▶ | my $src = $self->_state()->{_entries} || []; | ||||||||||||||||||||||||||
|
Condition50%1/2
$self->_state->{'_entries'} || []
MC/DC0%0/1
$self->_state->{'_entries'} || []
$self->_state->{'_entries'}
Truth table50%1/2
A
A= $self->_state->{'_entries'}
| |||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||
| 194 | 155 | ▶ | for( my $i = 0; $i < scalar( @$src ); $i++ ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 195 | { | ||||||||||||||||||||||||||||
| 196 | 759 | my $e = $src->[ $i ]; | |||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||
| 198 | 759 | ▶ | if( scalar( %filter ) ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 199 | { | ||||||||||||||||||||||||||||
| 200 | 4 | ▶ | next if( !$filter{ $e->{lkey} } ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||
| 203 | 758 | my $ok = $cb->( $e->{key}, $e->{val} ); | |||||||||||||||||||||||||||
| 204 | 758 | ▶ | last if( !$ok ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||
| 207 | 155 | return( $self ); | |||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||
| 210 | # error( [$message] ) | ||||||||||||||||||||||||||||
| 211 | # With an argument : creates a Mail::Make::Exception, stores it in the | ||||||||||||||||||||||||||||
| 212 | # instance, and returns undef (or empty list). | ||||||||||||||||||||||||||||
| 213 | # Without argument : returns the stored exception object, or undef. | ||||||||||||||||||||||||||||
| 214 | sub error | ||||||||||||||||||||||||||||
| 215 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
error: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 216 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||
| 217 | 0 | my $st = $self->_state(); | |||||||||||||||||||||||||||
| 218 | 0 | ▶ | if( @_ ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 219 | { | ||||||||||||||||||||||||||||
| 220 | 0 | my $msg = join( '', @_ ); | |||||||||||||||||||||||||||
| 221 | 0 | my $o = Mail::Make::Exception->new( $msg ); | |||||||||||||||||||||||||||
| 222 | 0 | $st->{_error} = $o; | |||||||||||||||||||||||||||
| 223 | 0 | ▶ | warn( $o->as_string ) if( warnings::enabled( scalar( caller ) ) ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 224 | 0 | return; | |||||||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||||||||
| 226 | 0 | return( $st->{_error} ); | |||||||||||||||||||||||||||
| 227 | } | ||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||
| 229 | sub get | ||||||||||||||||||||||||||||
| 230 | 1082 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
get: called CC=8 SCAR=20.8
Pod
documented
| |||||||||||||||||||||||||||||
| 231 | 1082 | my( $self, $key ) = @_; | |||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||
| 233 | 1082 | ▶ | $self->_validate_key( $key ) || return( $self->pass_error ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 234 | 1082 | my $lkey = lc( $key ); | |||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||
| 236 | 1082 | ▶ | my $src = $self->_state()->{_entries} || []; | ||||||||||||||||||||||||||
|
Condition50%1/2
$self->_state->{'_entries'} || []
MC/DC0%0/1
$self->_state->{'_entries'} || []
$self->_state->{'_entries'}
Truth table50%1/2
A
A= $self->_state->{'_entries'}
| |||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||
| 238 | 1082 | ▶ | if( wantarray ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 239 | { | ||||||||||||||||||||||||||||
| 240 | 993 | my @vals; | |||||||||||||||||||||||||||
| 241 | 993 | ▶ | for( my $i = 0; $i < scalar( @$src ); $i++ ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 242 | { | ||||||||||||||||||||||||||||
| 243 | 3869 | my $e = $src->[ $i ]; | |||||||||||||||||||||||||||
| 244 | 3869 | ▶ | next if( $e->{lkey} ne $lkey ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 245 | 304 | push( @vals, $e->{val} ); | |||||||||||||||||||||||||||
| 246 | } | ||||||||||||||||||||||||||||
| 247 | 993 | return( @vals ); | |||||||||||||||||||||||||||
| 248 | } | ||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||
| 250 | 89 | ▶ | for( my $i = 0; $i < scalar( @$src ); $i++ ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 251 | { | ||||||||||||||||||||||||||||
| 252 | 334 | my $e = $src->[ $i ]; | |||||||||||||||||||||||||||
| 253 | 334 | ▶ | next if( $e->{lkey} ne $lkey ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 254 | 19 | return( $e->{val} ); | |||||||||||||||||||||||||||
| 255 | } | ||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||
| 257 | 70 | return; | |||||||||||||||||||||||||||
| 258 | } | ||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||
| 260 | sub merge | ||||||||||||||||||||||||||||
| 261 | 5 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
merge: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||
| 262 | 5 | my( $self, $key, $val ) = @_; | |||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||
| 264 | 5 | ▶ | $self->_validate_key( $key ) || return( $self->pass_error ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 265 | 5 | $val = $self->_stringify_value( $val ); | |||||||||||||||||||||||||||
| 266 | 5 | my $lkey = lc( $key ); | |||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||
| 268 | 5 | my $st = $self->_state(); | |||||||||||||||||||||||||||
| 269 | 5 | ▶ | my $src = $st->{_entries} || []; | ||||||||||||||||||||||||||
|
Condition50%1/2
$st->{'_entries'} || []
MC/DC0%0/1
$st->{'_entries'} || []
$st->{'_entries'}
Truth table50%1/2
A
A= $st->{'_entries'}
| |||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||
| 271 | 5 | ▶ | for( my $i = 0; $i < scalar( @$src ); $i++ ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 272 | { | ||||||||||||||||||||||||||||
| 273 | 5 | my $e = $src->[ $i ]; | |||||||||||||||||||||||||||
| 274 | 5 | ▶ | next if( $e->{lkey} ne $lkey ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||
| 276 | 3 | $e->{val} = $e->{val} . ', ' . $val; | |||||||||||||||||||||||||||
| 277 | 3 | $self->_invalidate_tie_cache(); | |||||||||||||||||||||||||||
| 278 | 3 | return( $self ); | |||||||||||||||||||||||||||
| 279 | } | ||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||
| 281 | 2 | push( @$src, { key => $key, lkey => $lkey, val => $val } ); | |||||||||||||||||||||||||||
| 282 | 2 | $self->_invalidate_tie_cache(); | |||||||||||||||||||||||||||
| 283 | 2 | return( $self ); | |||||||||||||||||||||||||||
| 284 | } | ||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||
| 286 | sub overlap | ||||||||||||||||||||||||||||
| 287 | 2 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
overlap: called CC=9 SCAR=22.9
Pod
documented
| |||||||||||||||||||||||||||||
| 288 | 2 | my( $self, $other, $flags ) = @_; | |||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||
| 290 | 2 | ▶ | $self->_validate_table( $other ) || return( $self->pass_error ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 291 | 2 | ▶ | $self->_validate_overlap_flags( $flags ) || return( $self->pass_error ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 292 | 2 | ▶ | $flags //= 0; | ||||||||||||||||||||||||||
|
Condition50%1/2
$flags //= 0
MC/DC0%0/1
$flags //= 0
$flags
Truth table50%1/2
A
A= $flags
| |||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||
| 294 | 2 | ▶ | my $o = $other->_state()->{_entries} || []; | ||||||||||||||||||||||||||
|
Condition50%1/2
$other->_state->{'_entries'} || []
MC/DC0%0/1
$other->_state->{'_entries'} || []
$other->_state->{'_entries'}
Truth table50%1/2
A
A= $other->_state->{'_entries'}
| |||||||||||||||||||||||||||||
| 295 | 2 | ▶ | for( my $i = 0; $i < scalar( @$o ); $i++ ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 296 | { | ||||||||||||||||||||||||||||
| 297 | 3 | my $e = $o->[ $i ]; | |||||||||||||||||||||||||||
| 298 | 3 | ▶ | if( $flags ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 299 | { | ||||||||||||||||||||||||||||
| 300 | 2 | ▶ | $self->merge( $e->{key}, $e->{val} ) || return( $self->pass_error ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 301 | } | ||||||||||||||||||||||||||||
| 302 | else | ||||||||||||||||||||||||||||
| 303 | { | ||||||||||||||||||||||||||||
| 304 | 1 | ▶ | $self->set( $e->{key}, $e->{val} ) || return( $self->pass_error ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 305 | } | ||||||||||||||||||||||||||||
| 306 | } | ||||||||||||||||||||||||||||
| 307 | 2 | return( $self ); | |||||||||||||||||||||||||||
| 308 | } | ||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||
| 310 | sub overlay | ||||||||||||||||||||||||||||
| 311 | 1 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
overlay: called CC=7 SCAR=19.8
Pod
documented
| |||||||||||||||||||||||||||||
| 312 | 1 | my( $self, $other ) = @_; | |||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||
| 314 | 1 | ▶ | $self->_validate_table( $other ) || return( $self->pass_error ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||
| 316 | 1 | ▶ | my $class = ref( $self ) || $self; | ||||||||||||||||||||||||||
|
Condition33%1/3
ref $self || $self
MC/DC0%0/2
ref $self || $self
ref $self
$self
Truth table33%1/3
A || B
A= ref $selfB= $self
| |||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||
| 318 | 1 | my $state = | |||||||||||||||||||||||||||
| 319 | { | ||||||||||||||||||||||||||||
| 320 | _entries => [], | ||||||||||||||||||||||||||||
| 321 | _error => undef, | ||||||||||||||||||||||||||||
| 322 | _tied_href => undef, | ||||||||||||||||||||||||||||
| 323 | }; | ||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||
| 325 | 1 | my $new = bless( \$state, $class ); | |||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||
| 327 | 1 | my $dst = $new->_state()->{_entries}; | |||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||
| 329 | 1 | ▶ | my $o = $other->_state()->{_entries} || []; | ||||||||||||||||||||||||||
|
Condition50%1/2
$other->_state->{'_entries'} || []
MC/DC0%0/1
$other->_state->{'_entries'} || []
$other->_state->{'_entries'}
Truth table50%1/2
A
A= $other->_state->{'_entries'}
| |||||||||||||||||||||||||||||
| 330 | 1 | ▶ | for( my $i = 0; $i < scalar( @$o ); $i++ ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 331 | { | ||||||||||||||||||||||||||||
| 332 | 1 | my $e = $o->[ $i ]; | |||||||||||||||||||||||||||
| 333 | 1 | push( @$dst, { key => $e->{key}, lkey => $e->{lkey}, val => $e->{val} } ); | |||||||||||||||||||||||||||
| 334 | } | ||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||
| 336 | 1 | ▶ | my $s = $self->_state()->{_entries} || []; | ||||||||||||||||||||||||||
|
Condition50%1/2
$self->_state->{'_entries'} || []
MC/DC0%0/1
$self->_state->{'_entries'} || []
$self->_state->{'_entries'}
Truth table50%1/2
A
A= $self->_state->{'_entries'}
| |||||||||||||||||||||||||||||
| 337 | 1 | ▶ | for( my $i = 0; $i < scalar( @$s ); $i++ ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 338 | { | ||||||||||||||||||||||||||||
| 339 | 3 | my $e = $s->[$i]; | |||||||||||||||||||||||||||
| 340 | 3 | push( @$dst, { key => $e->{key}, lkey => $e->{lkey}, val => $e->{val} } ); | |||||||||||||||||||||||||||
| 341 | } | ||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||
| 343 | 1 | return( $new ); | |||||||||||||||||||||||||||
| 344 | } | ||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||
| 346 | # pass_error() | ||||||||||||||||||||||||||||
| 347 | # Propagates the error stored in this instance: sets it as the current | ||||||||||||||||||||||||||||
| 348 | # error and returns undef (or empty list), exactly as error() does, but | ||||||||||||||||||||||||||||
| 349 | # without creating a new exception object. | ||||||||||||||||||||||||||||
| 350 | sub pass_error | ||||||||||||||||||||||||||||
| 351 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
pass_error: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 352 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||
| 353 | # If called with arguments, delegate to error() to create a new exception. | ||||||||||||||||||||||||||||
| 354 | 0 | ▶ | return( $self->error( @_ ) ) if( @_ ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 355 | # No arguments: the error is already stored in the instance by the method | ||||||||||||||||||||||||||||
| 356 | # that failed. We simply return, letting Perl resolve the context: undef | ||||||||||||||||||||||||||||
| 357 | # in scalar context, empty list in list context. | ||||||||||||||||||||||||||||
| 358 | 0 | return; | |||||||||||||||||||||||||||
| 359 | } | ||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||
| 361 | sub set | ||||||||||||||||||||||||||||
| 362 | 21 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
set: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||
| 363 | 21 | my( $self, $key, $val ) = @_; | |||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||
| 365 | 21 | ▶ | $self->_validate_key( $key ) || return( $self->pass_error ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 366 | 21 | $val = $self->_stringify_value( $val ); | |||||||||||||||||||||||||||
| 367 | 21 | my $lkey = lc( $key ); | |||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||
| 369 | 21 | my $st = $self->_state(); | |||||||||||||||||||||||||||
| 370 | 21 | ▶ | my $src = $st->{_entries} || []; | ||||||||||||||||||||||||||
|
Condition50%1/2
$st->{'_entries'} || []
MC/DC0%0/1
$st->{'_entries'} || []
$st->{'_entries'}
Truth table50%1/2
A
A= $st->{'_entries'}
| |||||||||||||||||||||||||||||
| 371 | 21 | my @kept; | |||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||
| 373 | 21 | ▶ | for( my $i = 0; $i < scalar( @$src ); $i++ ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 374 | { | ||||||||||||||||||||||||||||
| 375 | 11 | my $e = $src->[ $i ]; | |||||||||||||||||||||||||||
| 376 | 11 | ▶ | next if( $e->{lkey} eq $lkey ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 377 | 9 | push( @kept, $e ); | |||||||||||||||||||||||||||
| 378 | } | ||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||
| 380 | 21 | push( @kept, { key => $key, lkey => $lkey, val => $val } ); | |||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||
| 382 | 21 | $st->{_entries} = \@kept; | |||||||||||||||||||||||||||
| 383 | 21 | $self->_invalidate_tie_cache(); | |||||||||||||||||||||||||||
| 384 | 21 | return( $self ); | |||||||||||||||||||||||||||
| 385 | } | ||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||
| 387 | sub unset | ||||||||||||||||||||||||||||
| 388 | 686 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
unset: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||
| 389 | 686 | my( $self, $key ) = @_; | |||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||
| 391 | 686 | ▶ | $self->_validate_key( $key ) || return( $self->pass_error ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 392 | 686 | my $lkey = lc( $key ); | |||||||||||||||||||||||||||
| 393 | |||||||||||||||||||||||||||||
| 394 | 686 | my $st = $self->_state(); | |||||||||||||||||||||||||||
| 395 | 686 | ▶ | my $src = $st->{_entries} || []; | ||||||||||||||||||||||||||
|
Condition50%1/2
$st->{'_entries'} || []
MC/DC0%0/1
$st->{'_entries'} || []
$st->{'_entries'}
Truth table50%1/2
A
A= $st->{'_entries'}
| |||||||||||||||||||||||||||||
| 396 | 686 | my @kept; | |||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||
| 398 | 686 | ▶ | for( my $i = 0; $i < scalar( @$src ); $i++ ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 399 | { | ||||||||||||||||||||||||||||
| 400 | 850 | my $e = $src->[ $i ]; | |||||||||||||||||||||||||||
| 401 | 850 | ▶ | next if( $e->{lkey} eq $lkey ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 402 | 827 | push( @kept, $e ); | |||||||||||||||||||||||||||
| 403 | } | ||||||||||||||||||||||||||||
| 404 | |||||||||||||||||||||||||||||
| 405 | 686 | $st->{_entries} = \@kept; | |||||||||||||||||||||||||||
| 406 | 686 | $self->_invalidate_tie_cache(); | |||||||||||||||||||||||||||
| 407 | 686 | return( $self ); | |||||||||||||||||||||||||||
| 408 | } | ||||||||||||||||||||||||||||
| 409 | |||||||||||||||||||||||||||||
| 410 | # NOTE: tied-hash like APR::Table | ||||||||||||||||||||||||||||
| 411 | sub _as_hashref | ||||||||||||||||||||||||||||
| 412 | 16 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_as_hashref: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 413 | 16 | my( $self ) = @_; | |||||||||||||||||||||||||||
| 414 | |||||||||||||||||||||||||||||
| 415 | 16 | my $st = $self->_state(); | |||||||||||||||||||||||||||
| 416 | |||||||||||||||||||||||||||||
| 417 | 16 | ▶ | if( defined( $st->{_tied_href} ) ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 418 | { | ||||||||||||||||||||||||||||
| 419 | 12 | return( $st->{_tied_href} ); | |||||||||||||||||||||||||||
| 420 | } | ||||||||||||||||||||||||||||
| 421 | |||||||||||||||||||||||||||||
| 422 | 4 | my %h; | |||||||||||||||||||||||||||
| 423 | 4 | tie( %h, 'MM::Table::Tie', $self ); | |||||||||||||||||||||||||||
| 424 | |||||||||||||||||||||||||||||
| 425 | 4 | $st->{_tied_href} = \%h; | |||||||||||||||||||||||||||
| 426 | 4 | return( $st->{_tied_href} ); | |||||||||||||||||||||||||||
| 427 | } | ||||||||||||||||||||||||||||
| 428 | |||||||||||||||||||||||||||||
| 429 | sub _invalidate_tie_cache | ||||||||||||||||||||||||||||
| 430 | 1902 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_invalidate_tie_cache: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 431 | 1902 | my( $self ) = @_; | |||||||||||||||||||||||||||
| 432 | |||||||||||||||||||||||||||||
| 433 | 1902 | my $st = $self->_state(); | |||||||||||||||||||||||||||
| 434 | # Drop our own reference to the tied hash. If the caller holds a copy of | ||||||||||||||||||||||||||||
| 435 | # the \%{} deref, Perl will keep the tie alive until that reference is | ||||||||||||||||||||||||||||
| 436 | # released - untie() would warn in that case, so we leave it to Perl's | ||||||||||||||||||||||||||||
| 437 | # normal reference counting and simply clear our cached pointer so that | ||||||||||||||||||||||||||||
| 438 | # the next %{} deref creates a fresh, correctly-initialised tie. | ||||||||||||||||||||||||||||
| 439 | 1902 | $st->{_tied_href} = undef; | |||||||||||||||||||||||||||
| 440 | |||||||||||||||||||||||||||||
| 441 | 1902 | return; | |||||||||||||||||||||||||||
| 442 | } | ||||||||||||||||||||||||||||
| 443 | |||||||||||||||||||||||||||||
| 444 | sub _state | ||||||||||||||||||||||||||||
| 445 | 5089 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_state: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 446 | 5089 | my( $self ) = @_; | |||||||||||||||||||||||||||
| 447 | 5089 | return( ${$self} ); | |||||||||||||||||||||||||||
| 448 | } | ||||||||||||||||||||||||||||
| 449 | |||||||||||||||||||||||||||||
| 450 | sub _stringify_value | ||||||||||||||||||||||||||||
| 451 | 1209 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_stringify_value: called CC=2 SCAR=7.2
| |||||||||||||||||||||||||||||
| 452 | 1209 | my( $self, $val ) = @_; | |||||||||||||||||||||||||||
| 453 | 1209 | ▶ | return( defined( $val ) ? "$val" : '' ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 454 | } | ||||||||||||||||||||||||||||
| 455 | |||||||||||||||||||||||||||||
| 456 | sub _validate_key | ||||||||||||||||||||||||||||
| 457 | 2977 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_validate_key: called CC=3 SCAR=13.3
| |||||||||||||||||||||||||||||
| 458 | 2977 | my( $self, $key ) = @_; | |||||||||||||||||||||||||||
| 459 | 2977 | ▶ | if( !defined( $key ) || ref( $key ) ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not defined $key or ref $key
MC/DC0%0/2
not defined $key or ref $key
not defined $key
ref $key
Truth table33%1/3
not(A) or B
A= not defined $keyB= ref $key
| |||||||||||||||||||||||||||||
| 460 | { | ||||||||||||||||||||||||||||
| 461 | 0 | return( $self->error( "MM::Table: key must be a defined non-reference scalar." ) ); | |||||||||||||||||||||||||||
| 462 | } | ||||||||||||||||||||||||||||
| 463 | 2977 | return(1); | |||||||||||||||||||||||||||
| 464 | } | ||||||||||||||||||||||||||||
| 465 | |||||||||||||||||||||||||||||
| 466 | sub _validate_overlap_flags | ||||||||||||||||||||||||||||
| 467 | 4 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_validate_overlap_flags: called CC=6 SCAR=19.4
| |||||||||||||||||||||||||||||
| 468 | 4 | my( $self, $flags, $method ) = @_; | |||||||||||||||||||||||||||
| 469 | 4 | ▶ | $method ||= 'method'; | ||||||||||||||||||||||||||
|
Condition100%2/2
$method ||= "method"
MC/DC100%1/1
$method ||= "method"
$method
Truth table100%2/2
A
A= $method
| |||||||||||||||||||||||||||||
| 470 | 4 | ▶ | return(1) if( !defined( $flags ) ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 471 | |||||||||||||||||||||||||||||
| 472 | 4 | ▶ | if( $flags !~ /^\d+\z/ ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 473 | { | ||||||||||||||||||||||||||||
| 474 | 0 | return( $self->error( "MM::Table->$method: invalid flags '$flags' (expected 0 or 1)." ) ); | |||||||||||||||||||||||||||
| 475 | } | ||||||||||||||||||||||||||||
| 476 | |||||||||||||||||||||||||||||
| 477 | 4 | $flags = int( $flags ); | |||||||||||||||||||||||||||
| 478 | 4 | ▶ | if( $flags != 0 && $flags != 1 ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$flags != 0 and $flags != 1
MC/DC0%0/2
$flags != 0 and $flags != 1
$flags != 0
$flags != 1
Truth table66%2/3
A and B
A= $flags != 0B= $flags != 1
| |||||||||||||||||||||||||||||
| 479 | { | ||||||||||||||||||||||||||||
| 480 | 0 | return( $self->error( "MM::Table->$method: invalid flags '$flags' (expected 0 or 1)." ) ); | |||||||||||||||||||||||||||
| 481 | } | ||||||||||||||||||||||||||||
| 482 | |||||||||||||||||||||||||||||
| 483 | 4 | return(1); | |||||||||||||||||||||||||||
| 484 | } | ||||||||||||||||||||||||||||
| 485 | |||||||||||||||||||||||||||||
| 486 | sub _validate_table | ||||||||||||||||||||||||||||
| 487 | 3 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_validate_table: called CC=4 SCAR=18.9
| |||||||||||||||||||||||||||||
| 488 | 3 | my( $self, $other ) = @_; | |||||||||||||||||||||||||||
| 489 | 3 | ▶ | if( !blessed( $other ) || !$other->isa( 'MM::Table' ) ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
builtin::blessed($other) and $other->isa("MM::Table")
MC/DC0%0/2
builtin::blessed($other) and $other->isa("MM::Table")
builtin::blessed($other)
$other->isa("MM::Table")
Truth table33%1/3
A and B
A= builtin::blessed($other)B= $other->isa("MM::Table")
| |||||||||||||||||||||||||||||
| 490 | { | ||||||||||||||||||||||||||||
| 491 | 0 | ▶ | return( $self->error( "MM::Table: expected an MM::Table object, got '" . ( ref( $other ) || 'undef' ) . "'." ) ); | ||||||||||||||||||||||||||
|
Condition0%0/2
ref $other || 'undef'
MC/DC0%0/1
ref $other || 'undef'
ref $other
Truth table0%0/2
A
A= ref $other
| |||||||||||||||||||||||||||||
| 492 | } | ||||||||||||||||||||||||||||
| 493 | 3 | return(1); | |||||||||||||||||||||||||||
| 494 | } | ||||||||||||||||||||||||||||
| 495 | |||||||||||||||||||||||||||||
| 496 | 10 | 1; | |||||||||||||||||||||||||||
| 497 | # NOTE: package MM::Table::Tie | ||||||||||||||||||||||||||||
| 498 | package MM::Table::Tie; | ||||||||||||||||||||||||||||
| 499 | |||||||||||||||||||||||||||||
| 500 | 10 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 501 | 10 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 502 | |||||||||||||||||||||||||||||
| 503 | sub TIEHASH | ||||||||||||||||||||||||||||
| 504 | 4 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
TIEHASH: called CC=4 SCAR=18.9
| |||||||||||||||||||||||||||||
| 505 | 4 | my( $class, $table ) = @_; | |||||||||||||||||||||||||||
| 506 | # This is a programming error, not a runtime one - die is appropriate here. | ||||||||||||||||||||||||||||
| 507 | 4 | ▶ | unless( defined( $table ) && ref( $table ) eq 'MM::Table' ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $table and ref $table eq "MM::Table"
MC/DC0%0/2
defined $table and ref $table eq "MM::Table"
defined $table
ref $table eq "MM::Table"
Truth table33%1/3
A and B
A= defined $tableB= ref $table eq "MM::Table"
| |||||||||||||||||||||||||||||
| 508 | { | ||||||||||||||||||||||||||||
| 509 | 0 | ▶ | die( "MM::Table::Tie: expected an MM::Table instance, got '" . ( ref( $table ) || 'undef' ) . "'.\n" ); | ||||||||||||||||||||||||||
|
Condition0%0/2
ref $table || 'undef'
MC/DC0%0/1
ref $table || 'undef'
ref $table
Truth table0%0/2
A
A= ref $table
| |||||||||||||||||||||||||||||
| 510 | } | ||||||||||||||||||||||||||||
| 511 | |||||||||||||||||||||||||||||
| 512 | 4 | return( bless( | |||||||||||||||||||||||||||
| 513 | { | ||||||||||||||||||||||||||||
| 514 | _table => $table, | ||||||||||||||||||||||||||||
| 515 | _iter => 0, | ||||||||||||||||||||||||||||
| 516 | _curr => undef, | ||||||||||||||||||||||||||||
| 517 | }, $class ) ); | ||||||||||||||||||||||||||||
| 518 | } | ||||||||||||||||||||||||||||
| 519 | |||||||||||||||||||||||||||||
| 520 | sub CLEAR | ||||||||||||||||||||||||||||
| 521 | 1 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
CLEAR: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 522 | 1 | my( $self ) = @_; | |||||||||||||||||||||||||||
| 523 | 1 | $self->{_table}->clear(); | |||||||||||||||||||||||||||
| 524 | 1 | return; | |||||||||||||||||||||||||||
| 525 | } | ||||||||||||||||||||||||||||
| 526 | |||||||||||||||||||||||||||||
| 527 | sub DELETE | ||||||||||||||||||||||||||||
| 528 | 1 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
DELETE: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 529 | 1 | my( $self, $key ) = @_; | |||||||||||||||||||||||||||
| 530 | 1 | $self->{_table}->unset( $key ); | |||||||||||||||||||||||||||
| 531 | 1 | return; | |||||||||||||||||||||||||||
| 532 | } | ||||||||||||||||||||||||||||
| 533 | |||||||||||||||||||||||||||||
| 534 | sub DESTROY | ||||||||||||||||||||||||||||
| 535 | 4 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
DESTROY: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 536 | 4 | my( $self ) = @_; | |||||||||||||||||||||||||||
| 537 | 4 | return; | |||||||||||||||||||||||||||
| 538 | } | ||||||||||||||||||||||||||||
| 539 | |||||||||||||||||||||||||||||
| 540 | sub EXISTS | ||||||||||||||||||||||||||||
| 541 | 3 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
EXISTS: called CC=6 SCAR=18.5
| |||||||||||||||||||||||||||||
| 542 | 3 | my( $self, $key ) = @_; | |||||||||||||||||||||||||||
| 543 | |||||||||||||||||||||||||||||
| 544 | 3 | ▶ | return(0) unless( defined( $key ) && !ref( $key ) ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $key and not ref $key
MC/DC0%0/2
defined $key and not ref $key
defined $key
not ref $key
Truth table33%1/3
A and not(B)
A= defined $keyB= not ref $key
| |||||||||||||||||||||||||||||
| 545 | 3 | my $lkey = lc( $key ); | |||||||||||||||||||||||||||
| 546 | |||||||||||||||||||||||||||||
| 547 | 3 | ▶ | my $src = $self->{_table}->_state()->{_entries} || []; | ||||||||||||||||||||||||||
|
Condition50%1/2
$self->{'_table'}->_state->{'_entries'} || []
MC/DC0%0/1
$self->{'_table'}->_state->{'_entries'} || []
$self->{'_table'}->_state->{'_entries'}
Truth table50%1/2
A
A= $self->{'_table'}->_state->{'_entries'}
| |||||||||||||||||||||||||||||
| 548 | 3 | ▶ | for( my $i = 0; $i < scalar( @$src ); $i++ ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 549 | { | ||||||||||||||||||||||||||||
| 550 | 4 | my $e = $src->[$i]; | |||||||||||||||||||||||||||
| 551 | 4 | ▶ | return(1) if( $e->{lkey} eq $lkey ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 552 | } | ||||||||||||||||||||||||||||
| 553 | |||||||||||||||||||||||||||||
| 554 | 1 | return(0); | |||||||||||||||||||||||||||
| 555 | } | ||||||||||||||||||||||||||||
| 556 | |||||||||||||||||||||||||||||
| 557 | sub FETCH | ||||||||||||||||||||||||||||
| 558 | 8 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
FETCH: called CC=10 SCAR=25.1
| |||||||||||||||||||||||||||||
| 559 | 8 | my( $self, $key ) = @_; | |||||||||||||||||||||||||||
| 560 | |||||||||||||||||||||||||||||
| 561 | 8 | ▶ | return( undef ) unless( defined( $key ) && !ref( $key ) ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $key and not ref $key
MC/DC0%0/2
defined $key and not ref $key
defined $key
not ref $key
Truth table33%1/3
A and not(B)
A= defined $keyB= not ref $key
| |||||||||||||||||||||||||||||
| 562 | 8 | my $lkey = lc( $key ); | |||||||||||||||||||||||||||
| 563 | |||||||||||||||||||||||||||||
| 564 | 8 | my $t = $self->{_table}; | |||||||||||||||||||||||||||
| 565 | 8 | ▶ | my $src = $t->_state()->{_entries} || []; | ||||||||||||||||||||||||||
|
Condition50%1/2
$t->_state->{'_entries'} || []
MC/DC0%0/1
$t->_state->{'_entries'} || []
$t->_state->{'_entries'}
Truth table50%1/2
A
A= $t->_state->{'_entries'}
| |||||||||||||||||||||||||||||
| 566 | |||||||||||||||||||||||||||||
| 567 | # Fast path: if the iterator is currently positioned on this key, we can | ||||||||||||||||||||||||||||
| 568 | # return its value without a full scan. This is safe because _curr is only | ||||||||||||||||||||||||||||
| 569 | # set by NEXTKEY, which always runs against the live _entries array, and | ||||||||||||||||||||||||||||
| 570 | # FIRSTKEY resets it to undef before any iteration begins. | ||||||||||||||||||||||||||||
| 571 | 8 | ▶ | if( defined( $self->{_curr} ) ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 572 | { | ||||||||||||||||||||||||||||
| 573 | 6 | my $idx = $self->{_curr}; | |||||||||||||||||||||||||||
| 574 | 6 | ▶ | if( $idx >= 0 && $idx < scalar( @$src ) ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$idx >= 0 and $idx < scalar @$src
MC/DC0%0/2
$idx >= 0 and $idx < scalar @$src
$idx >= 0
$idx < scalar @$src
Truth table33%1/3
A and B
A= $idx >= 0B= $idx < scalar @$src
| |||||||||||||||||||||||||||||
| 575 | { | ||||||||||||||||||||||||||||
| 576 | 6 | my $e = $src->[$idx]; | |||||||||||||||||||||||||||
| 577 | 6 | ▶ | return( $e->{val} ) if( $e->{lkey} eq $lkey ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 578 | } | ||||||||||||||||||||||||||||
| 579 | } | ||||||||||||||||||||||||||||
| 580 | |||||||||||||||||||||||||||||
| 581 | 3 | ▶ | for( my $i = 0; $i < scalar( @$src ); $i++ ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 582 | { | ||||||||||||||||||||||||||||
| 583 | 3 | my $e = $src->[$i]; | |||||||||||||||||||||||||||
| 584 | 3 | ▶ | next if( $e->{lkey} ne $lkey ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 585 | 3 | return( $e->{val} ); | |||||||||||||||||||||||||||
| 586 | } | ||||||||||||||||||||||||||||
| 587 | |||||||||||||||||||||||||||||
| 588 | 0 | return( undef ); | |||||||||||||||||||||||||||
| 589 | } | ||||||||||||||||||||||||||||
| 590 | |||||||||||||||||||||||||||||
| 591 | sub FIRSTKEY | ||||||||||||||||||||||||||||
| 592 | 1 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
FIRSTKEY: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 593 | 1 | my( $self ) = @_; | |||||||||||||||||||||||||||
| 594 | 1 | $self->{_iter} = 0; | |||||||||||||||||||||||||||
| 595 | 1 | $self->{_curr} = undef; | |||||||||||||||||||||||||||
| 596 | 1 | return( $self->NEXTKEY( undef ) ); | |||||||||||||||||||||||||||
| 597 | } | ||||||||||||||||||||||||||||
| 598 | |||||||||||||||||||||||||||||
| 599 | sub NEXTKEY | ||||||||||||||||||||||||||||
| 600 | 4 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
NEXTKEY: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 601 | 4 | my( $self, $lastkey ) = @_; | |||||||||||||||||||||||||||
| 602 | |||||||||||||||||||||||||||||
| 603 | 4 | ▶ | my $src = $self->{_table}->_state()->{_entries} || []; | ||||||||||||||||||||||||||
|
Condition50%1/2
$self->{'_table'}->_state->{'_entries'} || []
MC/DC0%0/1
$self->{'_table'}->_state->{'_entries'} || []
$self->{'_table'}->_state->{'_entries'}
Truth table50%1/2
A
A= $self->{'_table'}->_state->{'_entries'}
| |||||||||||||||||||||||||||||
| 604 | |||||||||||||||||||||||||||||
| 605 | 4 | ▶ | if( $self->{_iter} >= scalar( @$src ) ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 606 | { | ||||||||||||||||||||||||||||
| 607 | 1 | $self->{_curr} = undef; | |||||||||||||||||||||||||||
| 608 | 1 | return( undef ); | |||||||||||||||||||||||||||
| 609 | } | ||||||||||||||||||||||||||||
| 610 | |||||||||||||||||||||||||||||
| 611 | 3 | my $idx = $self->{_iter}; | |||||||||||||||||||||||||||
| 612 | 3 | $self->{_iter}++; | |||||||||||||||||||||||||||
| 613 | 3 | $self->{_curr} = $idx; | |||||||||||||||||||||||||||
| 614 | |||||||||||||||||||||||||||||
| 615 | 3 | return( $src->[$idx]->{key} ); | |||||||||||||||||||||||||||
| 616 | } | ||||||||||||||||||||||||||||
| 617 | |||||||||||||||||||||||||||||
| 618 | sub STORE | ||||||||||||||||||||||||||||
| 619 | 2 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
STORE: called CC=3 SCAR=12.0
| |||||||||||||||||||||||||||||
| 620 | 2 | my( $self, $key, $val ) = @_; | |||||||||||||||||||||||||||
| 621 | 2 | ▶ | return unless( defined( $key ) && !ref( $key ) ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $key and not ref $key
MC/DC0%0/2
defined $key and not ref $key
defined $key
not ref $key
Truth table33%1/3
A and not(B)
A= defined $keyB= not ref $key
| |||||||||||||||||||||||||||||
| 622 | 2 | $self->{_table}->set( $key, $val ); | |||||||||||||||||||||||||||
| 623 | 2 | return; | |||||||||||||||||||||||||||
| 624 | } | ||||||||||||||||||||||||||||
| 625 | |||||||||||||||||||||||||||||
| 626 | 10 | 1; | |||||||||||||||||||||||||||
| 627 | # NOTE: POD | ||||||||||||||||||||||||||||
| 628 | __END__ | ||||||||||||||||||||||||||||