minor editorial changes.
[sgn.git] / lib / SGN.pm
blob79b1abc898b9160231bbecc48832a55127523d75
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 Authentication
42 +SGN::Authentication::Store
43 Authorization::Roles
44 +SGN::Role::Site::Config
45 +SGN::Role::Site::DBConnector
46 +SGN::Role::Site::DBIC
47 +SGN::Role::Site::Exceptions
48 +SGN::Role::Site::Files
49 +SGN::Role::Site::Mason
50 +SGN::Role::Site::SiteFeatures
51 +SGN::Role::Site::TestMode
54 extends 'Catalyst';
56 =head1 METHODS
58 =cut
60 # configure catalyst-related things. in general, things should not be
61 # added here. add them to SGN.conf, with comments.
62 __PACKAGE__->config(
64 name => 'SGN',
65 root => 'static',
67 disable_component_resolution_regex_fallback => 1,
69 default_view => 'Mason',
71 # Static::Simple configuration
72 static => {
73 dirs => [qw[ css s static img documents static_content data ]],
76 'Plugin::ConfigLoader' => {
77 substitutions => {
78 UID => sub { $> },
79 USERNAME => sub { (getpwuid($>))[0] },
80 GID => sub { $) },
81 GROUPNAME => sub { (getgrgid($)))[0] },
85 # configure SGN::Role::Site::TestMode. These are the
86 # configuration keys that it will change so that they point into
87 # t/data
88 'Plugin::TestMode' => {
89 test_data_dir => __PACKAGE__->path_to('t','data'),
90 reroot_conf =>
91 [qw(
93 blast_db_path
94 cluster_shared_tempdir
95 ftpsite_root
96 image_path
97 genefamily_dir
98 homepage_files_dir
99 intron_finder_database
100 r_qtl_temp_path
101 static_content_path
102 static_datasets_path
103 trace_path
108 'Plugin::Cache'=>{
109 backend => {
110 store =>"FastMmap",
116 'Plugin::Authentication' => {
117 default_realm => 'default',
118 realms => {
119 default => {
120 credential => {
121 class => '+SGN::Authentication::Credentials',
124 store => {
125 class => "+SGN::Authentication::Store",
126 user_class => "+SGN::Authentication::User",
127 ### role_column => 'roles',
133 ( $ENV{SGN_TEST_MODE} ? ( test_mode => 1 ) : () ),
137 # on startup, do some dynamic configuration
138 after 'setup_finalize' => sub {
139 my $self = shift;
141 $self->config->{basepath} = $self->config->{home};
143 # all files written by web server should be group-writable
144 umask 000002;
146 # update the symlinks used to serve static files
147 $self->_update_static_symlinks;
150 __PACKAGE__->setup;
152 sub _update_static_symlinks {
153 my $self = shift;
155 # symlink the static_datasets and
156 # static_content in the root dir so that
157 # Catalyst::Plugin::Static::Simple can serve them. in production,
158 # these will be served directly by Apache
160 # make symlinks for static_content and static_datasets
161 my @links =
162 map [ $self->config->{$_.'_path'} =>
163 $self->path_to( $self->config->{root}, $self->config->{$_.'_url'} )
165 qw( static_content static_datasets );
167 for my $link (@links) {
168 if( $self->debug ) {
169 my $l1_rel = $link->[1]->relative( $self->path_to );
170 $self->log->debug("symlinking static dir '$link->[0]' -> '$l1_rel'") if $self->debug;
172 unlink $link->[1];
173 symlink( $link->[0], $link->[1] )
174 or die "$! symlinking $link->[0] => $link->[1]";
178 =head1 SEE ALSO
180 L<SGN::Controller::Root>, L<Catalyst>
182 =head1 AUTHOR
184 The SGN team
186 =head1 LICENSE
188 This library is free software. You can redistribute it and/or modify
189 it under the same terms as Perl itself.
191 =cut