in reply to Re: Re: Is it a bad idea to subclass XML::LibXML ?
in thread Is it a bad idea to subclass XML::LibXML ?

I posted a new module called IOC::Lite last week that contains a class that may be useful to you. It's called IOC::Lite::Adaptor. This class's job is to pretend to be another object while providing the means to add methods to it at runtime. It will be greatly enhanced in my next release (due out this weekend), but the current one may help you now (at least in concept).

Cheers,

John

  • Comment on Re: Re: Re: Is it a bad idea to subclass XML::LibXML ?

Replies are listed 'Best First'.
Re: Re: Re: Re: Is it a bad idea to subclass XML::LibXML ?
by nenbrian (Acolyte) on May 18, 2004 at 23:13 UTC

    Hello John,

    If I understand correctly, that might suit my purpose. Does it just AUTOLOAD its methods, and then dispatch the method calls that you don't implement in your subclasses to the contained object?

    What I have done in the mean time is to store the subclass name in the XML::LibXML::Element objects as an attribute, and then use that to bless the references returned by my lookup routine (which is just a wrapper around findnodes() that does the bless()ings). Unfortunately this is a little bit inefficient when findnodes() returns a large nodelist, but it works, and it seems to perform reasonably well for my application. I think that your solution is cleaner, and will most likely perform better. I'll take a look at it.

    Thanks,
    -brian

      Yes, it just autoloads the methods that it doesn't implement. I did it out of laziness, but I can now see other uses for it. I'm working on a more generalized version for the next release. The current class will stay the same (parent will change).

      Cheers,

      John