Added call to set Catalyst::Plugin::Assets(File::Assets) base URI
[sgn.git] / lib / SGN.pm
blob5b24cebf18d740cfc593881470f1a8542976b58d
2 =head1 NAME
4 SGN - Catalyst-based application to run the SGN website.
6 =head1 SYNOPSIS
8 script/sgn_server.pl
10 =head1 DESCRIPTION
12 This is the main class for the Sol Genomics Network main website.
14 =cut
16 package SGN;
17 use Moose;
18 use namespace::autoclean;
20 BEGIN {
21 $ENV{WEB_PROJECT_NAME} = $ENV{PROJECT_NAME} = __PACKAGE__;
24 use SGN::Exception;
26 use Catalyst::Runtime 5.80;
28 =head1 ROLES
30 Does the roles L<SGN::Role::Site::Config>,
31 L<SGN::Role::Site::DBConnector>, L<SGN::Role::Site::DBIC>,
32 L<SGN::Role::Site::Exceptions>, L<SGN::Role::Site::Files>,
33 L<SGN::Role::Site::Mason>, L<SGN::Role::Site::SiteFeatures>,
34 L<SGN::Role::Site::TestMode>
36 =cut
38 use Catalyst qw/
39 ConfigLoader
40 Static::Simple
41 SmartURI
42 Authentication
43 Assets
44 +SGN::Authentication::Store
45 Authorization::Roles
46 +SGN::Role::Site::Config
47 +SGN::Role::Site::DBConnector
48 +SGN::Role::Site::DBIC
49 +SGN::Role::Site::Exceptions
50 +SGN::Role::Site::Files
51 +SGN::Role::Site::Mason
52 +SGN::Role::Site::SiteFeatures
53 +SGN::Role::Site::TestMode
56 extends 'Catalyst';
58 =head1 METHODS
60 =cut
62 # configure catalyst-related things. in general, things should not be
63 # added here. add them to SGN.conf, with comments.
64 __PACKAGE__->config(
66 name => 'SGN',
67 root => 'static',
69 disable_component_resolution_regex_fallback => 1,
71 default_view => 'Mason',
73 # Static::Simple configuration
74 'Plugin::Static::Simple' => {
75 dirs => [qw[ css s static img documents static_content data ]],
78 'Plugin::ConfigLoader' => {
79 substitutions => {
80 UID => sub { $> },
81 USERNAME => sub { (getpwuid($>))[0] },
82 GID => sub { $) },
83 GROUPNAME => sub { (getgrgid($)))[0] },
87 # configure SGN::Role::Site::TestMode. These are the
88 # configuration keys that it will change so that they point into
89 # t/data
90 'Plugin::TestMode' => {
91 test_data_dir => __PACKAGE__->path_to('t','data'),
92 reroot_conf =>
93 [qw(
95 blast_db_path
96 cluster_shared_tempdir
97 ftpsite_root
98 image_path
99 genefamily_dir
100 homepage_files_dir
101 intron_finder_database
102 solqtl
103 static_content_path
104 static_datasets_path
105 trace_path
110 'Plugin::Cache'=>{
111 backend => {
112 store =>"FastMmap",
118 'Plugin::Authentication' => {
119 default_realm => 'default',
120 realms => {
121 default => {
122 credential => {
123 class => '+SGN::Authentication::Credentials',
126 store => {
127 class => "+SGN::Authentication::Store",
128 user_class => "+SGN::Authentication::User",
129 ### role_column => 'roles',
135 'Plugin::Assets' => {
137 path => "/static",
140 ( $ENV{SGN_TEST_MODE} ? ( test_mode => 1 ) : () ),
144 # on startup, do some dynamic configuration
145 after 'setup_finalize' => sub {
146 my $self = shift;
148 $self->config->{basepath} = $self->config->{home};
150 # all files written by web server should be group-writable
151 umask 000002;
153 # update the symlinks used to serve static files
154 $self->_update_static_symlinks;
157 __PACKAGE__->setup;
159 sub _update_static_symlinks {
160 my $self = shift;
162 # symlink the static_datasets and
163 # static_content in the root dir so that
164 # Catalyst::Plugin::Static::Simple can serve them. in production,
165 # these will be served directly by Apache
167 # make symlinks for static_content and static_datasets
168 my @links =
169 map [ $self->config->{$_.'_path'} =>
170 $self->path_to( $self->config->{root}, $self->config->{$_.'_url'} )
172 qw( static_content static_datasets );
174 for my $link (@links) {
175 if( $self->debug ) {
176 my $l1_rel = $link->[1]->relative( $self->path_to );
177 $self->log->debug("symlinking static dir '$link->[0]' -> '$l1_rel'") if $self->debug;
179 unlink $link->[1];
180 symlink( $link->[0], $link->[1] )
181 or die "$! symlinking $link->[0] => $link->[1]";
185 =head1 SEE ALSO
187 L<SGN::Controller::Root>, L<Catalyst>
189 =head1 AUTHOR
191 The SGN team
193 =head1 LICENSE
195 This library is free software. You can redistribute it and/or modify
196 it under the same terms as Perl itself.
198 =cut