line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Collection::Mem; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=head1 NAME |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
Collection::Mem - class for collections of data, stored in memory. |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 SYNOPSIS |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
use Collection::Mem; |
10
|
|
|
|
|
|
|
my $meta = new Collection::Mem:: mem=>$hash1; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 DESCRIPTION |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
Class for collection of data, stored in memory. |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 METHODS |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=cut |
19
|
|
|
|
|
|
|
|
20
|
2
|
|
|
2
|
|
2169
|
use Collection; |
|
2
|
|
|
|
|
15
|
|
|
2
|
|
|
|
|
80
|
|
21
|
2
|
|
|
2
|
|
14
|
use Collection::Utl::Base; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
82
|
|
22
|
2
|
|
|
2
|
|
1137
|
use Collection::Utl::Item; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
101
|
|
23
|
2
|
|
|
2
|
|
15
|
use Data::Dumper; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
104
|
|
24
|
2
|
|
|
2
|
|
13
|
use Test::More; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
19
|
|
25
|
2
|
|
|
2
|
|
872
|
use Collection::Utl::ActiveRecord; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
77
|
|
26
|
|
|
|
|
|
|
|
27
|
2
|
|
|
2
|
|
9
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
61
|
|
28
|
2
|
|
|
2
|
|
9
|
use warnings; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
1285
|
|
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
our @ISA = qw(Collection); |
31
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
attributes qw/ _mem_cache /; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub _init { |
36
|
2
|
|
|
2
|
|
5
|
my $self = shift; |
37
|
2
|
|
|
|
|
5
|
my %args = @_; |
38
|
2
|
|
50
|
|
|
76
|
$self->_mem_cache( $args{mem} || {} ); |
39
|
2
|
|
|
|
|
16
|
$self->SUPER::_init(); |
40
|
2
|
|
|
|
|
18
|
return 1; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub _delete { |
44
|
2
|
|
|
2
|
|
58
|
my $self = shift; |
45
|
2
|
|
|
|
|
4
|
my @ids = @_; |
46
|
2
|
|
|
|
|
42
|
my $coll = $self->_mem_cache; |
47
|
2
|
|
|
|
|
3
|
delete @{$coll}{@ids}; |
|
2
|
|
|
|
|
6
|
|
48
|
2
|
|
|
|
|
13
|
[@ids]; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub _create { |
52
|
4
|
|
|
4
|
|
7
|
my $self = shift; |
53
|
4
|
|
|
|
|
89
|
my $coll = $self->_mem_cache; |
54
|
4
|
100
|
|
|
|
11
|
if ( @_ > 1 ) { |
55
|
2
|
|
|
|
|
4
|
my %new_keys_vals = @_; |
56
|
2
|
|
|
|
|
3
|
my %res = (); |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
# resolve hash refs to new hashes |
59
|
2
|
|
|
|
|
11
|
while ( my ( $key, $val ) = each %new_keys_vals ) { |
60
|
2
|
|
|
|
|
8
|
%{ $coll->{$key} } = %$val; |
|
2
|
|
|
|
|
35
|
|
61
|
2
|
|
|
|
|
10
|
$res{$key} = $coll->{$key}; |
62
|
|
|
|
|
|
|
} |
63
|
2
|
|
|
|
|
9
|
return \%res; |
64
|
|
|
|
|
|
|
} |
65
|
2
|
|
|
|
|
3
|
my %res = (); |
66
|
2
|
|
|
|
|
5
|
my $attrs = shift; |
67
|
|
|
|
|
|
|
|
68
|
2
|
50
|
|
|
|
8
|
if ( ref($attrs) eq 'HASH' ) { |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
#merge with already exists |
71
|
|
|
|
|
|
|
# resolve hash refs to new hashes |
72
|
2
|
|
|
|
|
10
|
while ( my ( $key, $val ) = each %$attrs ) { |
73
|
2
|
|
|
|
|
7
|
%{ $coll->{$key} } = %$val; |
|
2
|
|
|
|
|
7
|
|
74
|
2
|
|
|
|
|
12
|
$res{$key} = $coll->{$key}; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
else { |
79
|
0
|
|
|
|
|
0
|
foreach my $value (@$attrs) { |
80
|
0
|
|
|
|
|
0
|
my ($max) = sort { $b <=> $a } keys %$coll; |
|
0
|
|
|
|
|
0
|
|
81
|
0
|
|
|
|
|
0
|
$coll->{ ++$max } = $value; |
82
|
0
|
|
|
|
|
0
|
$res{$max} = $value; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
} |
85
|
2
|
|
|
|
|
6
|
return \%res; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub _fetch { |
89
|
12
|
|
|
12
|
|
14
|
my $self = shift; |
90
|
12
|
|
|
|
|
17
|
my @ids = @_; |
91
|
12
|
|
|
|
|
278
|
my $coll = $self->_mem_cache; |
92
|
12
|
|
|
|
|
14
|
my %res; |
93
|
12
|
|
|
|
|
18
|
for (@ids) { |
94
|
12
|
100
|
|
|
|
49
|
$res{$_} = $coll->{$_} if exists $coll->{$_}; |
95
|
|
|
|
|
|
|
} |
96
|
12
|
|
|
|
|
69
|
return \%res; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
sub _prepare_record { |
100
|
6
|
|
|
6
|
|
10
|
my ( $self, $key, $ref ) = @_; |
101
|
6
|
|
|
|
|
6
|
my %hash; |
102
|
6
|
|
|
|
|
34
|
tie %hash, 'Collection::Utl::ActiveRecord', hash => $ref; |
103
|
6
|
|
|
|
|
18
|
return \%hash; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub _fetch_all { |
107
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
108
|
0
|
|
|
|
|
0
|
return [ keys %{ $self->_mem_cache } ]; |
|
0
|
|
|
|
|
0
|
|
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
sub _store { |
112
|
3
|
|
|
3
|
|
9
|
my $self = shift; |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
sub commit { |
116
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
sub list_ids { |
120
|
2
|
|
|
2
|
0
|
3
|
my $self = shift; |
121
|
2
|
|
|
|
|
3
|
return [ keys %{ $self->_mem_cache } ]; |
|
2
|
|
|
|
|
42
|
|
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
1; |
125
|
|
|
|
|
|
|
__END__ |