line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Egg::Model::Cache; |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# Masatoshi Mizuno E<lt>lusheE<64>cpan.orgE<gt> |
4
|
|
|
|
|
|
|
# |
5
|
|
|
|
|
|
|
# $Id: Cache.pm 315 2008-04-17 11:33:06Z lushe $ |
6
|
|
|
|
|
|
|
# |
7
|
2
|
|
|
2
|
|
517
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
67
|
|
8
|
2
|
|
|
2
|
|
9
|
use warnings; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
193
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION= '3.01'; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub _setup { |
13
|
0
|
|
|
0
|
|
|
my($class, $e)= @_; |
14
|
0
|
|
|
|
|
|
Egg::Model::Cache::handler->_setup($e); |
15
|
0
|
|
|
|
|
|
$class->next::method($e); |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
package Egg::Model::Cache::handler; |
19
|
2
|
|
|
2
|
|
10
|
use strict; |
|
2
|
|
|
|
|
14
|
|
|
2
|
|
|
|
|
272
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub new { |
22
|
0
|
|
|
0
|
|
|
my($class, $e, $c, $default)= @_; |
23
|
0
|
|
|
|
|
|
my $pkg= $e->project_name. '::Model::Cache'; |
24
|
0
|
|
|
|
|
|
$e->model_manager->context($pkg->default); |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
sub _setup { |
27
|
0
|
|
|
0
|
|
|
my($class, $e)= @_; |
28
|
0
|
|
|
|
|
|
my $base= $e->project_name. '::Model::Cache'; |
29
|
0
|
|
|
|
|
|
my $path= $e->path_to(qw{ lib_project Model/Cache }); |
30
|
2
|
|
|
2
|
|
10
|
no strict 'refs'; ## no critic. |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
636
|
|
31
|
0
|
|
|
|
|
|
push @{"${base}::ISA"}, 'Egg::Base'; |
|
0
|
|
|
|
|
|
|
32
|
0
|
|
|
|
|
|
$base->mk_classdata($_) for qw/ default labels /; |
33
|
0
|
|
|
|
|
|
my $labels= $base->labels($e->ixhash); |
34
|
0
|
|
|
|
|
|
for (sort (grep /.+\.pm$/, <$path/*>)) { ## no critic. |
35
|
0
|
0
|
|
|
|
|
m{([^\\\/\:]+)\.pm$} || next; |
36
|
0
|
|
|
|
|
|
my $name = $1; |
37
|
0
|
|
|
|
|
|
my $dc = "${base}::$name"; |
38
|
0
|
0
|
|
|
|
|
$dc->require or die $@; |
39
|
0
|
|
0
|
|
|
|
my $c= $dc->config || {}; |
40
|
0
|
|
0
|
|
|
|
my $label= lc( $c->{label_name} || "Cache::$name" ); |
41
|
0
|
|
|
|
|
|
$e->model_manager->add_register(0, $label, $dc); |
42
|
0
|
0
|
|
|
|
|
$base->default($label) if $c->{default}; |
43
|
0
|
|
|
|
|
|
$labels->{$label}= $dc; |
44
|
0
|
|
|
|
|
|
$dc->_setup($e); |
45
|
|
|
|
|
|
|
} |
46
|
0
|
0
|
|
|
|
|
%$labels || die __PACKAGE__. q{ - The Cache controller is not found.}; |
47
|
0
|
0
|
|
|
|
|
$base->default((keys %$labels)[0]) unless $base->default; |
48
|
0
|
|
|
|
|
|
@_; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
1; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
__END__ |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=head1 NAME |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
Egg::Model::Cache - Model for cashe. |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head1 SYNOPSIS |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
my $cahce= $e->model('cache_label'); |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
# Data is set in the cache. |
64
|
|
|
|
|
|
|
$cache->set( data_name => 'HOGE' ); |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
# Data is acquired from cashe. |
67
|
|
|
|
|
|
|
my $data= $cache->get('data_name'); |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
# Cashe is deleted. |
70
|
|
|
|
|
|
|
$cache->remove('data_name'); |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=head1 DESCRIPTION |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
It is a model to use cashe. |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
To use it, the CACHE controller is generated under the control of the project |
77
|
|
|
|
|
|
|
with the helper. |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
see L<Egg::Helper::Model::Cache>. |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
% cd /path/to/MyApp/bin |
82
|
|
|
|
|
|
|
% ./egg_helper M::Cache [MODULE_NAME] |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
The CACHE controller is set up when the project is started by this and using it |
85
|
|
|
|
|
|
|
becomes possible. |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
Two or more CACHE controllers can be used at the same time. |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=head1 HOW TO CACHE CONTROLLER |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
It is necessary to set up the cashe module used by 'setup_cache' method in the |
92
|
|
|
|
|
|
|
CACHE controller. |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
__PACKAGE__->setup_cache('Cache::FileCache'); |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
It is L<Cache::FileCache> in default, and the thing changed to an arbitrary module |
97
|
|
|
|
|
|
|
can be done. |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
The data set by the config method is passed by the constructor of all modules |
100
|
|
|
|
|
|
|
set up by 'setup_cache'. |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
When 'label_name' is set, the model call can be done by an arbitrary label name. |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
__PACKAGE__->config( |
105
|
|
|
|
|
|
|
label_name => 'mylabel', |
106
|
|
|
|
|
|
|
); |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
my $cache= $e->model('mylabel'); |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
Additionally, please construct the CACHE controller while arbitrarily adding a |
111
|
|
|
|
|
|
|
convenient code to obtain the cash data. |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=head1 METHODS |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
Please refer to L<Egg::Model::Cache::Base> for the method that the CACHE controller |
116
|
|
|
|
|
|
|
can use. |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head2 new |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
Constructor. |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
The object of the CACHE controller who default and has been treated is returned. |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
my $cache= $e->model('cache'); |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head1 SEE ALSO |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
L<Egg::Release>, |
129
|
|
|
|
|
|
|
L<Egg::Model::Cache::Base>, |
130
|
|
|
|
|
|
|
L<Egg::Helper::Model::Cache>, |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=head1 AUTHOR |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
Masatoshi Mizuno E<lt>lusheE<64>cpan.orgE<gt> |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
Copyright (C) 2008 Bee Flag, Corp. E<lt>L<http://egg.bomcity.com/>E<gt>, All Rights Reserved. |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
141
|
|
|
|
|
|
|
it under the same terms as Perl itself, either Perl version 5.8.6 or, |
142
|
|
|
|
|
|
|
at your option, any later version of Perl 5 you may have available. |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=cut |
145
|
|
|
|
|
|
|
|