Skip to content
Snippets Groups Projects
Commit 5e7ab147 authored by James Gilbert's avatar James Gilbert
Browse files

Added "can" to Container.pm in a similar manner

to the existing "isa", and added a friendly throw to
AUTOLOAD if the method does not exist on the object.
parent dfc19b17
No related branches found
No related tags found
No related merge requests found
=Head1 NAME - Bio::EnsEMBL::DBSQL::DBAdaptorHolder
=head1 NAME - Bio::EnsEMBL::DBSQL::DBAdaptorHolder
=head1 SYNOPSIS
$container = new Bio::EnsEMBL::Container($obj);
=head1 DESCRIPTION
This object is a hack necessary to work around perls circular reference
......@@ -112,12 +113,31 @@ sub isa {
return $self->SUPER::isa($module);
}
=head2 can
Arg [1] : string $method
Example : none
Description: Like the isa method above, calls can on the contained
_obj. Without this can fails because it gets trapped
by the AUTOLOAD method.
Returntype : boolean
Exceptions : none
Caller : general
=cut
sub can {
my( $self, $method ) = @_;
return $self->_obj->can($method);
}
=head2 AUTOLOAD
Arg [1] : @args list of arguments
Example : none
Description: Automatically callanopheles_build_est_augusted to forward calls to the object in this
Description: Automatically called to forward calls to the object in this
container
Returntype : arbitrary
Exceptions : none
......@@ -125,27 +145,29 @@ sub isa {
=cut
sub AUTOLOAD {
my ($self, @args) = @_;
my $method = $AUTOLOAD;
$method =~ s/.*:://;
#update the symbol table so AUTOLOAD is not needed the next time
#this method is called (faster this way)
no strict 'refs';
*{$AUTOLOAD} =
sub {
my ($self, @args) = @_;
return $self->_obj->$method(@args);
};
use strict 'refs';
#call the method on the contained object
return $self->_obj->$method(@args);
# call the method on the contained object
if ($self->_obj->can($method)) {
# update the symbol table so AUTOLOAD is not called
# the next time this method is called (faster this way)
no strict 'refs';
*{$AUTOLOAD} =
sub {
my ($self, @args) = @_;
return $self->_obj->$method(@args);
};
return $self->_obj->$method(@args);
} else {
# Method does not exist
$self->throw("method '$method' does not exist in '". ref($self->_obj) ."'");
}
}
......
......@@ -12,7 +12,6 @@ use vars qw($opt_l $opt_h);
#read command line options
&usage unless getopts('lh');
#print usage on '-h' command line option
if($opt_h) {
&usage;
......@@ -21,7 +20,7 @@ if($opt_h) {
#list test files on '-l' command line option
if($opt_l) {
foreach my $file (@{&get_all_tests('.', \@ARGV )}) {
foreach my $file (map {s{^\./}{}; $_} @{get_all_tests('.', \@ARGV)}) {
print "$file\n";
}
exit;
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment