line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Cache::Funky; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
20690
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
48
|
|
4
|
2
|
|
|
2
|
|
8
|
use strict qw( subs ); |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
42
|
|
5
|
2
|
|
|
2
|
|
9
|
use Carp; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
162
|
|
6
|
2
|
|
|
2
|
|
1509
|
use UNIVERSAL::require; |
|
2
|
|
|
|
|
2926
|
|
|
2
|
|
|
|
|
17
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '0.06'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub setup { |
11
|
1
|
|
|
1
|
1
|
21
|
my $class = shift; |
12
|
1
|
|
|
|
|
4
|
my $storage = shift; |
13
|
1
|
|
|
|
|
2
|
my $storage_args = shift; |
14
|
|
|
|
|
|
|
|
15
|
1
|
50
|
|
|
|
5
|
croak("setup() is a class method, not an object method") if ref $class; |
16
|
|
|
|
|
|
|
|
17
|
1
|
|
|
|
|
6
|
my $storage_class = __PACKAGE__ . "::$storage"; |
18
|
1
|
50
|
|
|
|
10
|
$storage_class->require or croak $@; |
19
|
|
|
|
|
|
|
|
20
|
1
|
|
|
|
|
27
|
my $storage_obj = $storage_class->new( $storage_args ); |
21
|
|
|
|
|
|
|
|
22
|
1
|
|
|
18
|
|
15
|
*{ $class . '::_storage' } = sub { $storage_obj }; |
|
1
|
|
|
|
|
14
|
|
|
18
|
|
|
|
|
98
|
|
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub register { |
26
|
2
|
|
|
2
|
1
|
25
|
my $class = shift; |
27
|
2
|
|
|
|
|
5
|
my $attribute = shift; |
28
|
2
|
|
|
|
|
4
|
my $code = shift; |
29
|
|
|
|
|
|
|
|
30
|
2
|
50
|
|
|
|
10
|
croak("register() is a class method, not an object method") if ref $class; |
31
|
2
|
50
|
|
|
|
6
|
croak("you need args of attribute") if !defined $attribute; |
32
|
2
|
50
|
33
|
|
|
17
|
croak("you need args of coderef") if !defined $code or ref $code ne 'CODE'; |
33
|
|
|
|
|
|
|
|
34
|
2
|
|
|
|
|
6
|
my $package_attribute = $class . '::' . $attribute; |
35
|
2
|
|
|
|
|
12
|
*{ $package_attribute } |
36
|
|
|
|
|
|
|
= sub { |
37
|
9
|
|
|
9
|
|
33
|
my $self = shift; |
38
|
9
|
|
|
|
|
46
|
my $id = shift; |
39
|
|
|
|
|
|
|
|
40
|
9
|
|
|
|
|
624
|
my $data; |
41
|
9
|
100
|
|
|
|
35
|
unless ( $data = $self->_storage->get( $package_attribute , $id ) ) { |
42
|
6
|
|
|
|
|
22
|
$data = $code->( $id ); |
43
|
6
|
|
|
|
|
42
|
$self->_storage->set( $package_attribute, $data , $id ); |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
9
|
|
|
|
|
69
|
return $data; |
47
|
2
|
|
|
|
|
11
|
}; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub delete { |
51
|
2
|
|
|
2
|
1
|
1001924
|
my $self = shift; |
52
|
2
|
|
|
|
|
8
|
my $attribute = shift; |
53
|
2
|
|
|
|
|
3
|
my $id = shift; |
54
|
|
|
|
|
|
|
|
55
|
2
|
|
33
|
|
|
26
|
my $package_attribute = ( ref $self || $self ) .'::'. $attribute; |
56
|
2
|
|
|
|
|
10
|
$self->_storage->delete( $package_attribute , $id ); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub deletes { |
60
|
1
|
|
|
1
|
1
|
5
|
my $self = shift; |
61
|
1
|
|
|
|
|
4
|
my $attributes = shift; |
62
|
|
|
|
|
|
|
|
63
|
1
|
50
|
|
|
|
12
|
croak "you need to set attributes keys" unless ref $attributes eq 'ARRAY' ; |
64
|
|
|
|
|
|
|
|
65
|
1
|
|
|
|
|
4
|
for my $attribute ( @{ $attributes } ) { |
|
1
|
|
|
|
|
6
|
|
66
|
1
|
|
33
|
|
|
13
|
my $package_attribute = ( ref $self || $self ) .'::'. $attribute; |
67
|
1
|
|
|
|
|
7
|
$self->_storage->delete( $package_attribute ); |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
1; # Magic true value required at end of module |
72
|
|
|
|
|
|
|
__END__ |