line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Starch::Plugin::Bundle; |
2
|
13
|
|
|
13
|
|
6914
|
use 5.008001; |
|
13
|
|
|
|
|
47
|
|
3
|
13
|
|
|
13
|
|
221
|
use strictures 2; |
|
13
|
|
|
|
|
114
|
|
|
13
|
|
|
|
|
527
|
|
4
|
|
|
|
|
|
|
our $VERSION = '0.11'; |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
=head1 NAME |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
Starch::Plugin::Bundle - Base role for Starch plugin bundles. |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 SYNOPSIS |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
# Create a bundle. |
13
|
|
|
|
|
|
|
package MyDevPlugins; |
14
|
|
|
|
|
|
|
use Moo; |
15
|
|
|
|
|
|
|
with 'Starch::Plugin::Bundle'; |
16
|
|
|
|
|
|
|
sub bundled_plugins { |
17
|
|
|
|
|
|
|
return ['::Trace', 'MyApp::Starch::CustomPLugin']; |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
# Use the bundle. |
21
|
|
|
|
|
|
|
my $starch = Starch->new( |
22
|
|
|
|
|
|
|
plugins => ['MyDevPlugin'], |
23
|
|
|
|
|
|
|
..., |
24
|
|
|
|
|
|
|
); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=head1 DESCRIPTION |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
Plugin bundles package together any number of other plugins and plugin |
29
|
|
|
|
|
|
|
bundles. To create a plugin bundle just make a new class that consumes |
30
|
|
|
|
|
|
|
this role and defines the C method. This method |
31
|
|
|
|
|
|
|
should return an array ref of plugin names (absolute or relative). |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
See L for more information. |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=cut |
36
|
|
|
|
|
|
|
|
37
|
13
|
|
|
13
|
|
3060
|
use Types::Standard -types; |
|
13
|
|
|
|
|
29
|
|
|
13
|
|
|
|
|
113
|
|
38
|
13
|
|
|
13
|
|
60582
|
use Types::Common::String -types; |
|
13
|
|
|
|
|
31
|
|
|
13
|
|
|
|
|
102
|
|
39
|
13
|
|
|
13
|
|
18695
|
use Starch::Util qw( load_prefixed_module ); |
|
13
|
|
|
|
|
30
|
|
|
13
|
|
|
|
|
707
|
|
40
|
|
|
|
|
|
|
|
41
|
13
|
|
|
13
|
|
87
|
use Moo::Role; |
|
13
|
|
|
|
|
55
|
|
|
13
|
|
|
|
|
93
|
|
42
|
13
|
|
|
13
|
|
5630
|
use namespace::clean; |
|
13
|
|
|
|
|
26
|
|
|
13
|
|
|
|
|
77
|
|
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
requires( 'bundled_plugins' ); |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub _roles_for { |
47
|
164
|
|
|
164
|
|
443
|
my ($self, $prefix) = @_; |
48
|
|
|
|
|
|
|
|
49
|
164
|
|
|
|
|
421
|
my $for_role = "Starch::Plugin::For$prefix"; |
50
|
|
|
|
|
|
|
|
51
|
164
|
|
|
|
|
287
|
my @roles; |
52
|
164
|
|
|
|
|
264
|
foreach my $role (@{ $self->roles() }) { |
|
164
|
|
|
|
|
2645
|
|
53
|
213
|
100
|
|
|
|
4087
|
next if !Moo::Role::does_role( $role, $for_role ); |
54
|
77
|
|
|
|
|
1351
|
push @roles, $role; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
164
|
|
|
|
|
4850
|
return \@roles; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=head2 plugins |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
This returns the array ref of plugins provided by the |
65
|
|
|
|
|
|
|
C method. |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=cut |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
has plugins => ( |
70
|
|
|
|
|
|
|
is => 'lazy', |
71
|
|
|
|
|
|
|
isa => ArrayRef[ Str ], |
72
|
|
|
|
|
|
|
init_arg => undef, |
73
|
|
|
|
|
|
|
builder => 'bundled_plugins', |
74
|
|
|
|
|
|
|
); |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head2 resolved_plugins |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
This returns L with all relative plugin names made |
79
|
|
|
|
|
|
|
absolute. |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=cut |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
has resolved_plugins => ( |
84
|
|
|
|
|
|
|
is => 'lazy', |
85
|
|
|
|
|
|
|
isa => ArrayRef[ NonEmptySimpleStr ], |
86
|
|
|
|
|
|
|
init_arg => undef, |
87
|
|
|
|
|
|
|
); |
88
|
|
|
|
|
|
|
sub _build_resolved_plugins { |
89
|
92
|
|
|
92
|
|
881
|
my ($self) = @_; |
90
|
|
|
|
|
|
|
|
91
|
92
|
|
|
|
|
186
|
my @plugins; |
92
|
92
|
|
|
|
|
154
|
foreach my $plugin (@{ $self->plugins() }) { |
|
92
|
|
|
|
|
1478
|
|
93
|
111
|
|
|
|
|
1800
|
push @plugins, load_prefixed_module( |
94
|
|
|
|
|
|
|
'Starch::Plugin', |
95
|
|
|
|
|
|
|
$plugin, |
96
|
|
|
|
|
|
|
); |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
92
|
|
|
|
|
2438
|
return \@plugins; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=head2 roles |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
Returns L with all plugin bundles expanded to |
105
|
|
|
|
|
|
|
their roles. |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=cut |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
has roles => ( |
110
|
|
|
|
|
|
|
is => 'lazy', |
111
|
|
|
|
|
|
|
isa => ArrayRef[ NonEmptySimpleStr ], |
112
|
|
|
|
|
|
|
init_arg => undef, |
113
|
|
|
|
|
|
|
); |
114
|
|
|
|
|
|
|
sub _build_roles { |
115
|
92
|
|
|
92
|
|
956
|
my ($self) = @_; |
116
|
|
|
|
|
|
|
|
117
|
92
|
|
|
|
|
179
|
my @roles; |
118
|
|
|
|
|
|
|
|
119
|
92
|
|
|
|
|
138
|
foreach my $plugin (@{ $self->resolved_plugins() }) { |
|
92
|
|
|
|
|
1561
|
|
120
|
111
|
100
|
|
|
|
3531
|
if (Moo::Role::does_role( $plugin, 'Starch::Plugin::Bundle')) { |
121
|
22
|
50
|
|
|
|
656
|
die "Plugin bundle $plugin is not a class" |
122
|
|
|
|
|
|
|
if !$plugin->can('new'); |
123
|
|
|
|
|
|
|
|
124
|
22
|
|
|
|
|
376
|
my $bundle = $plugin->new(); |
125
|
22
|
|
|
|
|
4600
|
push @roles, @{ $bundle->roles() }; |
|
22
|
|
|
|
|
373
|
|
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
else { |
128
|
89
|
50
|
|
|
|
2402
|
die "Plugin $plugin does not look like a role" |
129
|
|
|
|
|
|
|
if $plugin->can('new'); |
130
|
|
|
|
|
|
|
|
131
|
89
|
|
|
|
|
251
|
push @roles, $plugin; |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
|
135
|
92
|
|
|
|
|
3448
|
return \@roles; |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=head2 manager_roles |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
Of the L this returns the ones that consume the |
141
|
|
|
|
|
|
|
L role. |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=cut |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
has manager_roles => ( |
146
|
|
|
|
|
|
|
is => 'lazy', |
147
|
|
|
|
|
|
|
isa => ArrayRef[ NonEmptySimpleStr ], |
148
|
|
|
|
|
|
|
init_arg => undef, |
149
|
|
|
|
|
|
|
); |
150
|
|
|
|
|
|
|
sub _build_manager_roles { |
151
|
70
|
|
|
70
|
|
817
|
my ($self) = @_; |
152
|
|
|
|
|
|
|
|
153
|
70
|
|
|
|
|
233
|
return $self->_roles_for('Manager'); |
154
|
|
|
|
|
|
|
} |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=head2 state_roles |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
Of the L this returns the ones that consume the |
159
|
|
|
|
|
|
|
L role. |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=cut |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
has state_roles => ( |
164
|
|
|
|
|
|
|
is => 'lazy', |
165
|
|
|
|
|
|
|
isa => ArrayRef[ NonEmptySimpleStr ], |
166
|
|
|
|
|
|
|
init_arg => undef, |
167
|
|
|
|
|
|
|
); |
168
|
|
|
|
|
|
|
sub _build_state_roles { |
169
|
24
|
|
|
24
|
|
285
|
my ($self) = @_; |
170
|
|
|
|
|
|
|
|
171
|
24
|
|
|
|
|
82
|
return $self->_roles_for('State'); |
172
|
|
|
|
|
|
|
} |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=head2 store_roles |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
Of the L this returns the ones that consume the |
177
|
|
|
|
|
|
|
L role. |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=cut |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
has store_roles => ( |
182
|
|
|
|
|
|
|
is => 'lazy', |
183
|
|
|
|
|
|
|
isa => ArrayRef[ NonEmptySimpleStr ], |
184
|
|
|
|
|
|
|
init_arg => undef, |
185
|
|
|
|
|
|
|
); |
186
|
|
|
|
|
|
|
sub _build_store_roles { |
187
|
70
|
|
|
70
|
|
788
|
my ($self) = @_; |
188
|
|
|
|
|
|
|
|
189
|
70
|
|
|
|
|
192
|
return $self->_roles_for('Store'); |
190
|
|
|
|
|
|
|
} |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
1; |
193
|
|
|
|
|
|
|
__END__ |