File Coverage

blib/lib/MooseX/Storage/Traits/DisableCycleDetection.pm
Criterion Covered Total %
statement 9 9 100.0
branch n/a
condition n/a
subroutine 3 3 100.0
pod n/a
total 12 12 100.0


line stmt bran cond sub pod time code
1             package MooseX::Storage::Traits::DisableCycleDetection;
2             # ABSTRACT: A custom trait to bypass cycle detection
3              
4             our $VERSION = '0.50';
5              
6 1     1   719 use Moose::Role;
  1         2  
  1         9  
7 1     1   4754 use namespace::autoclean;
  1         2  
  1         14  
8              
9             requires 'pack';
10             requires 'unpack';
11              
12             around 'pack' => sub {
13             my ($orig, $self, %args) = @_;
14             $args{engine_traits} ||= [];
15             push(@{$args{engine_traits}}, 'DisableCycleDetection');
16             $self->$orig(%args);
17             };
18              
19             around 'unpack' => sub {
20             my ($orig, $self, $data, %args) = @_;
21             $args{engine_traits} ||= [];
22             push(@{$args{engine_traits}}, 'DisableCycleDetection');
23             $self->$orig($data, %args);
24             };
25              
26 1     1   196 no Moose::Role;
  1         2  
  1         4  
27              
28             1;
29              
30             __END__
31              
32             =pod
33              
34             =encoding UTF-8
35              
36             =head1 NAME
37              
38             MooseX::Storage::Traits::DisableCycleDetection - A custom trait to bypass cycle detection
39              
40             =head1 VERSION
41              
42             version 0.50
43              
44             =head1 SYNOPSIS
45              
46             package Double;
47             use Moose;
48             use MooseX::Storage;
49             with Storage( traits => ['DisableCycleDetection'] );
50              
51             has 'x' => ( is => 'rw', isa => 'HashRef' );
52             has 'y' => ( is => 'rw', isa => 'HashRef' );
53              
54             my $ref = {};
55              
56             my $double = Double->new( 'x' => $ref, 'y' => $ref );
57              
58             $double->pack;
59              
60             =head1 DESCRIPTION
61              
62             C<MooseX::Storage> implements a primitive check for circular references.
63             This check also triggers on simple cases as shown in the Synopsis.
64             Providing the C<DisableCycleDetection> traits disables checks for any cyclical
65             references, so if you know what you are doing, you can bypass this check.
66              
67             This trait is applied to all objects that inherit from it. To use this
68             on a per-case basis, see C<disable_cycle_check> in L<MooseX::Storage::Basic>.
69              
70             =for stopwords culted
71              
72             See the SYNOPSIS for a nice example that can be easily cargo-culted.
73              
74             =head1 METHODS
75              
76             =head2 Introspection
77              
78             =over 4
79              
80             =item B<meta>
81              
82             =back
83              
84             =head1 BUGS
85              
86             All complex software has bugs lurking in it, and this module is no
87             exception. If you find a bug please or add the bug to cpan-RT
88             at L<https://rt.cpan.org/Dist/Display.html?Queue=MooseX-Storage>.
89              
90             =head1 AUTHORS
91              
92             =over 4
93              
94             =item *
95              
96             Chris Prather <chris.prather@iinteractive.com>
97              
98             =item *
99              
100             Stevan Little <stevan.little@iinteractive.com>
101              
102             =item *
103              
104             יובל קוג'מן (Yuval Kogman) <nothingmuch@woobling.org>
105              
106             =back
107              
108             =head1 COPYRIGHT AND LICENSE
109              
110             This software is copyright (c) 2007 by Infinity Interactive, Inc..
111              
112             This is free software; you can redistribute it and/or modify it under
113             the same terms as the Perl 5 programming language system itself.
114              
115             =cut