[Bioperl-l] Auto-method caller proposal

Sendu Bala bix at sendu.me.uk
Thu Jan 4 10:45:45 UTC 2007

Chris Fields wrote:
> I completely agree; this would come in particularly handy with the 
> EUtilities parameter get/sets.
> It would also be handy to have this or something similar handle code 
> fragments on the fly, so you could deal with more complex methods:
> our %DT = (
>      'foo'  => 'my $self=shift; my $self->{\'_foo\'} = $shift if @_; 
> return;',
>      'bar'  => 'my $self=shift; my $bar = $shift if @_; return 
> ($self->foo)*$bar if $bar;',
> ...
> );
> # in new()
>    $self->_set_from_args(\@args,
>                          -methods => [qw(id foo bar)],
>                          -dispatch_table => \%DT,
>                          -create => 1);
> If the method exists in the dispatch_table hash then you could have more 
> complex subs; all others would be simple get/sets.

I not sure that this makes much sense; if you need something fancier 
than a simple scalar get/setter then by all means instead of writing it 
as a string and passing it to _set_from_args you should implement it as 
an explicit method in the class. That would be far preferable - users 
can then see its POD and code in the online documentation.

The -create => 1 option is really only to take the tediousness out of 
writing a million simple scalar get/setters for run-wrappers or other 
modules with many (externally determined) attributes.

More information about the Bioperl-l mailing list