move to github
[gitmo/MooseX-Storage.git] / lib / MooseX / Storage / Traits / DisableCycleDetection.pm
index 9d62b00..7c9d15a 100644 (file)
@@ -1,8 +1,24 @@
 package MooseX::Storage::Traits::DisableCycleDetection;
 use Moose::Role;
 
-our $VERSION   = '0.18';
-our $AUTHORITY = 'cpan:STEVAN';
+requires 'pack';
+requires 'unpack';
+
+around 'pack' => sub {
+    my ($orig, $self, %args) = @_;
+    $args{engine_traits} ||= [];
+    push(@{$args{engine_traits}}, 'DisableCycleDetection');
+    $self->$orig(%args);
+};
+
+around 'unpack' => sub {
+    my ($orig, $self, $data, %args) = @_;
+    $args{engine_traits} ||= [];
+    push(@{$args{engine_traits}}, 'DisableCycleDetection');
+    $self->$orig($data, %args);
+};
+
+no Moose::Role;
 
 1;
 
@@ -21,17 +37,16 @@ MooseX::Storage::Traits::DisableCycleDetection - A custom trait to bypass cycle
     use Moose;
     use MooseX::Storage;
     with Storage( traits => ['DisableCycleDetection'] );
-    
+
     has 'x' => ( is => 'rw', isa => 'HashRef' );
     has 'y' => ( is => 'rw', isa => 'HashRef' );
 
     my $ref = {};
 
     my $double = Double->new( 'x' => $ref, 'y' => $ref );
-    
+
     $double->pack;
+
 =head1 DESCRIPTION
 
 C<MooseX::Storage> implements a primitive check for circular references.
@@ -42,6 +57,8 @@ references, so if you know what you are doing, you can bypass this check.
 This trait is applied to all objects that inherit from it. To use this
 on a per-case basis, see C<disable_cycle_check> in L<MooseX::Storage::Basic>.
 
+=for stopwords culted
+
 See the SYNOPSIS for a nice example that can be easily cargo-culted.
 
 =head1 METHODS
@@ -56,7 +73,7 @@ See the SYNOPSIS for a nice example that can be easily cargo-culted.
 
 =head1 BUGS
 
-All complex software has bugs lurking in it, and this module is no 
+All complex software has bugs lurking in it, and this module is no
 exception. If you find a bug please either email me, or add the bug
 to cpan-RT.
 
@@ -74,3 +91,4 @@ This library is free software; you can redistribute it and/or modify
 it under the same terms as Perl itself.
 
 =cut
+