line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Curio::Role; |
2
|
|
|
|
|
|
|
our $VERSION = '0.11'; |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
=encoding utf8 |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
=head1 NAME |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
Curio::Role - Role for Curio classes. |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 DESCRIPTION |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
This L provides various shortcut methods for interacting |
13
|
|
|
|
|
|
|
witht the underlying L object. |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=cut |
16
|
|
|
|
|
|
|
|
17
|
11
|
|
|
11
|
|
11303
|
use Curio::Factory; |
|
11
|
|
|
|
|
34
|
|
|
11
|
|
|
|
|
398
|
|
18
|
11
|
|
|
11
|
|
79
|
use Curio::Util; |
|
11
|
|
|
|
|
20
|
|
|
11
|
|
|
|
|
561
|
|
19
|
11
|
|
|
11
|
|
68
|
use Package::Stash; |
|
11
|
|
|
|
|
18
|
|
|
11
|
|
|
|
|
206
|
|
20
|
|
|
|
|
|
|
|
21
|
11
|
|
|
11
|
|
4677
|
use Moo::Role; |
|
11
|
|
|
|
|
75670
|
|
|
11
|
|
|
|
|
66
|
|
22
|
11
|
|
|
11
|
|
3596
|
use strictures 2; |
|
11
|
|
|
|
|
90
|
|
|
11
|
|
|
|
|
468
|
|
23
|
11
|
|
|
11
|
|
2057
|
use namespace::clean; |
|
11
|
|
|
|
|
25
|
|
|
11
|
|
|
|
|
83
|
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
my %is_exporter_setup; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub import { |
28
|
7
|
|
|
7
|
|
3007
|
my ($class) = @_; |
29
|
|
|
|
|
|
|
|
30
|
7
|
|
|
|
|
19
|
my $factory = $class->factory(); |
31
|
7
|
50
|
|
|
|
21
|
return if !$factory; |
32
|
|
|
|
|
|
|
|
33
|
7
|
|
|
|
|
134
|
my $name = $factory->export_function_name(); |
34
|
7
|
50
|
|
|
|
45
|
return if !defined $name; |
35
|
|
|
|
|
|
|
|
36
|
7
|
100
|
|
|
|
19
|
if (!$is_exporter_setup{ $class }) { |
37
|
6
|
|
|
|
|
49
|
my $stash = Package::Stash->new( $class ); |
38
|
|
|
|
|
|
|
|
39
|
6
|
100
|
|
|
|
109
|
$stash->add_symbol( |
|
|
100
|
|
|
|
|
|
40
|
|
|
|
|
|
|
"&$name", |
41
|
|
|
|
|
|
|
$factory->export_resource() |
42
|
|
|
|
|
|
|
? subname( $name, _build_export_resource( $factory ) ) |
43
|
|
|
|
|
|
|
: subname( $name, _build_export_curio( $factory ) ), |
44
|
|
|
|
|
|
|
) if !$class->can($name); |
45
|
|
|
|
|
|
|
|
46
|
6
|
100
|
|
|
|
100
|
$stash->add_symbol( |
47
|
|
|
|
|
|
|
$factory->always_export() ? '@EXPORT' : '@EXPORT_OK', |
48
|
|
|
|
|
|
|
[ $name ], |
49
|
|
|
|
|
|
|
); |
50
|
|
|
|
|
|
|
|
51
|
6
|
|
|
|
|
81
|
$is_exporter_setup{ $class } = 1; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
7
|
|
|
|
|
2473
|
goto &Exporter::import; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub _build_export_curio { |
58
|
2
|
|
|
2
|
|
16
|
my $factory = shift; |
59
|
2
|
|
|
3
|
|
30
|
return sub{ $factory->fetch_curio( @_ ) }; |
|
3
|
|
|
4
|
|
366
|
|
|
|
|
|
3
|
|
|
|
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub _build_export_resource { |
63
|
2
|
|
|
2
|
|
22
|
my $factory = shift; |
64
|
2
|
|
|
3
|
|
28
|
return sub{ $factory->fetch_resource( @_ ) }; |
|
3
|
|
|
|
|
113
|
|
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=head1 CLASS METHODS |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=head2 fetch |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
my $curio = Some::Curio::Class->fetch(); |
72
|
|
|
|
|
|
|
my $curio = Some::Curio::Class->fetch( $key ); |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
This proxies to L. |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=cut |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
# The real fetch method is installed in the curio class by: |
79
|
|
|
|
|
|
|
# Curio::Factory::_install_fetch_method() |
80
|
0
|
|
|
2
|
1
|
0
|
sub fetch { undef } |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head2 find_curio |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
my $curio_object = MyApp::Service::Cache->find_curio( $resource ); |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
This proxies to L. |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=cut |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub find_curio { |
91
|
0
|
|
|
0
|
1
|
0
|
my $class = shift; |
92
|
0
|
|
|
|
|
0
|
return $class->factory->find_curio(); |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head2 inject |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
MyApp::Service::Cache->inject( $curio_object ); |
98
|
|
|
|
|
|
|
MyApp::Service::Cache->inject( $key, $curio_object ); |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
This proxies to L. |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=cut |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
sub inject { |
105
|
2
|
|
|
2
|
1
|
4
|
my $class = shift; |
106
|
2
|
|
|
|
|
6
|
return $class->factory->inject( @_ ); |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=head2 inject_with_guard |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
my $guard = MyApp::Service::Cache->inject_with_guard( |
112
|
|
|
|
|
|
|
$curio_object, |
113
|
|
|
|
|
|
|
); |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
my $guard = MyApp::Service::Cache->inject_with_guard( |
116
|
|
|
|
|
|
|
$key, $curio_object, |
117
|
|
|
|
|
|
|
); |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
This proxies to L. |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=cut |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
sub inject_with_guard { |
124
|
1
|
|
|
1
|
1
|
3
|
my $class = shift; |
125
|
1
|
|
|
|
|
3
|
return $class->factory->inject_with_guard( @_ ); |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=head2 clear_injection |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
my $curio_object = MyApp::Service::Cache->clear_injection(); |
131
|
|
|
|
|
|
|
my $curio_object = MyApp::Service::Cache->clear_injection( $key ); |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
This proxies to L. |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=cut |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
sub clear_injection { |
138
|
2
|
|
|
2
|
1
|
4
|
my $class = shift; |
139
|
2
|
|
|
|
|
8
|
return $class->factory->clear_injection( @_ ); |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=head2 injection |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
my $curio_object = MyApp::Service::Cache->injection(); |
145
|
|
|
|
|
|
|
my $curio_object = MyApp::Service::Cache->injection( $key ); |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
This proxies to L. |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=cut |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
sub injection { |
152
|
6
|
|
|
6
|
1
|
49
|
my $class = shift; |
153
|
6
|
|
|
|
|
15
|
return $class->factory->injection( @_ ); |
154
|
|
|
|
|
|
|
} |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=head2 has_injection |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
if (MyApp::Service::Cache->has_injection()) { ... } |
159
|
|
|
|
|
|
|
if (MyApp::Service::Cache->has_injection( $key )) { ... } |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
This proxies to L. |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=cut |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
sub has_injection { |
166
|
0
|
|
|
0
|
1
|
0
|
my $class = shift; |
167
|
0
|
|
|
|
|
0
|
return $class->factory->has_injection( @_ ); |
168
|
|
|
|
|
|
|
} |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=head2 initialize |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
Sets up your class's L object and is automatically |
173
|
|
|
|
|
|
|
called when you C |
174
|
|
|
|
|
|
|
directly by end-user code. |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=cut |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
sub initialize { |
179
|
35
|
|
|
35
|
1
|
635
|
Curio::Factory->new( class => shift ); |
180
|
35
|
|
|
|
|
88
|
return; |
181
|
|
|
|
|
|
|
} |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=head1 CLASS ATTRIBUTES |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
=head2 factory |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
my $factory = MyApp::Service::Cache->factory(); |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
Returns the class's L object. |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
=cut |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
# The real factory attribute is installed in the curio class by: |
194
|
|
|
|
|
|
|
# Curio::Factory::_install_factory_method() |
195
|
2
|
|
|
2
|
1
|
7470
|
sub factory { undef } |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
=head2 declared_keys |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
my $keys = MyApp::Service::Cache->declared_keys(); |
200
|
|
|
|
|
|
|
foreach my $key (@$keys) { ... } |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
This proxies to L. |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
=cut |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
sub declared_keys { |
207
|
0
|
|
|
0
|
1
|
|
my $class = shift; |
208
|
0
|
|
|
|
|
|
return $class->factory->declared_keys( @_ ); |
209
|
|
|
|
|
|
|
} |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
1; |
212
|
|
|
|
|
|
|
__END__ |