From: Tomas Doran (t0m) Date: Thu, 25 Mar 2010 18:24:56 +0000 (+0000) Subject: Fix infinite recusion in classes which overload stringify and call into MX::Storage X-Git-Tag: 0.26~1 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=049541bdd8fe53d81ca4e0bc8cea4d5a79210ada;p=gitmo%2FMooseX-Storage.git Fix infinite recusion in classes which overload stringify and call into MX::Storage --- diff --git a/Changes b/Changes index 5988146..9c59a87 100644 --- a/Changes +++ b/Changes @@ -1,6 +1,8 @@ Revision history for MooseX-Storage * Fix URI for repository in metadata. + * Fix infinite recursion when collapsing objects which overload stringify + to freeze themselves. 0.25 * Add support for Union types (bumps Moose dep to 0.99) diff --git a/Makefile.PL b/Makefile.PL index b085239..dd9e177 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -41,7 +41,7 @@ author_requires 'IO::File' => '0.1'; author_tests 't/author'; -build_requires 'Test::More' => '0.42'; +build_requires 'Test::More' => '0.88'; build_requires 'Test::Deep' => '0'; build_requires 'Test::Exception' => '0'; build_requires 'Test::TempDir' => '0.02'; diff --git a/lib/MooseX/Storage/Engine.pm b/lib/MooseX/Storage/Engine.pm index cee4178..61ce8ae 100644 --- a/lib/MooseX/Storage/Engine.pm +++ b/lib/MooseX/Storage/Engine.pm @@ -22,7 +22,7 @@ has 'seen' => ( default => sub {{}} ); -has 'object' => (is => 'rw', isa => 'Object'); +has 'object' => (is => 'rw', isa => 'Object', predicate => '_has_object'); has 'class' => (is => 'rw', isa => 'Str'); ## this is the API used by other modules ... @@ -143,7 +143,7 @@ sub map_attributes { } grep { # Skip our special skip attribute :) !$_->does('MooseX::Storage::Meta::Attribute::Trait::DoNotSerialize') - } ($self->object || $self->class)->meta->get_all_attributes; + } ($self->_has_object ? $self->object : $self->class)->meta->get_all_attributes; } ## ------------------------------------------------------------------ diff --git a/t/300_overloaded.t b/t/300_overloaded.t new file mode 100644 index 0000000..d17593b --- /dev/null +++ b/t/300_overloaded.t @@ -0,0 +1,38 @@ +use strict; +use warnings; +use Test::More; +use Test::Exception; + +BEGIN { + eval { require JSON::Any } or do { + plan skip_all => "JSON::Any is required for this test"; + exit 0; + } +} + +{ + package Thing; + use Moose; + use MooseX::Storage; + + use overload + q{""} => 'as_string', + fallback => 1; + + with Storage('format' => 'JSON'); + + has foo => ( is => 'ro' ); + + sub as_string { shift->freeze } + + no Moose; +} + +my $i = Thing->new(foo => "bar"); + +lives_ok { + $i . ""; +} 'Can stringify without deep recursion'; + +done_testing; +