line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Hash::AutoHash::AVPairsSingle; |
2
|
|
|
|
|
|
|
our $VERSION='1.17'; |
3
|
|
|
|
|
|
|
$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 single-valued, string or number elements. no references |
12
|
|
|
|
|
|
|
# |
13
|
|
|
|
|
|
|
################################################################################# |
14
|
9
|
|
|
9
|
|
267362
|
use strict; |
|
9
|
|
|
|
|
25
|
|
|
9
|
|
|
|
|
400
|
|
15
|
9
|
|
|
9
|
|
47
|
use Carp; |
|
9
|
|
|
|
|
19
|
|
|
9
|
|
|
|
|
533
|
|
16
|
9
|
|
|
9
|
|
5824
|
use Hash::AutoHash; |
|
9
|
|
|
|
|
53872
|
|
|
9
|
|
|
|
|
69
|
|
17
|
9
|
|
|
9
|
|
1675
|
use base qw(Hash::AutoHash); |
|
9
|
|
|
|
|
23
|
|
|
9
|
|
|
|
|
2179
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
our @NORMAL_EXPORT_OK=@Hash::AutoHash::EXPORT_OK; |
20
|
|
|
|
|
|
|
my $helper_class=__PACKAGE__.'::helper'; |
21
|
|
|
|
|
|
|
our @EXPORT_OK=$helper_class->EXPORT_OK; |
22
|
|
|
|
|
|
|
our @SUBCLASS_EXPORT_OK=$helper_class->SUBCLASS_EXPORT_OK; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
################################################################################# |
25
|
|
|
|
|
|
|
# helper package exists to avoid polluting Hash::AutoHash::Args namespace with |
26
|
|
|
|
|
|
|
# subs that would mask accessor/mutator AUTOLOADs |
27
|
|
|
|
|
|
|
# functions herein (except _new) are exportable by Hash::AutoHash::Args |
28
|
|
|
|
|
|
|
################################################################################# |
29
|
|
|
|
|
|
|
package Hash::AutoHash::AVPairsSingle::helper; |
30
|
|
|
|
|
|
|
our $VERSION=$Hash::AutoHash::AVPairsSingle::VERSION; |
31
|
9
|
|
|
9
|
|
49
|
use strict; |
|
9
|
|
|
|
|
17
|
|
|
9
|
|
|
|
|
308
|
|
32
|
9
|
|
|
9
|
|
42
|
use Carp; |
|
9
|
|
|
|
|
16
|
|
|
9
|
|
|
|
|
790
|
|
33
|
|
|
|
|
|
|
BEGIN { |
34
|
9
|
|
|
9
|
|
329
|
our @ISA=qw(Hash::AutoHash::helper); |
35
|
|
|
|
|
|
|
} |
36
|
9
|
|
|
9
|
|
48
|
use Hash::AutoHash qw(autohash_tie); |
|
9
|
|
|
|
|
22
|
|
|
9
|
|
|
|
|
35
|
|
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub _new { |
39
|
29
|
|
|
29
|
|
73670
|
my($helper_class,$class,@args)=@_; |
40
|
29
|
|
|
|
|
136
|
my $self=autohash_tie Hash::AutoHash::AVPairsSingle::tie,@args; |
41
|
29
|
|
|
|
|
201
|
bless $self,$class; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
################################################################################# |
45
|
|
|
|
|
|
|
# Tied hash which implements Hash::AutoHash::MultiValued |
46
|
|
|
|
|
|
|
################################################################################# |
47
|
|
|
|
|
|
|
package Hash::AutoHash::AVPairsSingle::tie; |
48
|
|
|
|
|
|
|
our $VERSION=$Hash::AutoHash::AVPairsSingle::VERSION; |
49
|
9
|
|
|
9
|
|
1647
|
use strict; |
|
9
|
|
|
|
|
20
|
|
|
9
|
|
|
|
|
270
|
|
50
|
9
|
|
|
9
|
|
43
|
use Carp; |
|
9
|
|
|
|
|
12
|
|
|
9
|
|
|
|
|
587
|
|
51
|
9
|
|
|
9
|
|
48
|
use Tie::Hash; |
|
9
|
|
|
|
|
14
|
|
|
9
|
|
|
|
|
356
|
|
52
|
|
|
|
|
|
|
our @ISA=qw(Tie::ExtraHash); |
53
|
9
|
|
|
9
|
|
94
|
use constant STORAGE=>0; |
|
9
|
|
|
|
|
14
|
|
|
9
|
|
|
|
|
2953
|
|
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub TIEHASH { |
56
|
29
|
|
|
29
|
|
404
|
my($class,@hash)=@_; |
57
|
29
|
|
|
|
|
113
|
my $self=bless [{}],$class; |
58
|
29
|
100
|
|
|
|
119
|
if (@hash==1) { # flatten if ARRAY or HASH |
59
|
4
|
|
|
|
|
76
|
my $hash=shift @hash; |
60
|
4
|
50
|
|
|
|
34
|
@hash=('ARRAY' eq ref $hash)? @$hash: ('HASH' eq ref $hash)? %$hash: (); |
|
|
100
|
|
|
|
|
|
61
|
|
|
|
|
|
|
} |
62
|
29
|
|
|
|
|
101
|
while (@hash>1) { # store initial values |
63
|
43
|
|
|
|
|
101
|
my($key,$value)=splice @hash,0,2; # shift 1st two elements |
64
|
43
|
|
|
|
|
111
|
$self->STORE($key,$value); |
65
|
|
|
|
|
|
|
} |
66
|
29
|
|
|
|
|
109
|
$self; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
sub STORE { |
69
|
84
|
|
|
84
|
|
128987
|
my($self,$key,$new)=@_; |
70
|
84
|
100
|
|
|
|
453
|
confess "Trying to store reference as value of attribute $key" if ref $new; |
71
|
83
|
|
|
|
|
403
|
$self->[STORAGE]->{$key}=$new; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
1; |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
__END__ |