$val = $self->_coerce_and_verify( $val, $instance );
$self->set_initial_value($instance, $val);
- $meta_instance->weaken_slot_value($instance, $self->name)
- if ref $val && $self->is_weak_ref;
+
+ if ( ref $val && $self->is_weak_ref ) {
+ $self->weaken_value($instance);
+ }
}
sub _call_builder {
$value = $self->_coerce_and_verify( $value, $instance );
- my $meta_instance = Class::MOP::Class->initialize(blessed($instance))
- ->get_meta_instance;
-
my @old;
if ( $self->has_trigger && $self->has_value($instance) ) {
@old = $self->get_value($instance, 'for trigger');
}
- $meta_instance->set_slot_value($instance, $attr_name, $value);
+ $self->SUPER::set_value($instance, $value);
- if (ref $value && $self->is_weak_ref) {
- $meta_instance->weaken_slot_value($instance, $attr_name);
+ if ( ref $value && $self->is_weak_ref ) {
+ $self->weaken_value($instance);
}
if ($self->has_trigger) {
}
}
+sub weaken_value {
+ my ( $self, $instance ) = @_;
+
+ my $meta_instance =
+ Class::MOP::Class->initialize( blessed($instance) )->get_meta_instance;
+
+ $meta_instance->weaken_slot_value( $instance, $self->name );
+}
+
sub get_value {
my ($self, $instance, $for_trigger) = @_;
use strict;
use warnings;
-use Test::More tests => 14;
+use Test::More tests => 20;
use Test::Exception;
}
{
+ my $foo = Foo->new;
+ isa_ok($foo, 'Foo');
+
+ my $attr = $foo->meta->find_attribute_by_name("lazy_foo");
+
+ isa_ok( $attr, "Moose::Meta::Attribute" );
+
+ ok( $attr->is_lazy, "it's lazy" );
+
+ is( $attr->get_raw_value($foo), undef, "raw value" );
+
+ is( $attr->get_value($foo), 10, "lazy value" );
+
+ is( $attr->get_raw_value($foo), 10, "raw value" );
+}
+
+{
my $foo = Foo->new(foo => 10, lazy_foo => 100);
isa_ok($foo, 'Foo');
use Scalar::Util 'isweak';
-use Test::More tests => 42;
+use Test::More tests => 43;
use Test::Exception;
'trigger called correctly on second set via meta-API',
);
@Foo::calls = ();
+
+ $attr->set_raw_value( $foo, 4 );
+
+ is_deeply(
+ \@Foo::calls,
+ [ ],
+ 'trigger not called using set_raw_value method',
+ );
+ @Foo::calls = ();
}
{