pray2s8n has asked for the wisdom of the Perl Monks concerning the following question:

I'm having great difficulty overriding the "_connect" method of the Net::ParseWhois module. Chances are that I'm just a dolt and need to understand objects more prior to diving in like this, but I've read through "Tom's Object Oriented Tutorial for Perl," and it lead me to believe that I can just do:
package MyParseWhois; require 5.004; use strict; use Carp; use vars qw/@ISA/; @ISA = ("Net::ParseWhois"); sub _connect { # My proxy connect code here.... } 1;
Now, when I do this and then try and drop in "use MyParseWhois" in place of "use Net::ParseWhois" it just doesn't work. If I omit the "use Carp" I get messload of errors, but even with it in I still get an error:
my $w = MyParseWhois::Domain->new($dom);
Error: "Can't locate object method "new" via package "MyParseWhois::Domain" at whois.pl line 8."

When "MyParseWhois" is changed back to "Net::ParseWhois" it works fine, but then it is not what I need. Now, I _know_ that this has got to be simple enough, but I've read and re-read the tutorial and it's just not working as described. There must be something that I am not seeing. Could someone please set me straight? I'm really only just getting into Objects and such, and I'm sure that I will eventually make sense of this, but for the moment I need my whois script working! Please almighty Perl Monks, help me see the light!

PM

Replies are listed 'Best First'.
Re: Stupid Subclassing Question- Net::ParseWhois
by no_slogan (Deacon) on May 14, 2001 at 23:12 UTC
    Have MyParseWhois do a use Net::ParseWhois. Just putting something in @ISA doesn't get the superclass code loaded.

    Update: Make your package name MyParseWhois::Domain instead of MyParseWhois.

(tye)Re: Stupid Subclassing Question- Net::ParseWhois
by tye (Sage) on May 15, 2001 at 01:50 UTC

    FYI, if its name starts with an underscore, then it is usually an "internal" method which means it was not designed to be overridden and even if you get it working your code is likely to break if the module is upgraded.

    Though I haven't verified that Net::ParseWhois is actually following this guideline in this case.

            - tye (but my friends call me "Tye")
      Maybe that's it, 'cause I still can't get it working. I've joined and posted to the netparsewhois list, but right now I'm leaning towards simply pasting my code directly into the original module's _connect() method and remembering to do so each time it is upgraded. This is acceptable to me since I am the exclusive user of the script, machine and modules so why not customize them to my liking? I really need to be able to whois using proxies, and would like to have been able to cleanly override the method rather than hacking it, but my project needs to move forward. Argh.

        In such cases, the best approach might be to patch the module such that it supports adding such capabilities and get the patch incorporated into the module so you don't have to keep repatching the module each time you upgrade it.

                - tye (but my friends call me "Tye")
Re: Stupid Subclassing Question- Net::ParseWhois
by ChemBoy (Priest) on May 15, 2001 at 02:36 UTC

    I think part of your problem is that Net::ParseWhois::Domain is a package of its own, and you haven't written MyParsewhois::Domain, so the compiler can't find it.

    I'm not sure quite how to solve that problem--might it help to create a dummy MyParsewhois::Domain package that had nothing but a pointer to the correct class? (This assumes that you don't need to change any of its methods.)

    package MyParsewhois::Domain; require ParseWhois::Domain; @ISA = ("ParseWhois::Domain"); __END__

    Alternatively, you could just sneakily declare yourself to be in package Net::Parsewhois, and patch in your own code that way... I believe this is discouraged, however.



    If God had meant us to fly, he would *never* have give us the railroads.
        --Michael Flanders