clean
[sgn.git] / lib / SGN.pm
blobf1add6e840cc047cca9297667cd66b1b50b8e245
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 +SGN::Authentication::Store
44 Authorization::Roles
45 +SGN::Role::Site::Config
46 +SGN::Role::Site::DBConnector
47 +SGN::Role::Site::DBIC
48 +SGN::Role::Site::Exceptions
49 +SGN::Role::Site::Files
50 +SGN::Role::Site::Mason
51 +SGN::Role::Site::SiteFeatures
52 +SGN::Role::Site::TestMode
55 extends 'Catalyst';
57 =head1 METHODS
59 =cut
61 # configure catalyst-related things. in general, things should not be
62 # added here. add them to SGN.conf, with comments.
63 __PACKAGE__->config(
65 name => 'SGN',
66 root => 'static',
68 disable_component_resolution_regex_fallback => 1,
70 default_view => 'Mason',
72 # Static::Simple configuration
73 static => {
74 dirs => [qw[ css s static img documents static_content data ]],
77 'Plugin::ConfigLoader' => {
78 substitutions => {
79 UID => sub { $> },
80 USERNAME => sub { (getpwuid($>))[0] },
81 GID => sub { $) },
82 GROUPNAME => sub { (getgrgid($)))[0] },
86 # configure SGN::Role::Site::TestMode. These are the
87 # configuration keys that it will change so that they point into
88 # t/data
89 'Plugin::TestMode' => {
90 test_data_dir => __PACKAGE__->path_to('t','data'),
91 reroot_conf =>
92 [qw(
94 blast_db_path
95 cluster_shared_tempdir
96 ftpsite_root
97 image_path
98 genefamily_dir
99 homepage_files_dir
100 intron_finder_database
101 solqtl
102 static_content_path
103 static_datasets_path
104 trace_path
109 'Plugin::Cache'=>{
110 backend => {
111 store =>"FastMmap",
117 'Plugin::Authentication' => {
118 default_realm => 'default',
119 realms => {
120 default => {
121 credential => {
122 class => '+SGN::Authentication::Credentials',
125 store => {
126 class => "+SGN::Authentication::Store",
127 user_class => "+SGN::Authentication::User",
128 ### role_column => 'roles',
134 ( $ENV{SGN_TEST_MODE} ? ( test_mode => 1 ) : () ),
138 # on startup, do some dynamic configuration
139 after 'setup_finalize' => sub {
140 my $self = shift;
142 $self->config->{basepath} = $self->config->{home};
144 # all files written by web server should be group-writable
145 umask 000002;
147 # update the symlinks used to serve static files
148 $self->_update_static_symlinks;
151 __PACKAGE__->setup;
153 sub _update_static_symlinks {
154 my $self = shift;
156 # symlink the static_datasets and
157 # static_content in the root dir so that
158 # Catalyst::Plugin::Static::Simple can serve them. in production,
159 # these will be served directly by Apache
161 # make symlinks for static_content and static_datasets
162 my @links =
163 map [ $self->config->{$_.'_path'} =>
164 $self->path_to( $self->config->{root}, $self->config->{$_.'_url'} )
166 qw( static_content static_datasets );
168 for my $link (@links) {
169 if( $self->debug ) {
170 my $l1_rel = $link->[1]->relative( $self->path_to );
171 $self->log->debug("symlinking static dir '$link->[0]' -> '$l1_rel'") if $self->debug;
173 unlink $link->[1];
174 symlink( $link->[0], $link->[1] )
175 or die "$! symlinking $link->[0] => $link->[1]";
179 =head1 SEE ALSO
181 L<SGN::Controller::Root>, L<Catalyst>
183 =head1 AUTHOR
185 The SGN team
187 =head1 LICENSE
189 This library is free software. You can redistribute it and/or modify
190 it under the same terms as Perl itself.
192 =cut