in reply to Re: Best Practice for replace sub
in thread Best Practice for replace sub
In HTML::HTML5::Entities I've got a hash with 2231 entries. It would be wasteful in the extreme to rebuild that hash every time the encode_entities function is called.
Closing over a lexical variable is a perfectly safe thing to do.
(As it happens, I use a package variable for HTML::Entities because that's what HTML::Entities does, and the aim is to provide a compatible API.)
package Cow { use Moo; has name => (is => 'lazy', default => sub { 'Mooington' }) } say Cow->new->name
|
---|
In Section
Seekers of Perl Wisdom