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

I'm getting the impression that XML::DOM::Document isn't the kind of class I can inherit. Am I right? If so, what's up with that?

Replies are listed 'Best First'.
Re: Inherit XML::DOM::Document?
by GrandFather (Saint) on Apr 06, 2006 at 08:27 UTC

    It's not obvious from the documentation that you can't inherit from XML::DOM::Document. What leads you to think that that is the case?

    What are you trying to achieve that you think such inheritance would help with?


    DWIM is Perl's answer to Gödel
      use XML::DOM; @ISA = qw( XML::DOM::Document );
      yields:
      Global symbol "@ISA" requires explicit package name at lib/Literally +/Document.pm
      and
      use XML::DOM::Document; @ISA = qw( XML::DOM::Document );
      yields:
      Can't locate XML/DOM/Document.pm in @INC
      I'd like to do the normal thing for which one uses inheritance: extend existing functionality. The particular problem I'm trying to solve involves creating a DOM tree from scratch; while that's not directly related to my desire to use inheritance, it is another thing that the XML::DOM documentation doesn't make obvious (rather, it focuses on operating on a DOM tree constructed with the parser).
        Howdy!

        The error message from your first snippet simply means that 'strict vars' is in effect, and you haven't told it that @ISA is ok.

        use vars qw ( @ISA ); use XML::DOM; @ISA = qw(XML::DOM::Document);
        should compile fine. The current package will now be a subclass of XML::DOM::Document. Whether that acutally does what you want is a separate problem.

        yours,
        Michael
        Looking at XML-DOM, XML::DOM::Document is a documentation module, consisting of POD only. You cannot inherit anything from in. Try XML::DOM as base class instead.