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


In reply to Re: Modifying/extending a superclass' data by Zaxo
in thread Modifying/extending a superclass' data by kiz

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.