[Bioperl-l] Auto-method caller proposal
Sendu Bala
bix at sendu.me.uk
Tue Jan 9 11:49:49 UTC 2007
Chris Fields wrote:
> The idea is one could add in customized code fairly easily using this
> (very useful, BTW) method, or a similar one. For example, I could
> replace code defined in a dispatch table with my own on the fly by
> passing in new code as an hash ref:
>
> # customized subs my %subs = ( 'ids' => '# modified id() for
> customized ID retrieval, not std get/set', 'score' => '# modified
> score() code using myparam() and mydata()' );
>
> # customized user-params (get/sets) my @params = (qw(myparam
> mydata));
>
> # pass into similar method to _set_from_args() # using parameters and
> hash/array refs
I'm not sure I understand. Can you offer a specific example of this sort
of thing being used?
From what I initially understood of your idea, in class Bio::MyNewClass
you write out a sub as a string and associate it with a key like
'bar' => 'my $self=shift; my $bar = $shift if @_; return
($self->foo)*$bar if $bar;'
and in some way supply that pair to something such that when bar() is
called by the user, the string is evaluated and used as the method. In
what circumstance does this provide any benefit (to the author or the
user) over defining the following sub explicitly in Bio::MyNewClass ?
sub bar {
my $self=shift;
my $bar = $shift if @_;
return ($self->foo)*$bar if $bar;
}
> BTW, don't know if this is possible, but can you get around 'no
> strict "refs"' by building the sub code as a string and using an
> eval? I did something like this in the EUtilities BEGIN block using
> heredoc, something picked up from Brian's Bio::DB::Query::GenBank.
The reference in question is the method name, not the method code.
More information about the Bioperl-l
mailing list