X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F001_mouse%2F031-clone.t;h=6d5a052fb1c042d89a6d4c073d5cad4c4a542528;hb=cb6a9721f6d1bf6aaba58920378aad6c03524639;hp=cc39e22b565b366dd305524cab3316431861c589;hpb=d72533cb68542eef3df6ce184b537090dde1b74d;p=gitmo%2FMouse.git diff --git a/t/001_mouse/031-clone.t b/t/001_mouse/031-clone.t index cc39e22..6d5a052 100644 --- a/t/001_mouse/031-clone.t +++ b/t/001_mouse/031-clone.t @@ -1,11 +1,11 @@ #!/usr/bin/env perl use strict; use warnings; -use Test::More tests => 12; +use Test::More; use Test::Exception; my %triggered; -do { +{ package Foo; use Mouse; @@ -38,7 +38,24 @@ do { my ($self, @args) = @_; $self->meta->clone_object($self, @args); } -}; +} + +{ + package Bar; + use Mouse; + + has id => ( + is => 'ro', + isa => 'Str', + + required => 1, + ); + + sub clone { + my ($self, @args) = @_; + $self->meta->clone_object($self, @args); + } +} my $foo = Foo->new(bar => [ 1, 2, 3 ], quuux => "indeed"); @@ -60,6 +77,13 @@ is_deeply($clone->bar, [ 1 .. 3 ], "clone attr"); is($clone->baz, "foo", "init_arg=undef means the attr is ignored"); is($clone->quux, "yes", "clone uses init_arg and not attribute name"); +lives_and { + my $bar = Bar->new(id => 'xyz'); + my $c = $bar->clone; + + is_deeply $bar, $c, "clone() with required attributes"; +}; + throws_ok { Foo->meta->clone_object("constant"); } qr/You must pass an instance of the metaclass \(Foo\), not \(constant\)/; @@ -68,4 +92,4 @@ throws_ok { Foo->meta->clone_object(Foo->meta) } qr/You must pass an instance of the metaclass \(Foo\), not \(Mouse::Meta::Class=HASH\(\w+\)\)/; - +done_testing;