19 my ($class, $cb) = @_;
20 bless { cb => $cb }, $class;
23 sub DESTROY { shift->{cb}->() }
30 my $bar = MyScopeGuard->new(sub { $destroyed++ });
31 my $foo = Foo->new({ bar => $bar });
32 my $clone = $foo->meta->clone_object($foo);
47 my $anon = Mouse::Meta::Class->create_anon_class;
49 my $foo = $anon->new_object;
50 isa_ok($foo, $anon->name);
51 ok(Mouse::Util::class_of($foo), "has a metaclass");
53 $clone = $anon->clone_object($foo);
54 isa_ok($clone, $anon->name);
55 ok(Mouse::Util::class_of($clone), "has a metaclass");
58 ok(Mouse::Util::class_of($clone), "still has a metaclass");
64 package Foo::Meta::Attr::Trait;
71 default => sub { shift->name },
78 default => sub { '<<COUNT>>' . shift->name },
83 return ($self->value_slot, $self->count_slot);
89 my $mi = $self->associated_class->get_meta_instance;
93 ($mi->get_slot_value($instance, $self->count_slot) || 0) + 1,
100 $self->associated_class->get_meta_instance->deinitialize_slot(
101 $instance, $self->count_slot
108 $self->associated_class->get_meta_instance->has_slot_value(
109 $instance, $self->count_slot
116 $self->associated_class->get_meta_instance->get_slot_value(
117 $instance, $self->count_slot
121 after set_initial_value => sub {
122 shift->_set_count(@_);
125 after set_value => sub {
126 shift->_set_count(@_);
129 around _inline_instance_set => sub {
134 my $mi = $self->associated_class->get_meta_instance;
137 . $mi->inline_set_slot_value(
140 $mi->inline_get_slot_value(
141 $instance, $self->count_slot
148 after clear_value => sub {
149 shift->_clear_count(@_);
156 Mouse::Util::MetaRole::apply_metaroles(
159 attribute => ['Foo::Meta::Attr::Trait'],
163 has baz => ( is => 'rw' );
167 my $attr = Bar->meta->find_attribute_by_name('baz');
169 my $bar = Bar->new(baz => 1);
170 is($attr->count($bar), 1, "right count");
173 is($attr->count($bar), 2, "right count");
175 my $clone = $bar->meta->clone_object($bar);
176 is($attr->count($clone), $attr->count($bar), "right count");