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 = Moose::Meta::Class->create_anon_class;
49 my $foo = $anon->new_object;
50 isa_ok($foo, $anon->name);
51 ok(Class::MOP::class_of($foo), "has a metaclass");
53 $clone = $anon->clone_object($foo);
54 isa_ok($clone, $anon->name);
55 ok(Class::MOP::class_of($clone), "has a metaclass");
58 ok(Class::MOP::class_of($clone), "still has a metaclass");
62 package Foo::Meta::Attr::Trait;
69 default => sub { shift->name },
76 default => sub { '<<COUNT>>' . shift->name },
81 return ($self->value_slot, $self->count_slot);
87 my $mi = $self->associated_class->get_meta_instance;
91 ($mi->get_slot_value($instance, $self->count_slot) || 0) + 1,
98 $self->associated_class->get_meta_instance->deinitialize_slot(
99 $instance, $self->count_slot
106 $self->associated_class->get_meta_instance->has_slot_value(
107 $instance, $self->count_slot
114 $self->associated_class->get_meta_instance->get_slot_value(
115 $instance, $self->count_slot
119 after set_initial_value => sub {
120 shift->_set_count(@_);
123 after set_value => sub {
124 shift->_set_count(@_);
127 around _inline_instance_set => sub {
132 my $mi = $self->associated_class->get_meta_instance;
135 . $mi->inline_set_slot_value(
138 $mi->inline_get_slot_value(
139 $instance, $self->count_slot
146 after clear_value => sub {
147 shift->_clear_count(@_);
154 Moose::Util::MetaRole::apply_metaroles(
157 attribute => ['Foo::Meta::Attr::Trait'],
161 has baz => ( is => 'rw' );
165 my $attr = Bar->meta->find_attribute_by_name('baz');
167 my $bar = Bar->new(baz => 1);
168 is($attr->count($bar), 1, "right count");
171 is($attr->count($bar), 2, "right count");
173 my $clone = $bar->meta->clone_object($bar);
174 is($attr->count($clone), $attr->count($bar), "right count");