1use strict;
2use warnings;
3
4package MyCloned;
5use Moose;
6use MooseX::Attribute::ChainedClone;
7
8has foo => ( is => 'rw', traits => ['ChainedClone'] );
9has writer =>
10    ( is => 'rw', writer => 'set_writer', traits => ['ChainedClone'] );
11
12package main;
13use Scalar::Util qw(refaddr);
14use Test::More;
15
16is( MyCloned->meta->get_attribute("foo")->accessor_metaclass,
17    'MooseX::Attribute::ChainedClone::Method::Accessor',
18    'accessor metaclass set'
19);
20
21ok( my $object = MyCloned->new( foo => "init", writer => "init" ), "build object" );
22ok( my $addr = refaddr $object, "get refaddr" );
23
24{
25    ok( my $clone = $object->foo("bar"), "set attribute and get clone" );
26    is( $object->foo, "init", '$object keeps value' );
27    is( $clone->foo,  "bar",  '$clone has new value' );
28    ok( $clone->isa("MyCloned"), "isa object" );
29    isnt( $addr, refaddr $clone, "refaddr doens't match" );
30}
31
32{
33    ok( my $clone = $object->set_writer("bar"), "set writer attribute and get clone" );
34    is( $object->writer, "init", '$object keeps value' );
35    is( $clone->writer,  "bar",  '$clone has new value' );
36    ok( $clone->isa("MyCloned"), "isa object" );
37    isnt( $addr, refaddr $clone, "refaddr doens't match" );
38}
39
40done_testing;
41