Beefy Boxes and Bandwidth Generously Provided by pair Networks Joe
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re^2: Safer monkey-patching

by moritz (Cardinal)
on Jan 19, 2012 at 08:07 UTC ( #948714=note: print w/ replies, xml ) Need Help??


in reply to Re: Safer monkey-patching
in thread Safer monkey-patching

in Example::ErrorList, provide a method that returns list item class name, and instantiate objects of that name.

You can also make that an attribute (plus accessor, if you want), so that subclassing isn't even necessary. If you use blessed hash references as objects, and do not create the hash key in the default case, there's not even a memory penality to be paid unless you deviate from the default.

An example for a read and write accessor could be

sub error_class { my $self = shift; my $default = 'Example::Error'; if (@_) { my $new = shift; if ($new eq $default) { delete $self->{error_class} } else { $self->{error_class} = $new' } } $self->{error_class} // $default }


Comment on Re^2: Safer monkey-patching
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://948714]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (7)
As of 2014-04-20 04:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (485 votes), past polls