line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Starch::Factory; |
2
|
13
|
|
|
13
|
|
225
|
use 5.008001; |
|
13
|
|
|
|
|
41
|
|
3
|
13
|
|
|
13
|
|
67
|
use strictures 2; |
|
13
|
|
|
|
|
81
|
|
|
13
|
|
|
|
|
442
|
|
4
|
|
|
|
|
|
|
our $VERSION = '0.12'; |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
=head1 NAME |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
Starch::Factory - Role applicator and class creator. |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 DESCRIPTION |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
This class consumes the L role and |
13
|
|
|
|
|
|
|
is used by L to apply specified plugins to manager, |
14
|
|
|
|
|
|
|
state, and store classes. |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
Normally there is no need to interact with this class directly. |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=cut |
19
|
|
|
|
|
|
|
|
20
|
13
|
|
|
13
|
|
8671
|
use Moo::Role qw(); |
|
13
|
|
|
|
|
216566
|
|
|
13
|
|
|
|
|
393
|
|
21
|
13
|
|
|
13
|
|
1794
|
use Types::Standard -types; |
|
13
|
|
|
|
|
221952
|
|
|
13
|
|
|
|
|
125
|
|
22
|
13
|
|
|
13
|
|
62274
|
use Types::Common::String -types; |
|
13
|
|
|
|
|
69278
|
|
|
13
|
|
|
|
|
110
|
|
23
|
13
|
|
|
13
|
|
23794
|
use Moo::Object qw(); |
|
13
|
|
|
|
|
8630
|
|
|
13
|
|
|
|
|
362
|
|
24
|
13
|
|
|
13
|
|
5334
|
use Starch::Util qw( load_prefixed_module croak ); |
|
13
|
|
|
|
|
35
|
|
|
13
|
|
|
|
|
774
|
|
25
|
13
|
|
|
13
|
|
98
|
use Module::Runtime qw( require_module ); |
|
13
|
|
|
|
|
26
|
|
|
13
|
|
|
|
|
78
|
|
26
|
|
|
|
|
|
|
|
27
|
13
|
|
|
13
|
|
6119
|
use Starch::Manager; |
|
13
|
|
|
|
|
62
|
|
|
13
|
|
|
|
|
567
|
|
28
|
13
|
|
|
13
|
|
108
|
use Starch::State; |
|
13
|
|
|
|
|
26
|
|
|
13
|
|
|
|
|
304
|
|
29
|
|
|
|
|
|
|
|
30
|
13
|
|
|
13
|
|
70
|
use Moo; |
|
13
|
|
|
|
|
29
|
|
|
13
|
|
|
|
|
69
|
|
31
|
13
|
|
|
13
|
|
6193
|
use namespace::clean; |
|
13
|
|
|
|
|
39
|
|
|
13
|
|
|
|
|
109
|
|
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
with qw( |
34
|
|
|
|
|
|
|
Starch::Plugin::Bundle |
35
|
|
|
|
|
|
|
); |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=head1 OPTIONAL ARGUMENTS |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=head2 plugins |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
This is the L attribute, but altered |
42
|
|
|
|
|
|
|
to be an argument. |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=cut |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
has '+plugins' => ( |
47
|
|
|
|
|
|
|
init_arg => 'plugins', |
48
|
|
|
|
|
|
|
); |
49
|
|
|
|
|
|
|
sub bundled_plugins { |
50
|
18
|
|
|
18
|
0
|
483
|
return []; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=head2 base_manager_class |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
The base class of the Starch manager object. Default to C. |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=cut |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
has base_manager_class => ( |
60
|
|
|
|
|
|
|
is => 'lazy', |
61
|
|
|
|
|
|
|
isa => NonEmptySimpleStr, |
62
|
|
|
|
|
|
|
default => 'Starch::Manager', |
63
|
|
|
|
|
|
|
); |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=head2 base_state_class |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
The base class of Starch state objects. Default to C. |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=cut |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
has base_state_class => ( |
72
|
|
|
|
|
|
|
is => 'lazy', |
73
|
|
|
|
|
|
|
isa => NonEmptySimpleStr, |
74
|
|
|
|
|
|
|
default => 'Starch::State', |
75
|
|
|
|
|
|
|
); |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=head2 manager_class |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
The anonymous class which extends L and has |
82
|
|
|
|
|
|
|
L applied to it. |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=cut |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
has manager_class => ( |
87
|
|
|
|
|
|
|
is => 'lazy', |
88
|
|
|
|
|
|
|
isa => ClassName, |
89
|
|
|
|
|
|
|
init_arg => undef, |
90
|
|
|
|
|
|
|
); |
91
|
|
|
|
|
|
|
sub _build_manager_class { |
92
|
70
|
|
|
70
|
|
876
|
my ($self) = @_; |
93
|
|
|
|
|
|
|
|
94
|
70
|
|
|
|
|
1221
|
my $roles = $self->manager_roles(); |
95
|
70
|
|
|
|
|
3652
|
my $class = $self->base_manager_class(); |
96
|
70
|
|
|
|
|
4737
|
require_module( $class ); |
97
|
|
|
|
|
|
|
|
98
|
70
|
100
|
|
|
|
2702
|
return $class if !@$roles; |
99
|
|
|
|
|
|
|
|
100
|
23
|
|
|
|
|
126
|
return Moo::Role->create_class_with_roles( $class, @$roles ); |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=head2 state_class |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
The anonymous class which extends L and has |
106
|
|
|
|
|
|
|
L applied to it. |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=cut |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
has state_class => ( |
111
|
|
|
|
|
|
|
is => 'lazy', |
112
|
|
|
|
|
|
|
isa => ClassName, |
113
|
|
|
|
|
|
|
init_arg => undef, |
114
|
|
|
|
|
|
|
); |
115
|
|
|
|
|
|
|
sub _build_state_class { |
116
|
24
|
|
|
24
|
|
312
|
my ($self) = @_; |
117
|
|
|
|
|
|
|
|
118
|
24
|
|
|
|
|
449
|
my $roles = $self->state_roles(); |
119
|
24
|
|
|
|
|
1453
|
my $class = $self->base_state_class(); |
120
|
24
|
|
|
|
|
1442
|
require_module( $class ); |
121
|
|
|
|
|
|
|
|
122
|
24
|
100
|
|
|
|
869
|
return $class if !@$roles; |
123
|
|
|
|
|
|
|
|
124
|
11
|
|
|
|
|
52
|
return Moo::Role->create_class_with_roles( $class, @$roles ); |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=head1 METHODS |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=head2 base_store_class |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
my $class = $factory->base_store_class( '::Memory' ); |
132
|
|
|
|
|
|
|
# Starch::Store::Memory |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
my $class = $factory->base_store_class( 'Starch::Store::Memory' ); |
135
|
|
|
|
|
|
|
# Starch::Store::Memory |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
Given an absolute or relative store class name this will |
138
|
|
|
|
|
|
|
return the resolved class name. |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=cut |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
sub base_store_class { |
143
|
120
|
|
|
120
|
1
|
258
|
my ($self, $suffix) = @_; |
144
|
|
|
|
|
|
|
|
145
|
120
|
|
|
|
|
370
|
return load_prefixed_module( |
146
|
|
|
|
|
|
|
'Starch::Store', |
147
|
|
|
|
|
|
|
$suffix, |
148
|
|
|
|
|
|
|
); |
149
|
|
|
|
|
|
|
} |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=head2 store_class |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
my $class = $factory->store_class( '::Memory' ); |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
Given an absolute or relative store class name this will |
156
|
|
|
|
|
|
|
return an anonymous class which extends the store class |
157
|
|
|
|
|
|
|
and has L applied to it. |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=cut |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
sub store_class { |
162
|
120
|
|
|
120
|
1
|
281
|
my ($self, $suffix) = @_; |
163
|
|
|
|
|
|
|
|
164
|
120
|
|
|
|
|
2085
|
my $roles = $self->store_roles(); |
165
|
120
|
|
|
|
|
3252
|
my $class = $self->base_store_class( $suffix ); |
166
|
|
|
|
|
|
|
|
167
|
120
|
100
|
|
|
|
430
|
return $class if !@$roles; |
168
|
|
|
|
|
|
|
|
169
|
68
|
|
|
|
|
292
|
return Moo::Role->create_class_with_roles( $class, @$roles ); |
170
|
|
|
|
|
|
|
} |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=head2 new_store |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
my $store = $factory->new_store( class=>'::Memory', %args ); |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
Creates and returns a new L object with the |
177
|
|
|
|
|
|
|
factory argument set. |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
Note that since the L argument is |
180
|
|
|
|
|
|
|
required you must specify it. |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
=cut |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
sub new_store { |
185
|
120
|
|
|
120
|
1
|
1616
|
my $self = shift; |
186
|
|
|
|
|
|
|
|
187
|
120
|
|
|
|
|
2256
|
my $args = Moo::Object->BUILDARGS( @_ ); |
188
|
120
|
|
|
|
|
12954
|
$args = { %$args }; |
189
|
120
|
|
|
|
|
340
|
my $suffix = delete $args->{class}; |
190
|
120
|
50
|
|
|
|
376
|
croak "No class key was declared in the Starch store hash ref" |
191
|
|
|
|
|
|
|
if !defined $suffix; |
192
|
|
|
|
|
|
|
|
193
|
120
|
|
|
|
|
412
|
my $class = $self->store_class( $suffix ); |
194
|
120
|
|
|
|
|
27223
|
return $class->new( |
195
|
|
|
|
|
|
|
%$args, |
196
|
|
|
|
|
|
|
); |
197
|
|
|
|
|
|
|
} |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
1; |
200
|
|
|
|
|
|
|
__END__ |