can download plant phenotype data in the same way as plot phenotype data
[sgn.git] / lib / SGN / Role / Site / Mason.pm
blob076a1a616b31d7e6d1f4933e3ea37f5ee3c9183b
1 package SGN::Role::Site::Mason;
3 use Moose::Role;
4 use namespace::autoclean;
6 use Carp;
7 use File::Basename;
8 use File::Path;
9 use Path::Class;
10 use Scalar::Util qw/blessed/;
12 use HTML::Mason::Interp;
14 requires
15 qw(
16 path_to
17 get_conf
18 tempfiles_subdir
19 setup_finalize
22 =head2 forward_to_mason_view
24 Deprecated. Do not use in new code.
26 =cut
28 # forward_to_mason_view
30 # Usage: $c->forward_to_mason_view( '/some/thing', foo => 'bar' );
31 # Desc : call a Mason view with the given arguments and exit
32 # Args : mason component name (with or without .mas extension),
33 # hash-style list of arguments for the mason component
34 # Ret : nothing. terminates the program afterward.
35 # Side Effects: exits after calling the component
37 # This replaces CXGN::MasonFactory->new->exec( ... )
39 sub forward_to_mason_view {
40 my $self = shift;
41 my ($comp,@args) = @_;
43 if( $ENV{SERVER_SOFTWARE} && $ENV{SERVER_SOFTWARE} =~ /HTTP-Request-AsCGI/ ) {
44 print $self->view('Mason')->render( $self, $comp, { %{$self->stash}, @args} );
45 die ["EXIT\n",0]; #< weird thing for working with Catalyst's CGIBin controller
46 } else {
47 croak "forward_to_mason_view is deprecated, and only works in CGI scripts";
52 =head2 render_mason
54 Usage: my $string = $c->render_mason( '/page/page_title',
55 title => 'My Page' );
56 Desc : call a Mason component without any autohandlers, just
57 render the component and return its output as a string
58 Args : mason component name (with or without .mas),
59 hash-style list of component arguments
60 Ret : string of component's output
61 Side Effects: none for this function, but the component could
62 access the database, or whatnot
63 Example :
65 print '<div>Blah blah: '.$c->render_mason('/foo').'</div>';
67 =cut
69 sub render_mason {
70 my $self = shift;
71 my $view = shift;
73 return $self->view('BareMason')->render( $self, $view, { %{$self->stash}, @_ } );
76 =head2 clear_mason_tempfiles
78 Usage: $c->clear_mason_tempfiles
79 Desc : delete mason cached tempfiles to force mason components to
80 reload. in normal operation, called only on server restart
81 Args : none
82 Ret : nothing meaningful
83 Side Effects: dies on error
84 Example :
86 This is run at app startup as a setup_finalize hook.
88 =cut
90 after 'setup_finalize' => \&clear_mason_tempfiles;
92 sub clear_mason_tempfiles {
93 my ( $self ) = @_;
95 for my $temp ( $self->path_to( $self->tempfiles_subdir() )->children ) {
96 rmtree( "$temp" ) if -d $temp && basename("$temp") =~ /^mason_cache_/;