AcePerl

 view release on metacpan or  search on metacpan

Ace/Browser/SiteDefs.pm  view on Meta::CPAN

  $config_object = Configuration();

Thereafter, it's just a matter of making the proper method calls.

   If the Configuration file is a....    The method call returns a...
   ----------------------------------    ----------------------------

   Scalar variable                       Scalar
   Array variable                        Array reference
   Hash variable                         Hash reference
   Subroutine                            Code reference

If a variable is not defined, the corresponding method will return undef.

=head1 BUGS

Please report them.

=head1 SEE ALSO

L<Ace::Object>, L<Ace::Browser::AceSubs>, L<Ace::Browsr::SearchSubs>, 
the README.ACEBROWSER file.

=head1 AUTHOR

Lincoln Stein <lstein@cshl.org>.

Copyright (c) 2001 Cold Spring Harbor Laboratory

This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.  See DISCLAIMER.txt for
disclaimers of warranty.

=cut

use CGI();
use Ace();

use strict;
use Carp;
use vars qw($AUTOLOAD);

# get location of configuration file
use Ace::Browser::LocalSiteDefs '$SITE_DEFS';

my %CONFIG;
my %CACHETIME;
my %CACHED;

sub getConfig {
  my $package = shift;
  my $name    = shift;
  croak "Usage: getConfig(\$database_name)" unless defined $name;
  $package = ref $package if ref $package;
  my $file    = "${name}.pm";

  # make search relative to SiteDefs.pm file
  my $path = $package->get_config || $package->resolveConf($file);

  return unless -r $path;
  return $CONFIG{$name} if exists $CONFIG{$name} and $CACHETIME{$name} >= (stat($path))[9];
  return unless $CONFIG{$name} = $package->_load($path);
  $CONFIG{$name}->{'name'} ||= $name;  # remember name
  $CACHETIME{$name} = (stat($path))[9];
  return $CONFIG{$name};
}

sub modtime {
  my $package = shift;
  my $name = shift;
  if (!$name && ref($package)) {
    $name = $package->Name;
  }
  return $CACHETIME{$name};
}

sub AUTOLOAD {
    my($pack,$func_name) = $AUTOLOAD=~/(.+)::([^:]+)$/;
    my $self = shift;
    croak "Unknown field \"$func_name\"" unless $func_name =~ /^[A-Z]/;
    return $self->{$func_name} = $_[0] if defined $_[0];
    return $self->{$func_name} if defined $self->{$func_name};
    # didn't find it, so get default
    return if (my $dflt = $pack->getConfig('default')) == $self;
    return $dflt->{$func_name};
}

sub DESTROY { }

sub map_url {
  my $self = shift;
  my ($display,$name,$class) = @_;
  $class ||= $name->class if ref($name) and $name->can('class');

  my (@result,$url);

  if (my $code = $self->Url_mapper) {
    if (@result = $code->($display,$name,$class)) {
      return @result;
    }
  }

  # if we get here, then take the first display
  my @displays = $self->displays($class,$name);
  push @displays,$self->displays('default') unless @displays;
  my $n = CGI::escape($name);
  my $c = CGI::escape($class);
  return ($displays[0],"name=$n;class=$c") if $displays[0];

  return unless @result = $self->getConfig('default')->Url_mapper->($display,$name,$class);
  return unless $url = $self->display($result[0],'url');
  return ($url,$result[1]);
}

sub searches {
  my $self = shift;
  return unless my $s = $self->Searches;
  return @{$s} unless defined $_[0];
  return $self->Search_titles->{$_[0]};
}

# displays()                   => list of display names
# displays($name)              => hash reference for display
# displays($name=>$field)      => displays at {field}



( run in 0.843 second using v1.01-cache-2.11-cpan-d7a12ab2c7f )