3 SGN::Role::Site::SiteFeatures - role for a context class that lets it find, load, and configure SGN::Feature objects
7 package SGN
::Role
::Site
::SiteFeatures
;
12 use Module
::Pluggable
::Object
;
13 use namespace
::autoclean
;
18 after
'setup_finalize' => sub {
20 $class->_features; #< build features
21 $class->setup_features;
24 # lazy accessor, returns arrayref of instantiated and configured
25 # SGN::Feature objects
28 $class = ref $class if ref $class;
29 state %feature_objects;
30 $feature_objects{$class} ||= do {
31 $class->_build__features;
36 values %{ shift->_features }
40 shift->_features->{+shift};
44 shift->config->{name
};
47 sub _build__features
{
50 Module
::Pluggable
::Object
51 ->new( 'search_path' => ['SGN::Feature'],
57 foreach my $class (@feature_classes) {
58 my $cfg = $self->config->{feature
}{$class} || {};
59 if (ref($cfg) eq "HASH" && exists($cfg->{enabled
}) && defined($cfg->{enabled
}) ) {
61 my $f = $class->new( %$cfg,
64 $feature_objects{$f->feature_name} = $f;
66 warn "WARNING: failed to configure $class : $_";
71 return \
%feature_objects;
76 $_->setup( $class ) for $class->enabled_features;
79 sub enabled_features
{
84 my $f = shift->feature(lc shift)
86 return unless $f->enabled;
91 my ( $c, $query, $args ) = @_;
93 my @f = $c->enabled_features;
94 if( my $ex = $args->{exclude
} ) {
95 $ex = [ $ex ] unless ref $ex;
96 my %ex = map { $_ => 1 } @
$ex;
97 @f = grep !$ex{$_->feature_name}, @f;
99 return map $_->xrefs( $query, $args ), @f;