| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
=head1 NAME |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
Class::Persist::Tracker - Keep track of all objects |
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
$tracker = Class::Persist::Tracker->new(); |
|
8
|
|
|
|
|
|
|
$tracker->object( $object ); |
|
9
|
|
|
|
|
|
|
$tracker->store(); |
|
10
|
|
|
|
|
|
|
print $tracker->class(); |
|
11
|
|
|
|
|
|
|
$tracker = Class::Persist::Tracker->load($oid); |
|
12
|
|
|
|
|
|
|
$obj = $tracker->object(); |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
Store Tracker Tracker keep track of the class and oid of all object, |
|
17
|
|
|
|
|
|
|
thus allowing to load an object based on its oid only. |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 INHERITANCE |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
Class::Persist |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=head1 METHODS |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=cut |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
package Class::Persist::Tracker; |
|
28
|
1
|
|
|
1
|
|
1887
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
31
|
|
|
29
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
28
|
|
|
30
|
1
|
|
|
1
|
|
6
|
use base qw( Class::Persist ); |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
136
|
|
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
__PACKAGE__->db_table('tracker'); |
|
33
|
|
|
|
|
|
|
__PACKAGE__->db_fields( qw/class/ ); |
|
34
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors( qw(class) ); |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=head2 object( $obj ) |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=cut |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub object { |
|
44
|
|
|
|
|
|
|
my $self = shift; |
|
45
|
|
|
|
|
|
|
my $obj = shift; |
|
46
|
|
|
|
|
|
|
if (defined $obj) { |
|
47
|
|
|
|
|
|
|
Class::Persist::Error::InvalidParameters->throw(text => "Should be a Class::Persist") unless (ref($obj) and $obj->isa('Class::Persist')); |
|
48
|
|
|
|
|
|
|
$self->set('object', $obj); |
|
49
|
|
|
|
|
|
|
$self->class( ref $obj ); |
|
50
|
|
|
|
|
|
|
$self->oid( $obj->oid ); |
|
51
|
|
|
|
|
|
|
die if ( $self->oid ne $obj->oid ); # Sanity good. |
|
52
|
|
|
|
|
|
|
return $self; |
|
53
|
|
|
|
|
|
|
} |
|
54
|
|
|
|
|
|
|
elsif ( $self->get('object') ) { |
|
55
|
|
|
|
|
|
|
return $self->get('object'); |
|
56
|
|
|
|
|
|
|
} |
|
57
|
|
|
|
|
|
|
else { |
|
58
|
|
|
|
|
|
|
my $class = $self->class or Class::Persist::Error::InvalidParameters->throw(text => "Tracker not loaded"); |
|
59
|
|
|
|
|
|
|
$self->loadModule( $class ) or return; |
|
60
|
|
|
|
|
|
|
$self->set( 'object', $class->load( $self->oid ) ); |
|
61
|
|
|
|
|
|
|
return $self->get('object'); |
|
62
|
|
|
|
|
|
|
} |
|
63
|
|
|
|
|
|
|
} |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub validate { |
|
67
|
|
|
|
|
|
|
my $self = shift; |
|
68
|
|
|
|
|
|
|
$self->SUPER::validate(@_) && $self->class; |
|
69
|
|
|
|
|
|
|
} |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub track { shift } |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
## |
|
75
|
|
|
|
|
|
|
## DB mapping utilities |
|
76
|
|
|
|
|
|
|
## |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub db_fields_spec { |
|
79
|
|
|
|
|
|
|
shift->SUPER::db_fields_spec, ( |
|
80
|
|
|
|
|
|
|
'class CHAR(40) NOT NULL', |
|
81
|
|
|
|
|
|
|
) |
|
82
|
|
|
|
|
|
|
}; |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
1; |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
Class::Persist |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=head1 AUTHOR |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
Fotango |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=cut |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
# Local Variables: |
|
99
|
|
|
|
|
|
|
# mode:CPerl |
|
100
|
|
|
|
|
|
|
# cperl-indent-level: 2 |
|
101
|
|
|
|
|
|
|
# indent-tabs-mode: nil |
|
102
|
|
|
|
|
|
|
# End: |