* Stop hiding warnings produced by throwing errors in DEMOLISH methods.
+ * The 'reset' native delegation for Counter attributes will now also respect
+ builders (previously, it only respected defaults).
+
2.0001 Fri, Apr 22, 2011
[ENHANCEMENTS]
my $self = shift;
my ($slot_access) = @_;
- return '$attr->default($self)';
+ my $attr = $self->associated_attribute;
+
+ return '(do { '
+ . join(' ', $attr->_inline_generate_default(
+ '$self', '$default_for_reset'
+ )) . ' '
+ . '$default_for_reset; '
+ . '})';
}
sub _inline_optimized_set_new_value {
my $self = shift;
my ($inv, $new, $slot_access) = @_;
- return $slot_access . ' = $attr->default($self);';
+ return $slot_access . ' = ' . $self->_potential_value . ';';
}
no Moose::Role;
$class;
}
+{
+ package WithBuilder;
+ use Moose;
+
+ has nonlazy => (
+ traits => ['Counter'],
+ is => 'rw',
+ isa => 'Int',
+ builder => '_builder',
+ handles => {
+ reset_nonlazy => 'reset',
+ },
+ );
+
+ has lazy => (
+ traits => ['Counter'],
+ is => 'rw',
+ isa => 'Int',
+ lazy => 1,
+ builder => '_builder',
+ handles => {
+ reset_lazy => 'reset',
+ },
+ );
+
+ sub _builder { 1 }
+}
+
+for my $attr ('lazy', 'nonlazy') {
+ my $obj = WithBuilder->new;
+ is($obj->$attr, 1, "built properly");
+ $obj->$attr(0);
+ is($obj->$attr, 0, "can be manually set");
+ $obj->${\"reset_$attr"};
+ is($obj->$attr, 1, "reset resets it to its default value");
+}
+
done_testing;