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:
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.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.
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 | |
by dragonchild (Archbishop) on Nov 17, 2005 at 14:41 UTC |