3 SGN::Feature::GBrowse - site feature object to provide GBrowse integration
7 package SGN
::Feature
::GBrowse
;
9 use namespace
::autoclean
;
11 extends
'SGN::Feature';
13 use Moose
::Util
::TypeConstraints
;
14 use MooseX
::Types
::Path
::Class qw
| Dir File
|;
15 use MooseX
::Types
::URI
'Uri';
16 use HTML
::Mason
::Interp
;
18 { my $pi = subtype as
'ArrayRef';
23 has
'perl_inc' => ( documentation
=> 'arrayref of paths to set in PERL5LIB if running in fastcgi or cgi mode',
26 default => sub { [] },
31 has
'+description' => (
32 default => 'Genome browser',
35 has
'conf_dir' => ( documentation
=> 'directory where GBrowse will look for its conf files',
40 ); sub _build_conf_dir
{ my $self = shift; $self->tmpdir->subdir( 'rendered_conf' ) }
42 has
'conf_template_dir' => ( documentation
=> <<'EOD',
43 directory for configuration templates, which will be rendered on a one-to-one basis into $self->conf_dir during setup()
49 ); sub _build_conf_template_dir
{ shift->path_to('conf','templates') }
51 has
'static_url' => ( documentation
=> 'URL base for GBrowse static files',
91 # default database connection info used by gbrowse
92 has
'default_db_host' => (
96 ); sub _build_default_db_host
{
97 my $dsn = shift->context->dbc_profile->{dsn
};
98 return unless $dsn =~ /host=([^;]+)/;
101 has
'default_db_user' => (
105 ); sub _build_default_db_user
{
106 shift->context->dbc_profile->{user
};
108 has
'default_db_password' => (
112 ); sub _build_default_db_password
{
113 shift->context->dbc_profile->{password
};
118 'local @INC = ( '.join(', ',map "'$_'",@INC).' );';
122 # assembles a URI linking to gbrowse.
124 my ( $self, $conf_name, $params ) = @_;
126 my $uri = URI
->new($self->cgi_url."/$conf_name/");
127 $uri->query_form( %$params );
133 my ( $self, $c ) = @_;
134 $self->render_all_configs;
138 my ( $self, $q ) = @_;
139 return unless defined $q;
141 # go through each data source and give it a crack at it
142 return map $_->xrefs($q), $self->data_sources;
146 die 'data_sources not yet implemented for gbrowse 1.x';
150 # for each .mas file in the $self->conf_template_dir directory, run
151 # templating on it and put the output in $self->conf_dir under the
152 # same filename, without the ending .mas
153 sub render_all_configs
{
156 # all .mas files in the conf_template_dir
158 $self->conf_template_dir->recurse(
161 return if $child->is_dir || $child !~ /\.mas$/ || $child =~ /^#/ || $child =~ /~$/;
162 push @template_files, $child;
165 foreach my $template_file (@template_files) {
167 # assemble our target filename, which is the same file name
168 # (minus the .mas), in the $self->conf_dir directory
169 my $render_target_relative = $template_file->relative( $self->conf_template_dir );
170 $render_target_relative =~ s/\.mas$//;
171 my $render_target = $self->conf_dir->file( $render_target_relative );
173 $render_target->dir->mkpath;
174 $self->render_config_template( $template_file => $render_target );
177 # also symlink other things in the conf dir into there
178 for my $conf_thing ( $self->conf_template_dir->parent->children ) {
179 my $link_target = $self->conf_dir->file( $conf_thing->relative( $conf_thing->parent ) );
181 symlink $conf_thing, $link_target
182 or die "$! linking $conf_thing -> $link_target";
186 sub render_config_template
{
187 my ( $self, $template_file, $render_target ) = @_;
189 # render the template into the target file
191 # my $mason = HTML::Mason::Interp
192 # ->new( allow_globals => [qw[ $c $feature ]],
193 # autohandler_name => '',
194 # comp_root => [['conf_templates', $self->conf_template_dir->stringify ]],
195 # out_method => \$outbuf,
197 # $mason->set_global( '$c' => $self->context );
198 # $mason->set_global( '$feature' => $self );
200 # $mason->exec( '/'.$template_file->relative( $self->conf_template_dir) ); #< mason's default search path is current working directory
202 # $render_target->openw->print( $outbuf );
205 # # returns a string of apache configuration to be included during
206 # # startup. will be part of plugin role
209 # my $dir = $self->static_dir;
210 # my $conf = $self->conf_dir;
211 # my $cgibin = $self->cgi_bin;
212 # my $tmp = $self->tmp_dir;
213 # my $cgiroot = basename($cgibin);
214 # my $perl5lib = $self->added_to_INC;
215 # my $inc = $perl5lib ? "SetEnv PERL5LIB \"$perl5lib\"" : '';
216 # my $fcgi_inc = $perl5lib ? "-initial-env PERL5LIB=$perl5lib" : '';
217 # my $fcgid_inc = $perl5lib ? "DefaultInitEnv PERL5LIB $perl5lib" : '';
218 # my $modperl_inc = $inc ? "Perl$inc" : '';
219 # my $url_base = $self->url_base;
221 # my %runmode_conf = (
223 # Alias /$url_base "$cgibin"
225 # SetHandler perl-script
226 # PerlResponseHandler ModPerl::Registry
227 # PerlOptions +ParseHeaders
228 # PerlSetEnv GBROWSE_CONF "$conf"
233 # Alias /$url_base "$cgibin"
235 # SetHandler fcgid-script
238 # DefaultInitEnv GBROWSE_CONF $conf
242 # Alias /$url_base "$cgibin"
244 # SetHandler fastcgi-script
247 # FastCgiConfig $fcgi_inc -initial-env GBROWSE_CONF=$conf
250 # ScriptAlias "/$url_base" "$cgibin"
251 # <Directory "$cgibin">
253 # SetEnv GBROWSE_CONF "$conf"
258 # my $runmode_conf = $runmode_conf{ $self->run_mode }
259 # or confess "invalid run mode '".$self->run_mode."'";
262 # Alias "/$url_base/static/i/" "$tmp/images/"
263 # Alias "/$url_base/static" "$dir"
266 # Options -Indexes -MultiViews +FollowSymLinks
273 __PACKAGE__
->meta->make_immutable;