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');
45 Attempt to find index.pl pages, and prints standard 404 error page if
46 nothing could be found.
51 my ( $self, $c ) = @_;
53 return 1 if $self->_do_redirects($c);
60 Render a bare mason component, with no autohandler wrapping.
61 Currently used for GBrowse integration (GBrowse makes a subrequest for
62 the mason header and footer).
66 sub bare_mason
:Path
('bare_mason') {
67 my ( $self, $c, @args ) = @_;
69 # figure out our template path
70 my $t = File
::Spec
->catfile( @args );
71 $t .= '.mas' unless $t =~ m
|\
.[^/\\\
.]+$|;
72 $c->stash->{template
} = $t;
74 # TODO: check that it exists
76 $c->forward('View::BareMason');
79 =head1 PRIVATE ACTIONS
83 Attempt to render a view, if needed.
87 sub render
: ActionClass
('RenderView') { }
89 my ( $self, $c ) = @_;
91 return if @
{$c->error};
93 # don't try to render a default view if this was handled by a CGI
94 $c->forward('render') unless $c->req->path =~ /\.pl$/;
96 # enforce a default text/html content type regardless of whether
97 # we tried to render a default view
98 $c->res->content_type('text/html') unless $c->res->content_type;
100 # insert our javascript packages into the rendered view
101 if( $c->res->content_type eq 'text/html' ) {
102 $c->forward('/js/insert_js_pack_html');
103 $c->res->headers->push_header('Vary', 'Cookie');
105 $c->log->debug("skipping JS pack insertion for page with content type ".$c->res->content_type)
113 Run for every request to the site.
119 CatalystX
::GlobalContext
->set_context( $c );
121 weaken
$c->stash->{c
};
123 # gluecode for logins
125 unless( $c->config->{'disable_login'} ) {
126 my $dbh = $c->dbc->dbh;
127 if ( my $sp_person_id = CXGN
::Login
->new( $dbh )->has_session ) {
129 my $sp_person = CXGN
::People
::Person
->new( $dbh, $sp_person_id);
132 username
=> $sp_person->get_username(),
133 password
=> $sp_person->get_password(),
143 ########### helper methods ##########3
147 my $path = $c->req->path;
148 my $query = $c->req->uri->query || '';
149 $query = "?$query" if $query;
151 $c->log->debug("searching for redirects ($path) ($query)") if $c->debug;
153 # if the path has multiple // in it, collapse them and redirect to
155 if( $path =~ s!/{2,}!/!g ) {
156 $c->log->debug("redirecting multi-/ request to /$path$query") if $c->debug;
157 $c->res->redirect( "/$path$query", 301 );
161 # try an internal redirect for index.pl files if the url has not
162 # already been found and does not have an extension
163 if( $path !~ m
|\
.\w
{2,4}$| ) {
164 if( my $index_action = $self->_find_cgi_action( $c, "$path/index.pl" ) ) {
165 $c->log->debug("redirecting to action $index_action") if $c->debug;
166 my $uri = $c->uri_for_action($index_action, $c->req->query_parameters)
167 ->rel( $c->uri_for('/') );
168 $c->res->redirect( "/$uri", 302 );
173 # redirect away from cgi-bin URLs
174 elsif( $path =~ s!cgi-bin/!! ) {
175 $c->log->debug("redirecting cgi-bin url to /$path$query") if $c->debug;
176 $c->res->redirect( "/$path$query", 301 );
183 ############# helper subs ##########
185 sub _find_cgi_action
{
186 my ($self,$c,$path) = @_;
189 my $cgi = $c->controller('CGI')
192 my $index_action = $cgi->cgi_action_for( $path )
195 $c->log->debug("found CGI index action '$index_action'") if $c->debug;
197 return $index_action;
202 Robert Buels, Jonathan "Duke" Leto
206 This library is free software. You can redistribute it and/or modify
207 it under the same terms as Perl itself.
211 __PACKAGE__
->meta->make_immutable;