[Bioperl-l] Auto-method caller proposal

Chris Fields cjfields at uiuc.edu
Thu Jan 4 17:08:59 UTC 2007

On Jan 4, 2007, at 4:45 AM, Sendu Bala wrote:

> Chris Fields wrote:
>> ...
>> 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 script/class POD would still describe the method w/o the actual  
code being present.  Just describing the methods as get/setters or  
whatever in POD should be enough.  It's already done for BioPerl  
classes inheriting defined methods from base or interface classes.

> 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.

Not a big deal, really.  I think it's probably best to have  
_set_from_args() use simple get/setters as you now have it, and have  
a different RootI-based method capable of doing what I described if  

I agree there are other much more straightforward ways of doing this,  
but I'm thinking along the lines of added hooks for customization.   
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  
              '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

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.


More information about the Bioperl-l mailing list