line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Objects::Collection::ActiveRecord; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=head1 NAME |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
Objects::Collection::ActiveRecord - Tools for track changes in HASHes. |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 SYNOPSIS |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
use Objects::Collection::ActiveRecord; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub _prepare_record { |
12
|
|
|
|
|
|
|
my ( $self, $key, $ref ) = @_; |
13
|
|
|
|
|
|
|
my %hash; |
14
|
|
|
|
|
|
|
tie %hash, 'Objects::Collection::ActiveRecord', hash => $ref; |
15
|
|
|
|
|
|
|
return \%hash; |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head1 DESCRIPTION |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
Tools for track changes in HASHes. |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=cut |
23
|
|
|
|
|
|
|
|
24
|
3
|
|
|
3
|
|
806
|
use strict; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
99
|
|
25
|
3
|
|
|
3
|
|
15
|
use warnings; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
74
|
|
26
|
3
|
|
|
3
|
|
14
|
use strict; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
77
|
|
27
|
3
|
|
|
3
|
|
15
|
use Carp; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
172
|
|
28
|
3
|
|
|
3
|
|
15
|
use Data::Dumper; |
|
3
|
|
|
|
|
12
|
|
|
3
|
|
|
|
|
168
|
|
29
|
|
|
|
|
|
|
require Tie::Hash; |
30
|
3
|
|
|
3
|
|
1085
|
use Objects::Collection::Base; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
1760
|
|
31
|
|
|
|
|
|
|
@Objects::Collection::ActiveRecord::ISA = qw(Tie::StdHash Objects::Collection::Base); |
32
|
|
|
|
|
|
|
$Objects::Collection::ActiveRecord::VERSION = '0.01'; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
attributes qw( _changed _orig_record __temp_array); |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub _init { |
37
|
3
|
|
|
3
|
|
5
|
my $self = shift; |
38
|
3
|
|
|
|
|
13
|
return $self->Init(@_); |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub DELETE { |
42
|
0
|
|
|
0
|
|
0
|
my ( $self, $key ) = @_; |
43
|
0
|
|
|
|
|
0
|
$self->_changed(1); |
44
|
0
|
|
|
|
|
0
|
delete $self->_orig_record->{$key}; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub STORE { |
49
|
1
|
|
|
1
|
|
3
|
my ( $self, $key, $val ) = @_; |
50
|
1
|
|
|
|
|
28
|
my $hash = $self->_orig_record; |
51
|
1
|
|
|
|
|
25
|
$self->_changed(1); |
52
|
1
|
|
|
|
|
4
|
$hash->{$key} = $val; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub FETCH { |
56
|
19
|
|
|
19
|
|
70
|
my ( $self, $key ) = @_; |
57
|
19
|
100
|
|
|
|
40
|
if ( $key eq '_changed' ) { |
58
|
2
|
|
|
|
|
49
|
$self->_changed(); |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
else { |
61
|
17
|
|
|
|
|
455
|
$self->_orig_record->{$key}; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub Init { |
66
|
3
|
|
|
3
|
0
|
8
|
my ( $self, %arg ) = @_; |
67
|
3
|
|
|
|
|
102
|
$self->_orig_record( $arg{hash} ); |
68
|
3
|
50
|
|
|
|
14
|
unless ( $arg{hash} ) { |
69
|
0
|
|
|
|
|
0
|
carp "Not inited param hash" |
70
|
|
|
|
|
|
|
} |
71
|
3
|
|
|
|
|
140
|
$self->_changed(0); |
72
|
3
|
|
|
|
|
17
|
return 1; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub GetKeys { |
76
|
26
|
|
|
26
|
0
|
27
|
my $self = shift; |
77
|
26
|
|
|
|
|
667
|
my $hash = $self->_orig_record; |
78
|
26
|
|
|
|
|
178
|
return [ keys %$hash ]; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
|
82
|
3
|
|
|
3
|
|
42
|
sub TIEHASH {return Objects::Collection::Base::new(@_) } |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub FIRSTKEY { |
85
|
26
|
|
|
26
|
|
1410
|
my ($self) = @_; |
86
|
26
|
|
|
|
|
31
|
$self->__temp_array( [ sort { $a cmp $b } @{ $self->GetKeys() } ] ); |
|
24
|
|
|
|
|
622
|
|
|
26
|
|
|
|
|
46
|
|
87
|
26
|
|
|
|
|
49
|
shift( @{ $self->__temp_array() } ); |
|
26
|
|
|
|
|
625
|
|
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub NEXTKEY { |
91
|
50
|
|
|
50
|
|
69
|
my ( $self, $key ) = @_; |
92
|
50
|
|
|
|
|
50
|
shift( @{ $self->__temp_array() } ); |
|
50
|
|
|
|
|
1169
|
|
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub EXISTS { |
96
|
24
|
|
|
24
|
|
115
|
my ( $self, $key ) = @_; |
97
|
24
|
|
|
|
|
612
|
my $hash = $self->_orig_record; |
98
|
24
|
|
|
|
|
111
|
return exists $hash->{$key}; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub CLEAR { |
102
|
0
|
|
|
0
|
|
|
my $self = shift; |
103
|
0
|
|
|
|
|
|
%{ $self->_orig_record } = (); |
|
0
|
|
|
|
|
|
|
104
|
0
|
|
|
|
|
|
$self->_changed(1); |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
1; |
108
|
|
|
|
|
|
|
__END__ |