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