| 1 | package Hash::AutoHash::AVPairsMulti; | ||||||||||||||||||||||||||||
| 2 | 11 | our $VERSION='1.17_01'; | |||||||||||||||||||||||||||
| 3 | 11 | $VERSION=eval $VERSION; # I think this is the accepted idiom.. | |||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | ################################################################################# | ||||||||||||||||||||||||||||
| 6 | # | ||||||||||||||||||||||||||||
| 7 | # Author: Nat Goodman | ||||||||||||||||||||||||||||
| 8 | # Created: 09-03-05 | ||||||||||||||||||||||||||||
| 9 | # $Id: | ||||||||||||||||||||||||||||
| 10 | # | ||||||||||||||||||||||||||||
| 11 | # AutoHash with multivalued string or number elements. no references | ||||||||||||||||||||||||||||
| 12 | # Inspired by Tie::Hash::Multivalue | ||||||||||||||||||||||||||||
| 13 | # | ||||||||||||||||||||||||||||
| 14 | ################################################################################# | ||||||||||||||||||||||||||||
| 15 | 11 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | 11 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | 11 | ▶ | use Hash::AutoHash; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | 11 | ▶ | use base qw(Hash::AutoHash); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 11 | our @NORMAL_EXPORT_OK=@Hash::AutoHash::EXPORT_OK; | |||||||||||||||||||||||||||
| 21 | 11 | my $helper_class=__PACKAGE__.'::helper'; | |||||||||||||||||||||||||||
| 22 | 11 | our @EXPORT_OK=$helper_class->EXPORT_OK; | |||||||||||||||||||||||||||
| 23 | 11 | our @SUBCLASS_EXPORT_OK=$helper_class->SUBCLASS_EXPORT_OK; | |||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | ################################################################################# | ||||||||||||||||||||||||||||
| 26 | # helper package exists to avoid polluting Hash::AutoHash::Args namespace with | ||||||||||||||||||||||||||||
| 27 | # subs that would mask accessor/mutator AUTOLOADs | ||||||||||||||||||||||||||||
| 28 | # functions herein (except _new) are exportable by Hash::AutoHash::Args | ||||||||||||||||||||||||||||
| 29 | ################################################################################# | ||||||||||||||||||||||||||||
| 30 | package Hash::AutoHash::AVPairsMulti::helper; | ||||||||||||||||||||||||||||
| 31 | 11 | our $VERSION=$Hash::AutoHash::AVPairsMulti::VERSION; | |||||||||||||||||||||||||||
| 32 | 11 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 33 | 11 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 34 | BEGIN { | ||||||||||||||||||||||||||||
| 35 | 11 | ▶ | our @ISA=qw(Hash::AutoHash::helper); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||
| 37 | 11 | ▶ | use Hash::AutoHash qw(autohash_tie); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | sub _new { | ||||||||||||||||||||||||||||
| 40 | 178 | ▶ | my($helper_class,$class,@args)=@_; | ||||||||||||||||||||||||||
|
Subroutine
_new: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 41 | 178 | my $self=autohash_tie Hash::AutoHash::AVPairsMulti::tie,@args; | |||||||||||||||||||||||||||
| 42 | 175 | bless $self,$class; | |||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | ################################################################################# | ||||||||||||||||||||||||||||
| 46 | # Tied hash which implements Hash::AutoHash::AVPairsMulti | ||||||||||||||||||||||||||||
| 47 | ################################################################################# | ||||||||||||||||||||||||||||
| 48 | package Hash::AutoHash::AVPairsMulti::tie; | ||||||||||||||||||||||||||||
| 49 | 11 | our $VERSION=$Hash::AutoHash::AVPairsMulti::VERSION; | |||||||||||||||||||||||||||
| 50 | 11 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 51 | 11 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 52 | 11 | ▶ | use Hash::AutoHash::MultiValued; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 53 | 11 | our @ISA=qw(Hash::AutoHash::MultiValued::tie); | |||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | sub STORE { | ||||||||||||||||||||||||||||
| 56 | 605 | ▶ | my($self,$key,@new)=@_; | ||||||||||||||||||||||||||
|
Subroutine
STORE: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||
| 57 | # all values must be simple (non-reference) | ||||||||||||||||||||||||||||
| 58 | 605 | my $bad; | |||||||||||||||||||||||||||
| 59 | 605 | ▶ | if (@new==1 && 'ARRAY' eq ref $new[0]) { # if passed ARRAY, look inside | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@new == 1 and "ARRAY" eq ref $new[0]
MC/DC100%2/2
@new == 1 and "ARRAY" eq ref $new[0]
@new == 1
"ARRAY" eq ref $new[0]
Truth table100%3/3
A and B
A= @new == 1B= "ARRAY" eq ref $new[0]
| |||||||||||||||||||||||||||||
| 60 | 495 | ▶ | $bad=1 if grep {ref($_)} @{$new[0]}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 61 | } else { | ||||||||||||||||||||||||||||
| 62 | 110 | $bad=grep {ref($_)} @new; | |||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | 605 | ▶ | confess "Trying to store reference as value of attribute $key" if $bad; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 65 | 598 | $self->SUPER::STORE($key,@new); | |||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | 11 | 1; | |||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | __END__ | ||||||||||||||||||||||||||||