line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
############################################################################### |
2
|
|
|
|
|
|
|
# Purpose : Extension of Cache::Object.pm to support policy meta-data. |
3
|
|
|
|
|
|
|
# Author : Sam Graham |
4
|
|
|
|
|
|
|
# Created : 24 Jun 2008 |
5
|
|
|
|
|
|
|
# CVS : $Id: Object.pm,v 1.7 2010-02-16 12:25:41 illusori Exp $ |
6
|
|
|
|
|
|
|
############################################################################### |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
package Cache::CacheFactory::Object; |
9
|
|
|
|
|
|
|
|
10
|
10
|
|
|
10
|
|
51
|
use warnings; |
|
10
|
|
|
|
|
19
|
|
|
10
|
|
|
|
|
300
|
|
11
|
10
|
|
|
10
|
|
50
|
use strict; |
|
10
|
|
|
|
|
20
|
|
|
10
|
|
|
|
|
278
|
|
12
|
|
|
|
|
|
|
|
13
|
10
|
|
|
10
|
|
45
|
use base qw/Cache::Object/; |
|
10
|
|
|
|
|
16
|
|
|
10
|
|
|
|
|
13998
|
|
14
|
|
|
|
|
|
|
|
15
|
10
|
|
|
10
|
|
15148
|
use Storable; |
|
10
|
|
|
|
|
34917
|
|
|
10
|
|
|
|
|
3822
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
$Cache::CacheFactory::Object::VERSION = '1.10'; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub new_from_old |
20
|
|
|
|
|
|
|
{ |
21
|
0
|
|
|
0
|
1
|
0
|
my ( $class, $old_ob, $param ) = @_; |
22
|
0
|
|
|
|
|
0
|
my ( $ob ); |
23
|
|
|
|
|
|
|
|
24
|
0
|
|
|
|
|
0
|
$ob = $class->new(); |
25
|
|
|
|
|
|
|
$ob->initialize( |
26
|
|
|
|
|
|
|
$old_ob->get_key(), |
27
|
|
|
|
|
|
|
$old_ob->get_data(), |
28
|
|
|
|
|
|
|
{ |
29
|
|
|
|
|
|
|
created_at => $old_ob->get_created_at(), |
30
|
|
|
|
|
|
|
accessed_at => $old_ob->get_accessed_at(), |
31
|
|
|
|
|
|
|
expires_at => $old_ob->get_expires_at(), |
32
|
|
|
|
|
|
|
no_deep_clone => $param->{ no_deep_clone }, |
33
|
0
|
|
|
|
|
0
|
} ); |
34
|
|
|
|
|
|
|
# TODO: this should probably be recalculated by the policies? |
35
|
0
|
|
|
|
|
0
|
$ob->set_size( $old_ob->get_size() ); |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub initialize |
39
|
|
|
|
|
|
|
{ |
40
|
79
|
|
|
79
|
1
|
162
|
my ( $self, $key, $data, $param ) = @_; |
41
|
|
|
|
|
|
|
|
42
|
79
|
|
|
|
|
238
|
$self->set_key( $key ); |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
# Produce a deep clone fo the data unless we don't need to |
45
|
|
|
|
|
|
|
# or we're asked not to. |
46
|
|
|
|
|
|
|
$data = Storable::dclone( $data ) |
47
|
79
|
100
|
100
|
|
|
1616
|
if ref( $data ) and not $param->{ no_deep_clone }; |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
# Set the data. |
50
|
79
|
|
|
|
|
254
|
$self->set_data( $data ); |
51
|
|
|
|
|
|
|
# TODO: weaken ref param handling here? |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
# Overrule default properties if they've been supplied. |
54
|
79
|
|
|
|
|
374
|
foreach my $property ( qw/created_at accessed_at expires_at/ ) |
55
|
|
|
|
|
|
|
{ |
56
|
237
|
100
|
|
|
|
685
|
if( exists( $param->{ $property } ) ) |
57
|
|
|
|
|
|
|
{ |
58
|
79
|
|
|
|
|
78
|
my ( $method ); |
59
|
|
|
|
|
|
|
|
60
|
79
|
|
|
|
|
117
|
$method = "set_${property}"; |
61
|
79
|
|
|
|
|
303
|
$self->$method( $param->{ $property } ); |
62
|
79
|
|
|
|
|
398
|
delete $param->{ $property }; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub set_policy_metadata |
68
|
|
|
|
|
|
|
{ |
69
|
5
|
|
|
5
|
1
|
11
|
my ( $self, $policytype, $policy, $metadata ) = @_; |
70
|
|
|
|
|
|
|
|
71
|
5
|
|
100
|
|
|
27
|
$self->{ _Policy_Meta_Data } ||= {}; |
72
|
5
|
|
50
|
|
|
45
|
$self->{ _Policy_Meta_Data }->{ $policytype } ||= {}; |
73
|
5
|
|
|
|
|
27
|
$self->{ _Policy_Meta_Data }->{ $policytype }->{ $policy } = $metadata; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub get_policy_metadata |
77
|
|
|
|
|
|
|
{ |
78
|
15
|
|
|
15
|
1
|
27
|
my ( $self, $policytype, $policy ) = @_; |
79
|
|
|
|
|
|
|
|
80
|
15
|
|
|
|
|
68
|
return( $self->{ _Policy_Meta_Data }->{ $policytype }->{ $policy } ); |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
1; |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
__END__ |