Merge remote-tracking branch 'origin/topic/stock_search'
[sgn.git] / lib / SGN / Feature.pm
blob2ccbe4bacca6e2819617a4517e2eaa2cd87e887b
1 package SGN::Feature;
2 use Moose;
4 use namespace::autoclean;
5 use File::Spec;
7 # our context object
8 has 'context' => (
9 documentation => 'our context class',
11 is => 'ro',
12 does => 'SGN::Role::Site::SiteFeatures',
13 required => 1,
14 weak_ref => 1,
16 has 'enabled' => (
17 documentation => 'boolean flag, whether this feature is enabled',
19 is => 'ro',
20 isa => 'Bool',
21 default => 0,
24 sub feature_name {
25 my $self = shift;
26 my $name = ref( $self ) || $self;
27 $name =~ s/.+:://;
28 return lc $name;
31 has 'description' => (
32 documentation => <<'',
33 short plaintext description of the feature, user-visible. May be used in default views for crossreferences and so forth.
35 is => 'ro',
36 isa => 'Str',
37 default => sub { ucfirst shift->feature_name },
40 has 'feature_dir' => (
41 is => 'ro',
42 isa => 'Path::Class::Dir',
43 coerce => 1,
44 lazy_build => 1,
45 ); sub _build_feature_dir {
46 my $self = shift;
47 return $self->context->path_to( 'features', $self->feature_name )->stringify;
50 sub path_to {
51 my $self = shift;
52 return File::Spec->catfile( $self->feature_dir, @_ );
55 sub tmpdir {
56 my $self = shift;
57 return $self->context->tempfiles_base->subdir( 'features', $self->feature_name );
60 # called on application restart
61 sub setup {
64 # return one or more SGN::SiteFeature::CrossReference objects for the
65 # given input (input can be anything) or nothing if the query is not
66 # handled by this Feature. note that a CrossReference object should
67 # always be returned, it just might be empty
68 sub xrefs {
71 sub apache_conf {
72 return ''
75 __PACKAGE__->meta->make_immutable;