1 package SGN
::Controller
::Root
;
3 use namespace
::autoclean
;
5 use Scalar
::Util
'weaken';
6 use CatalystX
::GlobalContext
();
9 use CXGN
::People
::Person
;
11 BEGIN { extends
'Catalyst::Controller' }
14 # Sets the actions in this controller to be registered with no prefix
15 # so they function identically to actions created in MyApp.pm
17 __PACKAGE__
->config(namespace
=> '');
21 SGN::Controller::Root - Root Controller for SGN
25 Web application to run the SGN web site.
35 sub index :Path
:Args
(0) {
36 my ( $self, $c ) = @_;
39 $c->stash->{template
} = '/index.mas';
40 $c->stash->{schema
} = $c->dbic_schema('SGN::Schema');
41 $c->stash->{static_content_path
} = $c->config->{static_content_path
};
46 Attempt to find index.pl pages, and prints standard 404 error page if
47 nothing could be found.
52 my ( $self, $c ) = @_;
54 return 1 if $c->forward('/redirects/find_redirect');
61 Render a bare mason component, with no autohandler wrapping.
62 Currently used for GBrowse integration (GBrowse makes a subrequest for
63 the mason header and footer).
67 sub bare_mason
:Path
('bare_mason') {
68 my ( $self, $c, @args ) = @_;
70 # figure out our template path
71 my $t = File
::Spec
->catfile( @args );
72 $t .= '.mas' unless $t =~ m
|\
.[^/\\\
.]+$|;
73 $c->stash->{template
} = $t;
75 # TODO: check that it exists
77 $c->forward('View::BareMason');
80 =head1 PRIVATE ACTIONS
84 Attempt to render a view, if needed.
88 sub render
: ActionClass
('RenderView') { }
90 my ( $self, $c ) = @_;
92 return if @
{$c->error};
94 # don't try to render a default view if this was handled by a CGI
95 $c->forward('render') unless $c->req->path =~ /\.pl$/;
97 # enforce a default text/html content type regardless of whether
98 # we tried to render a default view
99 $c->res->content_type('text/html') unless $c->res->content_type;
101 if( $c->res->content_type eq 'text/html' ) {
102 # insert any additional header html collected during rendering
103 $c->forward('insert_collected_html');
105 # tell caches our responses vary depending on the Cookie header
106 $c->res->headers->push_header('Vary', 'Cookie');
108 $c->log->debug("skipping JS pack insertion for page with content type ".$c->res->content_type)
114 sub insert_collected_html
:Private
{
115 my ( $self, $c ) = @_;
117 $c->forward('/js/resolve_javascript_classes');
119 my $b = $c->res->body;
120 my $inserted_head_pre = $b && $b =~ s{<!-- \s* INSERT_HEAD_PRE_HTML \s* --> }{ $self->_make_head_pre_html( $c ) }ex;
121 my $inserted_head_post = $b && $b =~ s{<!-- \s* INSERT_HEAD_POST_HTML \s* -->}{ $self->_make_head_post_html( $c ) }ex;
122 if( $inserted_head_pre || $inserted_head_post ) {
125 # we have changed the size of the body. remove the
126 # content-length and let catalyst recalculate the content-length
128 $c->res->headers->remove_header('content-length');
130 delete $c->stash->{$_} for qw( add_head_html add_css_files add_js_classes );
134 sub _make_head_pre_html
{
135 my ( $self, $c ) = @_;
136 return join "\n", @
{ $c->stash->{head_pre_html
} || [] };
139 sub _make_head_post_html
{
140 my ( $self, $c ) = @_;
142 my $head_post_html = join "\n", (
143 @
{ $c->stash->{add_head_html
} || [] },
145 qq{<link rel
="stylesheet" type
="text/css" href
="$_" />}
146 } @
{ $c->stash->{css_uris
} || [] }
149 qq{<script src
="$_" type
="text/javascript"></script
>}
150 } @
{ $c->stash->{js_uris
} || [] }
154 return $head_post_html;
159 Run for every request to the site.
165 CatalystX
::GlobalContext
->set_context( $c );
167 weaken
$c->stash->{c
};
169 # gluecode for logins
171 unless( $c->config->{'disable_login'} ) {
172 my $dbh = $c->dbc->dbh;
173 if ( my $sp_person_id = CXGN
::Login
->new( $dbh )->has_session ) {
175 my $sp_person = CXGN
::People
::Person
->new( $dbh, $sp_person_id);
178 username
=> $sp_person->get_username(),
179 password
=> $sp_person->get_password(),
189 ############# helper methods ##########
191 sub _find_cgi_action
{
192 my ($self,$c,$path) = @_;
195 my $cgi = $c->controller('CGI')
198 my $index_action = $cgi->cgi_action_for( $path )
201 $c->log->debug("found CGI index action '$index_action'") if $c->debug;
203 return $index_action;
208 Robert Buels, Jonathan "Duke" Leto
212 This library is free software. You can redistribute it and/or modify
213 it under the same terms as Perl itself.
217 __PACKAGE__
->meta->make_immutable;