develooper Front page | perl.moose | Postings from February 2009

Re: advice on wrapping methods from a superclass

Thread Previous | Thread Next
From:
Jonathan Swartz
Date:
February 13, 2009 17:44
Subject:
Re: advice on wrapping methods from a superclass
Message ID:
15D54379-5DFD-421B-803A-0339E93C9E9A@pobox.com
> On Wed, 11 Feb 2009, Jonathan Swartz wrote:
>
>> The problem is that there are now legitimate reasons to "wrap"  
>> these methods at the CHI/Driver.pm superclass level (meaning, do  
>> something before and/or after the method). For example, I want to  
>> add an optional generic size-awareness feature (the cache can keep  
>> track of its own size), which means that we have to adjust size  
>> whenever remove() and clear() are called. And I want to log  
>> remove() calls the way we currently log get() and set().
>>
>> So one solution is to define remove() and clear() in CHI/Driver.pm,  
>> and have them call _remove() and _clear() in the driver  
>> subclasses.  But this kind of change makes me uneasy for several  
>> reasons:
>
> You want to use augment/inner, I think.
>
> See http://search.cpan.org/~drolsky/Moose-0.68/lib/Moose/Cookbook/Basics/Recipe6.pod 
>  and http://search.cpan.org/~drolsky/Moose-0.68/lib/Moose/Manual/MethodModifiers.pod#INNER_AND_AUGMENT
>

That provides an alternative to _remove() and _clear() - a little  
cleaner, a little more verbose. But it still mandates a driver API  
change, and it still requires us to tell drivers to define certain  
methods differently because we currently need them wrapped. If we want  
to wrap more methods later, the API has to change again. That's what  
I'm trying to avoid.

Jon


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About