line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Collection::Utl::ActiveRecord; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=head1 NAME |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
Collection::Utl::ActiveRecord - Tools for track changes in HASHes. |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 SYNOPSIS |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
use Collection::Utl::ActiveRecord; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub _prepare_record { |
12
|
|
|
|
|
|
|
my ( $self, $key, $ref ) = @_; |
13
|
|
|
|
|
|
|
my %hash; |
14
|
|
|
|
|
|
|
tie %hash, 'Collection::Utl::ActiveRecord', hash => $ref; |
15
|
|
|
|
|
|
|
return \%hash; |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head1 DESCRIPTION |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
Tools for track changes in HASHes. |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=cut |
23
|
|
|
|
|
|
|
|
24
|
5
|
|
|
5
|
|
74068
|
use strict; |
|
5
|
|
|
|
|
18
|
|
|
5
|
|
|
|
|
181
|
|
25
|
5
|
|
|
5
|
|
25
|
use warnings; |
|
5
|
|
|
|
|
10
|
|
|
5
|
|
|
|
|
127
|
|
26
|
5
|
|
|
5
|
|
25
|
use strict; |
|
5
|
|
|
|
|
13
|
|
|
5
|
|
|
|
|
155
|
|
27
|
5
|
|
|
5
|
|
391
|
use Carp; |
|
5
|
|
|
|
|
11
|
|
|
5
|
|
|
|
|
398
|
|
28
|
5
|
|
|
5
|
|
26
|
use Data::Dumper; |
|
5
|
|
|
|
|
8
|
|
|
5
|
|
|
|
|
259
|
|
29
|
|
|
|
|
|
|
require Tie::Hash; |
30
|
5
|
|
|
5
|
|
4550
|
use Collection::Utl::Base; |
|
5
|
|
|
|
|
24
|
|
|
5
|
|
|
|
|
3161
|
|
31
|
|
|
|
|
|
|
@Collection::Utl::ActiveRecord::ISA = qw(Tie::StdHash Collection::Utl::Base); |
32
|
|
|
|
|
|
|
$Collection::Utl::ActiveRecord::VERSION = '0.01'; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
attributes qw( _changed_ _orig_record __temp_array); |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub _init { |
37
|
11
|
|
|
11
|
|
18
|
my $self = shift; |
38
|
11
|
|
|
|
|
33
|
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
|
6
|
|
|
6
|
|
24
|
my ( $self, $key, $val ) = @_; |
50
|
6
|
|
|
|
|
156
|
my $hash = $self->_orig_record; |
51
|
6
|
|
|
|
|
150
|
$self->_changed_(1); |
52
|
6
|
|
|
|
|
33
|
$hash->{$key} = $val; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
2
|
|
|
2
|
|
73
|
sub _changed { $_[0]->_changed_} |
56
|
|
|
|
|
|
|
sub FETCH { |
57
|
43
|
|
|
43
|
|
127
|
my ( $self, $key ) = @_; |
58
|
43
|
100
|
|
|
|
92
|
if ( $key eq '_changed' ) { |
59
|
12
|
|
|
|
|
297
|
$self->_changed_(); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
else { |
62
|
31
|
|
|
|
|
752
|
$self->_orig_record->{$key}; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub Init { |
67
|
11
|
|
|
11
|
0
|
25
|
my ( $self, %arg ) = @_; |
68
|
11
|
|
|
|
|
304
|
$self->_orig_record( $arg{hash} ); |
69
|
11
|
50
|
|
|
|
31
|
unless ( $arg{hash} ) { |
70
|
0
|
|
|
|
|
0
|
carp "Not inited param hash" |
71
|
|
|
|
|
|
|
} |
72
|
11
|
|
|
|
|
291
|
$self->_changed_(0); |
73
|
11
|
|
|
|
|
62
|
return 1; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub GetKeys { |
77
|
36
|
|
|
36
|
0
|
48
|
my $self = shift; |
78
|
36
|
|
|
|
|
914
|
my $hash = $self->_orig_record; |
79
|
36
|
|
|
|
|
207
|
return [ keys %$hash ]; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
|
83
|
11
|
|
|
11
|
|
55
|
sub TIEHASH {return Collection::Utl::Base::new(@_) } |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub FIRSTKEY { |
86
|
36
|
|
|
36
|
|
3104
|
my ($self) = @_; |
87
|
36
|
|
|
|
|
50
|
$self->{__temp_array} = [ sort { $a cmp $b } @{ $self->GetKeys() } ] ; |
|
27
|
|
|
|
|
100
|
|
|
36
|
|
|
|
|
75
|
|
88
|
36
|
|
|
|
|
78
|
shift( @{ $self->{__temp_array} } ); |
|
36
|
|
|
|
|
151
|
|
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub NEXTKEY { |
92
|
63
|
|
|
63
|
|
96
|
my ( $self, $key ) = @_; |
93
|
63
|
|
|
|
|
71
|
shift( @{ $self->{__temp_array} } ); |
|
63
|
|
|
|
|
351
|
|
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
sub EXISTS { |
97
|
30
|
|
|
30
|
|
177
|
my ( $self, $key ) = @_; |
98
|
30
|
|
|
|
|
740
|
my $hash = $self->_orig_record; |
99
|
30
|
|
|
|
|
149
|
return exists $hash->{$key}; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub CLEAR { |
103
|
1
|
|
|
1
|
|
2
|
my $self = shift; |
104
|
1
|
|
|
|
|
2
|
%{ $self->_orig_record } = (); |
|
1
|
|
|
|
|
19
|
|
105
|
1
|
|
|
|
|
21
|
$self->_changed_(1); |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
1; |
109
|
|
|
|
|
|
|
__END__ |