[Bioperl-l] Philosophy, BioPerl Object Creation

Heikki Lehvaslaiho heikki at ebi.ac.uk
Fri Mar 28 10:01:07 EST 2003


Hilmar,

I think you missed the point. 

I can create this object with bioperl-like key-value pairs. It does rely
on _one_ superclass implementing a method named identically to the key
and that's how I'd like the classes to written in bioperl:

$w = Bio::WebAgent->new
    (-env_proxy => 1,   # LWP::Agent method with bioperl hyphenated key
     timeout => 30,     # LWP::Agent method
     -verbose => 2      # Bio::Root::Root method
);




On Thu, 2003-03-27 at 18:21, Hilmar Lapp wrote:
> On Thursday, March 27, 2003, at 04:15  AM, Heikki Lehvaslaiho wrote:
> 
> > In related note: I wanted to inherit directly from a non-bioperl class
> > and merge it with the rest of bioperl and came up with this:
> >
> > package Bio::WebAgent;
> > use vars qw(@ISA);
> > use strict;
> > use LWP::UserAgent;
> > use Bio::Root::Root;
> >
> > @ISA = qw(LWP::UserAgent Bio::Root::Root);
> >
> > sub new {
> >     my $class = shift;
> >
> >     my $self = $class->SUPER::new();
> >     while( @_ ) {
> > 	my $key = shift;

I even think we should write:

          my $key = lc shift;

since long_method_name is lot easier to get right than LongMethodName or
get_LongMethodName.


	-Heikki


> >         $key =~ s/^-//;
> >         $self->$key(shift);
> >     }
> >
> >     return $self; # success - we hope!
> >
> > }
> >
> > This actually faster than using _rearrange. In some of my tests old_new
> > versus new_new was 19:14 seconds, sometimes less.
> >
> > Can anyone point out why this would be bad and perhaps show me a better
> > way of doing the same thing.
> 
> Well, you don't pass on any parameters, so you rely on every class down 
> the tree having a method named identically to the parameter.
> 
> Would be nice if that were the case, but in bioperl it's definitely 
> not...
> 
> 	-hilmar
> 
> 
> >
> > 	-Heikki
> >
> >
> >
> >
> > On Thu, 2003-03-27 at 11:32, Matthew Pocock wrote:
> >>> argument list intact. Also, parameters may be used
> >>> in more than one
> >>> level in the hierarchy.
> >>>
> >>> 	-hilmar
> >>
> >> That seems a little rude. Can we get around this a bit
> >> by accessing the parameter via an accessor? e.g.
> >>
> >> my $self = my_super->new(@_);
> >> // pigColor was an argument but I need to know it to
> >> // set myself up - use an accessor
> >> my $pigColor = $self->pigColor();
> >>
> >> Matthew
> >>
> >>> -- 
> >>>
> >> -------------------------------------------------------------
> >>> Hilmar Lapp                            email: lapp
> >>> at gnf.org
> >>> GNF, San Diego, Ca. 92121              phone:
> >>> +1-858-812-1757
> >>>
> >> -------------------------------------------------------------
> >>>
> >>> _______________________________________________
> >>> Bioperl-l mailing list
> >>> Bioperl-l at bioperl.org
> >>> http://bioperl.org/mailman/listinfo/bioperl-l
> >>
> >> __________________________________________________
> >> Do You Yahoo!?
> >> Everything you'll ever need on one web page
> >> from News and Sport to Email and Music Charts
> >> http://uk.my.yahoo.com
> >> _______________________________________________
> >> Bioperl-l mailing list
> >> Bioperl-l at bioperl.org
> >> http://bioperl.org/mailman/listinfo/bioperl-l
> > -- 
> > ______ _/      _/_____________________________________________________
> >       _/      _/                      http://www.ebi.ac.uk/mutations/
> >      _/  _/  _/  Heikki Lehvaslaiho          heikki at ebi.ac.uk
> >     _/_/_/_/_/  EMBL Outstation, European Bioinformatics Institute
> >    _/  _/  _/  Wellcome Trust Genome Campus, Hinxton
> >   _/  _/  _/  Cambs. CB10 1SD, United Kingdom
> >      _/      Phone: +44 (0)1223 494 644   FAX: +44 (0)1223 494 468
> > ___ _/_/_/_/_/________________________________________________________
> >
> >
-- 
______ _/      _/_____________________________________________________
      _/      _/                      http://www.ebi.ac.uk/mutations/
     _/  _/  _/  Heikki Lehvaslaiho          heikki at ebi.ac.uk
    _/_/_/_/_/  EMBL Outstation, European Bioinformatics Institute
   _/  _/  _/  Wellcome Trust Genome Campus, Hinxton
  _/  _/  _/  Cambs. CB10 1SD, United Kingdom
     _/      Phone: +44 (0)1223 494 644   FAX: +44 (0)1223 494 468
___ _/_/_/_/_/________________________________________________________



More information about the Bioperl-l mailing list