On 29/03/11 09:09, Peter Gordon wrote:
In this example, I have defined two classes - MyValue, and MyValueBool.
MyValueBool is meant to do the same thing as MyValue, except that the
value is restricted to a boolean.

The problem is that the 'around' function only gets called when using
the base class.


This succeeds - around 'value' is called.

$f = MyValue->new ;
$n = $f->value ;


This fails - around 'value' is not called.

$f = MyValueBool->new ;
$n = $f->value ;

Without repeating the 'around' routine, what should I do?

Thanks,

Peter





package MyValue ;
use Mouse ;
has 'value' =>  ( accessor => '_value' ) ;

sub value {
  print "WHEE\n";
  shift->_value(@_);
}

__PACKAGE__->meta->strict_constructor(1);
__PACKAGE__->meta->make_immutable;
no Mouse ;

package MyValueBool ;
use Mouse ;
extends 'MyValue' ;
has '+value' =>  (
                 isa     =>  'Bool',
                );

__PACKAGE__->meta->strict_constructor(1);
__PACKAGE__->meta->make_immutable;
no Mouse ;
1;

would work. Not sure if that's precisely what you want, though.

Perhaps your best option would be to look at adding introspection to Class::MOP::Method::Wrapped so that modifiers can be re-applied further down? I've given consideration to doing this a couple of times now and I don't think it's actually -hard- as such, just fiddly enough I've not felt like trying.

Reply via email to