in reply to Modifying/extending a superclass' data

Unfortunately (though many think it a feature), your point 3. is correct. The declaration of %ENTITIES as a lexical gives it file scope only. Without some sub forming a closure by returning it or a reference to it, it is invisible outside the file.

There is a half-measure you can take. The functions exported by MathML::Entities need not be imported, and you can define your own %ENTITIES and functions like so:

package 'MathML::Entities::Approximate'; use MathML::Entities (); # explicit no-arg stops import my %ENTITIES = ( foo => '&x000042', ); sub _convert2numbered { my $reference = shift; $reference =~ /^&([a-zA-Z0-9]+);$/; my $name = $1; # above copied from MathML::Entities return exists $ENTITIES{$name} ? $ENTITIES{$name} : MathML::Entities::_convert2numbered($reference); } # etc.
Note that the _convert2numbered code copied from M::E is not very good. It assumes the match succeeded and blithely goes on to work with $1. Bad Practice. In its defense, such a match has already succeeded before this function is called, but that's a thin reed to hang on to if you want robust subclassible code.

Another choice would be to just copy the MathML::Entities code to your module and modify it there. That's not very different from the above code, and probably simpler.

After Compline,
Zaxo

Replies are listed 'Best First'.
Re^2: Modifying/extending a superclass' data
by kiz (Monk) on Nov 17, 2005 at 14:00 UTC
    Another choice would be to just copy the MathML::Entities code to your module and modify it there.

    Indeed - or I could simply hack the changes I want into M::E itself (which I have done on my workstation, for development purposes).... but that kinda defeats the purpose of having proper Packages <grin />)



    -- Ian Stuart
    A man depriving some poor village, somewhere, of a first-class idiot.
      I would provide some set of accessor functions to, at least, add entities to %ENTITIES. Then, I would submit the patch back to the author along with some tests. Remember - in OSS, if you want something done, the quickest way is to do it yourself. That's why you have the code.

      My criteria for good software:
      1. Does it work?
      2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?