[VPM] stupid stupid stupid

Nathanael Kuipers nkuipers at uvic.ca
Fri Apr 25 13:57:15 CDT 2003


*sigh*

I'm writing a parser module for a research tool that we use.  I've sort of 
been "raised" in OO Perl, so by default I write OO modules.  Here is my 
synopsis for what I want to be able to do:

my $struct_ref = BIO::vmatchIO->new(*FH)->parse();

And here's the constructor:

sub new () {
	my ($class, $fh) = @_;
	bless (\FileHandle->new($fh), (ref($class) || $class));
}

Later, the parse method calls a support method, _check_format(), to decide 
what output format it's looking at, and the following line throws an error 
("can't locate object method getline via package BIO::vmatchIO..."):

while (my $line = $this->getline()) {}

Messing with @ISA (via use base pragma) just gets me a "Not a GLOB reference 
at ...Handle.pm line 407" when I test the module with a script where I pass a 
reference to an opened filehandle to the constructor above.

Is it clear what I am trying to do and how Perl isn't DWIM?  I've never tried 
re-blessing an object into my own package before, what's the best way to 
accomplish this?

And then in a fit of curiosity I took out all the OO stuff and instead put the 
parse() method in @EXPORT.  In the test script that uses BIO::vmatchIO,  
calling parse() threw an error because there was no parse method in the main:: 
package (obviously).  I almost flew off the handle (no pun intended) at that 
point and angrily stuffed my OO features back in.

Any ideas on either approach?

Thanks.

Nathanael  




More information about the Victoria-pm mailing list