| 1 | package MooX::TaggedAttributes::Cache; | ||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||
| 3 | # ABSTRACT: Extract information from a Tagged Attribute Cache | ||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||
| 5 | 8 | ▶ | use v5.10.1; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||
| 7 | 8 | ▶ | use strict; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 8 | 8 | ▶ | use warnings; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||
| 10 | 8 | our $VERSION = '0.18'; | |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||
| 12 | 8 | ▶ | use Const::Fast (); | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 13 | 8 | ▶ | use overload '%{}' => \&tag_hash, fallback => 1; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||
| 36 | 68 | ▶ | sub new { | ||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||
| 37 | 68 | my ( $class, $target ) = @_; | |||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||
| 39 | 68 | return bless { list => $target->_tag_list }, $class; | |||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||
| 71 | 54 | ▶ | sub tag_attr_hash { | ||||||||||||||||||||||||||||
|
Subroutine
tag_attr_hash: called CC=5 SCAR=16.2
Pod
documented
| |||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||
| 73 | 54 | my $self = shift; | |||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||
| 75 | 8 | ▶ | no overloading; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||
| 77 | 54 | ▶ | return $self->{tag_attr_hash} //= do { | ||||||||||||||||||||||||||||
|
Condition33%1/3
$self->{"tag_attr_hash"} //= do {
my %tags;
foreach my $tuple (@{$$self{"list"};}) {
my $tag = ($tags{$tuple->[0]} //= {});
$tag->{$_} = $tuple->[2] foreach (@{$$tuple[1];});
};
&Const::Fast::const(\my %rtags, %tags);
\%rtags
}
MC/DC0%0/2
$self->{"tag_attr_hash"} //= do {
my %tags;
foreach my $tuple (@{$$self{"list"};}) {
my $tag = ($tags{$tuple->[0]} //= {});
$tag->{$_} = $tuple->[2] foreach (@{$$tuple[1];});
};
&Const::Fast::const(\my %rtags, %tags);
\%rtags
}
$self->{"tag_attr_hash"}
do {
my %tags;
foreach my $tuple (@{$$self{"list"};}) {
my $tag = ($tags{$tuple->[0]} //= {});
$tag->{$_} = $tuple->[2] foreach (@{$$tuple[1];});
};
&Const::Fast::const(\my %rtags, %tags);
\%rtags
}
Truth table33%1/3
A //= B
A= $self->{"tag_attr_hash"}B= do {
my %tags;
foreach my $tuple (@{$$self{"list"};}) {
my $tag = ($tags{$tuple->[0]} //= {});
$tag->{$_} = $tuple->[2] foreach (@{$$tuple[1];});
};
&Const::Fast::const(\my %rtags, %tags);
\%rtags
}
| |||||||||||||||||||||||||||||||
| 78 | 54 | my %tags; | |||||||||||||||||||||||||||||
| 79 | 54 | for my $tuple ( @{ $self->{list} } ) { | |||||||||||||||||||||||||||||
| 80 | # my ( $tag, $attrs, $value ) = @$tuple; | ||||||||||||||||||||||||||||||
| 81 | 240 | ▶ | my $tag = ( $tags{ $tuple->[0] } //= {} ); | ||||||||||||||||||||||||||||
|
Condition100%2/2
$tags{$tuple->[0]} //= {}
MC/DC100%1/1
$tags{$tuple->[0]} //= {}
$tags{$tuple->[0]}
Truth table100%2/2
A
A= $tags{$tuple->[0]}
| |||||||||||||||||||||||||||||||
| 82 | 240 | $tag->{$_} = $tuple->[2] for @{ $tuple->[1] }; | |||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||
| 84 | 54 | Const::Fast::const my %rtags => %tags; | |||||||||||||||||||||||||||||
| 85 | 54 | \%rtags; | |||||||||||||||||||||||||||||
| 86 | }; | ||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||
| 88 | 8 | *tag_hash = \&tag_attr_hash; | |||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||
| 113 | 2 | ▶ | sub tag_value_hash { | ||||||||||||||||||||||||||||
|
Subroutine
tag_value_hash: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||
| 115 | 2 | my $self = shift; | |||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||
| 117 | 8 | ▶ | no overloading; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||
| 119 | 2 | ▶ | return $self->{tag_value_hash} //= do { | ||||||||||||||||||||||||||||
|
Condition33%1/3
$self->{"tag_value_hash"} //= do {
my %tags;
foreach my $tuple (@{$$self{"list"};}) {
my $tag = ($tags{$tuple->[0]} //= {});
push @{$$tag{$tuple->[2]} //= [];}, @{$tuple->[1];};
};
&Const::Fast::const(\my %rtags, %tags);
\%rtags
}
MC/DC0%0/2
$self->{"tag_value_hash"} //= do {
my %tags;
foreach my $tuple (@{$$self{"list"};}) {
my $tag = ($tags{$tuple->[0]} //= {});
push @{$$tag{$tuple->[2]} //= [];}, @{$tuple->[1];};
};
&Const::Fast::const(\my %rtags, %tags);
\%rtags
}
$self->{"tag_value_hash"}
do {
my %tags;
foreach my $tuple (@{$$self{"list"};}) {
my $tag = ($tags{$tuple->[0]} //= {});
push @{$$tag{$tuple->[2]} //= [];}, @{$tuple->[1];};
};
&Const::Fast::const(\my %rtags, %tags);
\%rtags
}
Truth table33%1/3
A //= B
A= $self->{"tag_value_hash"}B= do {
my %tags;
foreach my $tuple (@{$$self{"list"};}) {
my $tag = ($tags{$tuple->[0]} //= {});
push @{$$tag{$tuple->[2]} //= [];}, @{$tuple->[1];};
};
&Const::Fast::const(\my %rtags, %tags);
\%rtags
}
| |||||||||||||||||||||||||||||||
| 120 | 2 | my %tags; | |||||||||||||||||||||||||||||
| 121 | 2 | for my $tuple ( @{ $self->{list} } ) { | |||||||||||||||||||||||||||||
| 122 | # my ( $tag, $attrs, $value ) = @$tuple; | ||||||||||||||||||||||||||||||
| 123 | 16 | ▶ | my $tag = ( $tags{ $tuple->[0] } //= {} ); | ||||||||||||||||||||||||||||
|
Condition100%2/2
$tags{$tuple->[0]} //= {}
MC/DC100%1/1
$tags{$tuple->[0]} //= {}
$tags{$tuple->[0]}
Truth table100%2/2
A
A= $tags{$tuple->[0]}
| |||||||||||||||||||||||||||||||
| 124 | # copy so don't corrupt internal list. | ||||||||||||||||||||||||||||||
| 125 | 16 | ▶ | push @{ $tag->{ $tuple->[2] } //= [] }, @{ $tuple->[1] }; | ||||||||||||||||||||||||||||
|
Condition100%2/2
$$tag{$tuple->[2]} //= []
MC/DC100%1/1
$$tag{$tuple->[2]} //= []
$$tag{$tuple->[2]}
Truth table100%2/2
A
A= $$tag{$tuple->[2]}
| |||||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||||
| 127 | 2 | Const::Fast::const my %rtags => %tags; | |||||||||||||||||||||||||||||
| 128 | 2 | \%rtags; | |||||||||||||||||||||||||||||
| 129 | }; | ||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||
| 142 | 22 | ▶ | sub attr_hash { | ||||||||||||||||||||||||||||
|
Subroutine
attr_hash: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||
| 144 | 22 | my $self = shift; | |||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||
| 146 | 8 | ▶ | no overloading; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||
| 148 | 22 | ▶ | return $self->{attr_hash} //= do { | ||||||||||||||||||||||||||||
|
Condition66%2/3
$self->{"attr_hash"} //= do {
my %attrs;
foreach my $tuple (@{$$self{"list"};}) {
($attrs{$_} //= {})->{$tuple->[0]} = $tuple->[2] foreach (@{$$tuple[1];});
};
&Const::Fast::const(\my %rattrs, %attrs);
\%rattrs
}
MC/DC0%0/2
$self->{"attr_hash"} //= do {
my %attrs;
foreach my $tuple (@{$$self{"list"};}) {
($attrs{$_} //= {})->{$tuple->[0]} = $tuple->[2] foreach (@{$$tuple[1];});
};
&Const::Fast::const(\my %rattrs, %attrs);
\%rattrs
}
$self->{"attr_hash"}
do {
my %attrs;
foreach my $tuple (@{$$self{"list"};}) {
($attrs{$_} //= {})->{$tuple->[0]} = $tuple->[2] foreach (@{$$tuple[1];});
};
&Const::Fast::const(\my %rattrs, %attrs);
\%rattrs
}
Truth table66%2/3
A //= B
A= $self->{"attr_hash"}B= do {
my %attrs;
foreach my $tuple (@{$$self{"list"};}) {
($attrs{$_} //= {})->{$tuple->[0]} = $tuple->[2] foreach (@{$$tuple[1];});
};
&Const::Fast::const(\my %rattrs, %attrs);
\%rattrs
}
| |||||||||||||||||||||||||||||||
| 149 | 12 | my %attrs; | |||||||||||||||||||||||||||||
| 150 | 12 | for my $tuple ( @{ $self->{list} } ) { | |||||||||||||||||||||||||||||
| 151 | # my ( $tag, $attrs, $value ) = @$tuple; | ||||||||||||||||||||||||||||||
| 152 | ( $attrs{$_} //= {} )->{ $tuple->[0] } = $tuple->[2] | ||||||||||||||||||||||||||||||
| 153 | 96 | ▶ | for @{ $tuple->[1] }; | ||||||||||||||||||||||||||||
|
Condition100%2/2
$attrs{$_} //= {}
MC/DC100%1/1
$attrs{$_} //= {}
$attrs{$_}
Truth table100%2/2
A
A= $attrs{$_}
| |||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||
| 155 | 12 | Const::Fast::const my %rattrs => %attrs; | |||||||||||||||||||||||||||||
| 156 | 12 | \%rattrs; | |||||||||||||||||||||||||||||
| 157 | }; | ||||||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||
| 172 | 10 | ▶ | sub tags { | ||||||||||||||||||||||||||||
|
Subroutine
tags: called CC=6 SCAR=18.7
Pod
documented
| |||||||||||||||||||||||||||||||
| 173 | 10 | my ( $self, $attr ) = @_; | |||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||
| 175 | 8 | ▶ | no overloading; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||
| 177 | 10 | ▶ | if ( !defined $attr ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 178 | 2 | ▶ | return $self->{tags} //= do { | ||||||||||||||||||||||||||||
|
Condition33%1/3
$self->{"tags"} //= do {
&Const::Fast::const(\my @tags, keys %{$self->tag_hash;});
\@tags
}
MC/DC0%0/2
$self->{"tags"} //= do {
&Const::Fast::const(\my @tags, keys %{$self->tag_hash;});
\@tags
}
$self->{"tags"}
do {
&Const::Fast::const(\my @tags, keys %{$self->tag_hash;});
\@tags
}
Truth table33%1/3
A //= B
A= $self->{"tags"}B= do {
&Const::Fast::const(\my @tags, keys %{$self->tag_hash;});
\@tags
}
| |||||||||||||||||||||||||||||||
| 179 | 2 | Const::Fast::const my @tags => keys %{ $self->tag_hash }; | |||||||||||||||||||||||||||||
| 180 | 2 | \@tags; | |||||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||
| 184 | 8 | ▶ | return ( $self->{attr} //= {} )->{$attr} //= do { | ||||||||||||||||||||||||||||
|
Condition40%2/5
+($self->{"attr"} //= {})->{$attr} //= do {
my $attrs = $self->attr_hash;
[keys %{$attrs->{$attr} // {};}]
}
$self->{"attr"} //= {}
MC/DC0%0/2
+($self->{"attr"} //= {})->{$attr} //= do {
my $attrs = $self->attr_hash;
[keys %{$attrs->{$attr} // {};}]
}
+($self->{"attr"} //= {})->{$attr}
do {
my $attrs = $self->attr_hash;
[keys %{$attrs->{$attr} // {};}]
}
MC/DC0%0/1
$self->{"attr"} //= {}
$self->{"attr"}
Truth table33%1/3
A //= B
A= +($self->{"attr"} //= {})->{$attr}B= do {
my $attrs = $self->attr_hash;
[keys %{$attrs->{$attr} // {};}]
}
Truth table50%1/2
A
A= $self->{"attr"}
| |||||||||||||||||||||||||||||||
| 185 | 8 | my $attrs = $self->attr_hash; | |||||||||||||||||||||||||||||
| 186 | 8 | ▶ | [ keys %{ $attrs->{$attr} // {} } ]; | ||||||||||||||||||||||||||||
|
Condition50%1/2
$attrs->{$attr} // {}
MC/DC0%0/1
$attrs->{$attr} // {}
$attrs->{$attr}
Truth table50%1/2
A
A= $attrs->{$attr}
| |||||||||||||||||||||||||||||||
| 187 | }; | ||||||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||
| 198 | 12 | ▶ | sub value { | ||||||||||||||||||||||||||||
|
Subroutine
value: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||
| 199 | 12 | my ( $self, $attr, $tag ) = @_; | |||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||
| 201 | 8 | ▶ | no autovivification; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 202 | 12 | return $self->attr_hash->{$attr}{$tag}; | |||||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||
| 205 | # | ||||||||||||||||||||||||||||||
| 206 | # This file is part of MooX-TaggedAttributes | ||||||||||||||||||||||||||||||
| 207 | # | ||||||||||||||||||||||||||||||
| 208 | # This software is Copyright (c) 2018 by Smithsonian Astrophysical Observatory. | ||||||||||||||||||||||||||||||
| 209 | # | ||||||||||||||||||||||||||||||
| 210 | # This is free software, licensed under: | ||||||||||||||||||||||||||||||
| 211 | # | ||||||||||||||||||||||||||||||
| 212 | # The GNU General Public License, Version 3, June 2007 | ||||||||||||||||||||||||||||||
| 213 | # | ||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||
| 215 | __END__ | ||||||||||||||||||||||||||||||