Version 0.32
[gitmo/MooseX-Storage.git] / lib / MooseX / Storage / Traits / DisableCycleDetection.pm
CommitLineData
5b7ea1fd 1package MooseX::Storage::Traits::DisableCycleDetection;
2use Moose::Role;
3
e44b5f54 4our $VERSION = '0.32';
5b7ea1fd 5our $AUTHORITY = 'cpan:STEVAN';
6
59abaf70 7requires 'pack';
8requires 'unpack';
9
10around 'pack' => sub {
11 my ($orig, $self, %args) = @_;
12 $args{engine_traits} ||= [];
13 push(@{$args{engine_traits}}, 'DisableCycleDetection');
14 $self->$orig(%args);
15};
16
17around 'unpack' => sub {
18 my ($orig, $self, $data, %args) = @_;
19 $args{engine_traits} ||= [];
20 push(@{$args{engine_traits}}, 'DisableCycleDetection');
21 $self->$orig($data, %args);
22};
23
f82612bc 24no Moose::Role;
25
5b7ea1fd 261;
27
28__END__
29
30=pod
31
32=head1 NAME
33
34MooseX::Storage::Traits::DisableCycleDetection - A custom trait to bypass cycle detection
35
36=head1 SYNOPSIS
37
38
39 package Double;
40 use Moose;
41 use MooseX::Storage;
42 with Storage( traits => ['DisableCycleDetection'] );
ec725183 43
5b7ea1fd 44 has 'x' => ( is => 'rw', isa => 'HashRef' );
45 has 'y' => ( is => 'rw', isa => 'HashRef' );
46
47 my $ref = {};
48
49 my $double = Double->new( 'x' => $ref, 'y' => $ref );
ec725183 50
5b7ea1fd 51 $double->pack;
ec725183 52
5b7ea1fd 53=head1 DESCRIPTION
54
55C<MooseX::Storage> implements a primitive check for circular references.
56This check also triggers on simple cases as shown in the Synopsis.
57Providing the C<DisableCycleDetection> traits disables checks for any cyclical
58references, so if you know what you are doing, you can bypass this check.
59
60This trait is applied to all objects that inherit from it. To use this
61on a per-case basis, see C<disable_cycle_check> in L<MooseX::Storage::Basic>.
62
63See the SYNOPSIS for a nice example that can be easily cargo-culted.
64
65=head1 METHODS
66
67=head2 Introspection
68
69=over 4
70
71=item B<meta>
72
73=back
74
75=head1 BUGS
76
ec725183 77All complex software has bugs lurking in it, and this module is no
5b7ea1fd 78exception. If you find a bug please either email me, or add the bug
79to cpan-RT.
80
81=head1 AUTHOR
82
83Stevan Little E<lt>stevan.little@iinteractive.comE<gt>
84
85=head1 COPYRIGHT AND LICENSE
86
87Copyright 2007-2008 by Infinity Interactive, Inc.
88
89L<http://www.iinteractive.com>
90
91This library is free software; you can redistribute it and/or modify
92it under the same terms as Perl itself.
93
94=cut
ec725183 95