| 1 | # Copyrights 2010-2018 by [Mark Overmeer]. | ||||||||||||||||||||||||||||||||
| 2 | # For other contributors see ChangeLog. | ||||||||||||||||||||||||||||||||
| 3 | # See the manual pages for details on the licensing terms. | ||||||||||||||||||||||||||||||||
| 4 | # Pod stripped from pm file by OODoc 2.02. | ||||||||||||||||||||||||||||||||
| 5 | # This code is part of distribution Tie::Nested. Meta-POD processed with | ||||||||||||||||||||||||||||||||
| 6 | # OODoc into POD and HTML manual-pages. See README.md | ||||||||||||||||||||||||||||||||
| 7 | # Copyright Mark Overmeer. Licensed under the same terms as Perl itself. | ||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||
| 9 | package Tie::Nested; | ||||||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use vars '$VERSION'; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 11 | 2 | $VERSION = '0.11'; | |||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||
| 14 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 15 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||
| 17 | 2 | ▶ | use Log::Report 'tie-nested', syntax => 'SHORT'; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 18 | 2 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||
| 21 | sub TIEHASH(@) | ||||||||||||||||||||||||||||||||
| 22 | 11 | ▶ | { my $class = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
TIEHASH: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||
| 23 | 11 | ▶ | my $add = @_ % 2 ? shift : {}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 24 | 11 | my $self = (bless {}, $class)->init({@_} ); | |||||||||||||||||||||||||||||||
| 25 | 11 | my @a = %$add; | |||||||||||||||||||||||||||||||
| 26 | 11 | tie %$add, $self->{mine}; | |||||||||||||||||||||||||||||||
| 27 | 11 | $self->{data} = $add; | |||||||||||||||||||||||||||||||
| 28 | 11 | ▶ | $self->STORE(shift @a, shift @a) while @a; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 29 | 11 | $self; | |||||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||
| 33 | sub TIEARRAY(@) | ||||||||||||||||||||||||||||||||
| 34 | 0 | ▶ | { my $class = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
TIEARRAY: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||
| 35 | 0 | ▶ | my $add = @_ % 2 ? shift : []; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 36 | 0 | ▶ | $add = [$add] if ref $add ne 'ARRAY'; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 37 | 0 | my $self = (bless {}, $class)->init( {@_} ); | |||||||||||||||||||||||||||||||
| 38 | 0 | tie @$add, $self->{mine}; | |||||||||||||||||||||||||||||||
| 39 | 0 | $self->{data} = $add; | |||||||||||||||||||||||||||||||
| 40 | 0 | $self; | |||||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||
| 43 | sub init($) | ||||||||||||||||||||||||||||||||
| 44 | 11 | ▶ | { my ($self, $args) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
init: called CC=8 SCAR=21.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||
| 46 | 11 | my ($mine, @nest_opts); | |||||||||||||||||||||||||||||||
| 47 | 11 | ▶ | if(my $r = $args->{recurse}) | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 48 | 6 | ▶ | { $r = [ $r ] if ref $r ne 'ARRAY'; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 49 | 6 | $mine = $r->[0]; | |||||||||||||||||||||||||||||||
| 50 | 6 | @nest_opts = (recurse => $r); | |||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||
| 52 | elsif(my $n = $args->{nestings}) | ||||||||||||||||||||||||||||||||
| 53 | 5 | ▶ | { ($mine, my @nest) = ref $n eq 'ARRAY' ? @$n : $n; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 54 | 5 | ▶ | @nest_opts = (nestings => \@nest) if @nest; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||
| 56 | else | ||||||||||||||||||||||||||||||||
| 57 | 0 | { error __x"tie needs either 'recurse' or 'nestings' parameter"; | |||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||
| 60 | 11 | ▶ | defined $mine | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 61 | or error __x"requires a package name for the tie on the data"; | ||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||
| 63 | 11 | $self->{mine} = $mine; | |||||||||||||||||||||||||||||||
| 64 | 11 | ▶ | $self->{nest} = \@nest_opts if @nest_opts; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 65 | 11 | $self; | |||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||
| 68 | sub STORE($$$) | ||||||||||||||||||||||||||||||||
| 69 | 25 | ▶ | { my ($self, $k, $v) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
STORE: called CC=7 SCAR=21.5
| |||||||||||||||||||||||||||||||||
| 70 | 25 | my $t = $self->{mine}; | |||||||||||||||||||||||||||||||
| 71 | 25 | ▶ | my $d = $self->{data} ||= $t->($k, $v); | ||||||||||||||||||||||||||||||
|
Condition33%1/3
$self->{"data"} ||= &$t($k, $v)
MC/DC0%0/2
$self->{"data"} ||= &$t($k, $v)
$self->{"data"}
&$t($k, $v)
Truth table33%1/3
A ||= B
A= $self->{"data"}B= &$t($k, $v)
| |||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||
| 73 | 25 | ▶ | if(my $nest = $self->{nest}) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 74 | { | ||||||||||||||||||||||||||||||||
| 75 | 21 | ▶ | if(ref $v eq 'HASH' && $nest->[1][0]->can('TIEHASH')) | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%2/3
ref $v eq "HASH" and $nest->[1][0]->can("TIEHASH")
MC/DC50%1/2
ref $v eq "HASH" and $nest->[1][0]->can("TIEHASH")
ref $v eq "HASH"
$nest->[1][0]->can("TIEHASH")
Truth table66%2/3
A and B
A= ref $v eq "HASH"B= $nest->[1][0]->can("TIEHASH")
| |||||||||||||||||||||||||||||||||
| 76 | 7 | { tie %$v, ref $self, {%$v}, @$nest; | |||||||||||||||||||||||||||||||
| 77 | 7 | return $d->{$k} = $v; | |||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||
| 79 | ▶ | elsif(ref $v eq 'ARRAY' && $nest->[1][0]->can('TIEARRAY')) | |||||||||||||||||||||||||||||||
|
Condition33%1/3
ref $v eq "ARRAY" and $nest->[1][0]->can("TIEARRAY")
MC/DC0%0/2
ref $v eq "ARRAY" and $nest->[1][0]->can("TIEARRAY")
ref $v eq "ARRAY"
$nest->[1][0]->can("TIEARRAY")
Truth table33%1/3
A and B
A= ref $v eq "ARRAY"B= $nest->[1][0]->can("TIEARRAY")
| |||||||||||||||||||||||||||||||||
| 80 | 0 | { tie @$v, ref $self, [@$v], @$nest; | |||||||||||||||||||||||||||||||
| 81 | 0 | return $d->{$k} = $v; | |||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||
| 85 | 18 | (tied %$d)->STORE($k, $v); | |||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||
| 88 | 2 | my $end; | |||||||||||||||||||||||||||||||
| 89 | 2 | ▶ | END { $end++ } | ||||||||||||||||||||||||||||||
|
Subroutine
END: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||
| 91 | 2 | our $AUTOLOAD; | |||||||||||||||||||||||||||||||
| 92 | sub AUTOLOAD(@) | ||||||||||||||||||||||||||||||||
| 93 | 191 | ▶ | { return if $end; | ||||||||||||||||||||||||||||||
|
Subroutine
AUTOLOAD: called CC=4 SCAR=14.0
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 94 | 191 | $AUTOLOAD =~ s/.*\:\://; | |||||||||||||||||||||||||||||||
| 95 | 191 | my $d = shift->{data}; | |||||||||||||||||||||||||||||||
| 96 | 191 | my $obj = tied %$d; | |||||||||||||||||||||||||||||||
| 97 | 191 | ▶ | return if $AUTOLOAD eq 'DESTROY' && ! $obj->can('DESTROY'); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$Tie::Nested::AUTOLOAD eq "DESTROY" and not $obj->can("DESTROY")
MC/DC50%1/2
$Tie::Nested::AUTOLOAD eq "DESTROY" and not $obj->can("DESTROY")
$Tie::Nested::AUTOLOAD eq "DESTROY"
not $obj->can("DESTROY")
Truth table66%2/3
A and not(B)
A= $Tie::Nested::AUTOLOAD eq "DESTROY"B= not $obj->can("DESTROY")
| |||||||||||||||||||||||||||||||||
| 98 | 180 | $obj->$AUTOLOAD(@_); | |||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||
| 101 | 2 | 1; | |||||||||||||||||||||||||||||||