In the source (and the ref you provided mentions this) of Mojo::Util html_entities.txt is hardcoded. From this file's contents %Mojo::Util::ENTITIES is constructed. So, it looks to me that without changing the filename in Mojo::Util you will not achieve what you want.

However, this being Perl and this being Perlmonks, here is a workaround which should be applied to all script parts which use Mojo::Util;. This may not be surely is not practical.

Mojo::Util provides the wonderfully named monkey_patch() which you can use to alter the only sub therein which uses %ENTITIES, which is Mojo::Util::_entity. And make it use your own (EDIT: e.g. _entity2 which is identical to the original but it uses your locally defined %ENTITIES which you create as you see fit):

use Mojo::Util; my $str = '&#x3c;foo&#x3E;bar&lt;baz&gt;&#x0026;&#34;'; my $res1 = Mojo::Util::html_unescape($str); my %ENTITIES = (lt => '<<<', gt => '>>>'); Mojo::Util::monkey_patch 'Mojo::Util', _entity => \&_entity2; my $res2 = Mojo::Util::html_unescape($str); print "res1: $res1\n"; print "res2: $res2\n"; sub _entity2 { my ($point, $name, $attr) = @_; print "_entity2 called...\n"; # Code point return chr($point !~ /^x/ ? $point : hex $point) unless defined $nam +e; # Named character reference my $rest = my $last = ''; while (length $name) { return $ENTITIES{$name} . reverse $rest if exists $ENTITIES{$name} && (!$attr || $name =~ /;$/ || $last +!~ /[A-Za-z0-9=]/); $rest .= $last = chop $name; } return '&' . reverse $rest; }

bw, bliako


In reply to Re: Customize Mojo's html_entities.txt by bliako
in thread Customize Mojo's html_entities.txt by Anonymous Monk

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.