$|++; use Test::More no_plan => 1; { package Foo; use MooseX::Cache; use Cache::FileCache; cache( Cache::FileCache->new( { 'namespace' => __PACKAGE__, } ) ); has bar => ( isa => 'Str', is => 'rw', default => 'bar' ); } { my $foo = Foo->new(); is( $foo->bar, 'bar', 'is bar' ); $foo->bar('baz'); is( $foo->bar, 'baz', 'is baz' ); our $oid = $foo->oid; } { my $foo; ok( !defined $foo, 'foo is undef' ); ok( $foo = Foo->new( oid => $oid ), 'new foo via oid' ); isa_ok( $foo, 'Foo' ); is( $foo->bar, 'baz', 'baz still' ); } { my $bar = Foo->new(); my $bar2 = Foo->new( oid => $bar->oid ); ok( $bar != $bar2, 'not the same ref' ); is( $bar->oid, $bar2->oid, 'but the same object' ); is( $bar->bar, 'bar', 'is bar' ); is( $bar->bar(), $bar2->bar, 'the same bar' ); $bar->bar('baz'); is( $bar->bar, 'baz', 'is now baz' ); is( $bar->bar(), $bar2->bar, 'the same baz' ); }