Skip to content

Instantly share code, notes, and snippets.

@preaction
Created December 14, 2014 02:59
Show Gist options
  • Save preaction/566e2f27954f57d56a74 to your computer and use it in GitHub Desktop.
Save preaction/566e2f27954f57d56a74 to your computer and use it in GitHub Desktop.
Attribute value after clearer is called differs between lazy and non-lazy
{
package FooMoo;
use Moo;
has foo => (
is => 'rw',
default => sub { 'foo' },
clearer => 1,
);
has bar => (
is => 'rw',
default => sub { 'bar' },
lazy => 1,
clearer => 1,
);
}
use strict;
use warnings;
use feature ':5.10';
my $foo = FooMoo->new;
say "foo: " . $foo->foo;
$foo->foo( "BAZINGA" );
say "foo after set: " . $foo->foo;
$foo->clear_foo;
say "foo after clear: " . $foo->foo;
say "bar: " . $foo->bar;
$foo->bar( "BAZINGA" );
say "bar after set: " . $foo->bar;
$foo->clear_bar;
say "bar after clear: " . $foo->bar;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment