Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
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 surveying the Monastery: (7)
As of 2015-07-02 06:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (29 votes), past polls