Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

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?

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2015-11-28 00:16 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (735 votes), past polls