Merge pull request #5230 from solgenomics/topic/open_pollinated
[sgn.git] / lib / SGN / View / Mason.pm
blob57e04eece242aea3980f24fe7d11799a43dc90d7
1 =head1 NAME
3 SGN::View::Mason - Mason View Component for SGN
5 =head1 DESCRIPTION
7 Mason View Component for SGN. This extends Catalyst::View::HTML::Mason.
9 =cut
11 package SGN::View::Mason;
12 use Moose;
13 use Moose::Util::TypeConstraints;
14 use namespace::autoclean;
16 extends 'Catalyst::View::HTML::Mason';
17 with 'Catalyst::Component::ApplicationAttribute';
19 __PACKAGE__->config(
20 globals => ['$c'],
21 template_extension => '.mas',
22 interp_args => {
23 data_dir => SGN->tempfiles_base->subdir('mason'),
24 comp_root => [
25 [ main => SGN->path_to('mason') ],
27 preamble => "use utf8; ",
31 =head1 CONFIGURATION SETTINGS (which are also accessors)
33 =head2 add_comp_root
35 Configurable arrayref of additional Mason component roots. These will
36 be searched before the default ones. Must be absolute paths.
38 =cut
40 # munges the interp_args comp_root to include the add_comp_root
41 # configuration, plus the comp roots for SiteFeatures
42 sub COMPONENT {
43 my ( $class, $c, $args ) = @_;
45 $args = $class->merge_config_hashes( $class->config, $args );
47 # coerce add_comp_root to arrayref
48 if( $args->{add_comp_root} && ! ref $args->{add_comp_root} ) {
49 $args->{add_comp_root} = [ $args->{add_comp_root} ];
52 # add comp roots for features and add_comp_root
53 unshift @{ $args->{interp_args}->{comp_root} }, (
54 # add_comp_root
55 ( map [ additional => $_ ], @{ $args->{add_comp_root} || [] } ),
56 # SiteFeatures
57 ( map [ $_->feature_name, $_->path_to('mason')], $c->features ),
60 return $class->new($c, $args);
63 =head1 FUNCTIONS
65 =head2 $self->component_exists($component)
67 Check if a Mason component exists. Returns 1 if the component exists, otherwise 0.
70 =cut
72 sub component_exists {
73 my ( $self, $component ) = @_;
75 return $self->interp->comp_exists( $component ) ? 1 : 0;
78 =head1 SEE ALSO
80 L<SGN>, L<HTML::Mason>, L<Catalyst::View::HTML::Mason>
82 =head1 AUTHORS
84 Robert Buels, Jonathan "Duke" Leto
86 =head1 LICENSE
88 This library is free software . You can redistribute it and/or modify it under
89 the same terms as perl itself.
91 =cut
93 __PACKAGE__->meta->make_immutable;