#!/usr/bin/env perl
use strict;
use warnings;
-use Test::More tests => 10;
-use t::Exception;
+use Test::More tests => 12;
+use Test::Exception;
+my %triggered;
do {
package Foo;
use Mouse;
has quux => (
is => 'rw',
init_arg => 'quuux',
+ trigger => sub{
+ my($self, $value) = @_;
+ $triggered{$self} = $value;
+ },
);
sub clone {
is($foo->foo, "foo", "attr 1",);
is($foo->quux, "indeed", "init_arg respected");
+
+is $triggered{$foo}, "indeed";
+
is_deeply($foo->bar, [ 1 .. 3 ], "attr 2");
$foo->baz("foo");
my $clone = $foo->clone(foo => "dancing", baz => "bar", quux => "nope", quuux => "yes");
+is $triggered{$foo}, "indeed";
+is $triggered{$clone}, "yes", 'clone_object() invokes triggers';
+
is($clone->foo, "dancing", "overridden attr");
is_deeply($clone->bar, [ 1 .. 3 ], "clone attr");
is($clone->baz, "foo", "init_arg=undef means the attr is ignored");
throws_ok {
Foo->meta->clone_object(Foo->meta)
-} qr/You must pass an instance of the metaclass \(Foo\), not \(Mo.se::Meta::Class=HASH\(\w+\)\)/;
+} qr/You must pass an instance of the metaclass \(Foo\), not \(Mouse::Meta::Class=HASH\(\w+\)\)/;
-throws_ok {
- Foo->meta->clone_instance("constant")
-} qr/You can only clone instances, \(constant\) is not a blessed instance/;