$Starch::Plugin::Bundle::VERSION
=
'0.07'
;
requires(
'bundled_plugins'
);
sub
_roles_for {
my
(
$self
,
$prefix
) =
@_
;
my
$for_role
=
"Starch::Plugin::For$prefix"
;
my
@roles
;
foreach
my
$role
(@{
$self
->roles() }) {
next
if
!Moo::Role::does_role(
$role
,
$for_role
);
push
@roles
,
$role
;
}
return
\
@roles
;
}
has
plugins
=> (
is
=>
'lazy'
,
isa
=> ArrayRef[ Str ],
init_arg
=>
undef
,
builder
=>
'bundled_plugins'
,
);
has
resolved_plugins
=> (
is
=>
'lazy'
,
isa
=> ArrayRef[ NonEmptySimpleStr ],
init_arg
=>
undef
,
);
sub
_build_resolved_plugins {
my
(
$self
) =
@_
;
my
@plugins
;
foreach
my
$plugin
(@{
$self
->plugins() }) {
push
@plugins
, load_prefixed_module(
'Starch::Plugin'
,
$plugin
,
);
}
return
\
@plugins
;
}
has
roles
=> (
is
=>
'lazy'
,
isa
=> ArrayRef[ NonEmptySimpleStr ],
init_arg
=>
undef
,
);
sub
_build_roles {
my
(
$self
) =
@_
;
my
@roles
;
foreach
my
$plugin
(@{
$self
->resolved_plugins() }) {
if
(Moo::Role::does_role(
$plugin
,
'Starch::Plugin::Bundle'
)) {
die
"Plugin bundle $plugin is not a class"
if
!
$plugin
->can(
'new'
);
my
$bundle
=
$plugin
->new();
push
@roles
, @{
$bundle
->roles() };
}
else
{
die
"Plugin $plugin does not look like a role"
if
$plugin
->can(
'new'
);
push
@roles
,
$plugin
;
}
}
return
\
@roles
;
}
has
manager_roles
=> (
is
=>
'lazy'
,
isa
=> ArrayRef[ NonEmptySimpleStr ],
init_arg
=>
undef
,
);
sub
_build_manager_roles {
my
(
$self
) =
@_
;
return
$self
->_roles_for(
'Manager'
);
}
has
state_roles
=> (
is
=>
'lazy'
,
isa
=> ArrayRef[ NonEmptySimpleStr ],
init_arg
=>
undef
,
);
sub
_build_state_roles {
my
(
$self
) =
@_
;
return
$self
->_roles_for(
'State'
);
}
has
store_roles
=> (
is
=>
'lazy'
,
isa
=> ArrayRef[ NonEmptySimpleStr ],
init_arg
=>
undef
,
);
sub
_build_store_roles {
my
(
$self
) =
@_
;
return
$self
->_roles_for(
'Store'
);
}
1;