Deflator/Registry.pm

filter: Statementstmt 100% 32 / 32 Branchbran 75.0% 12 / 16 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 9 / 9 Podpod 100% 4 / 4 totaltotal 93.4% 57 / 61 CC 9 SCAR 9.9
CC
9
Cov
92%
find_deflator
4.1
find_inflator
4.1
add_deflator
2.0
CRAP 2.7
« LazyInflator/Meta/Role/Method/Constructor.pm ↑ Summary Deflator/Moose.pm »
1 #
2 # This file is part of MooseX-Attribute-Deflator
3 #
4 # This software is Copyright (c) 2012 by Moritz Onken.
5 #
6 # This is free software, licensed under:
7 #
8 # The (three-clause) BSD License
9 #
10 package MooseX::Attribute::Deflator::Registry;
11 {
12 15 $MooseX::Attribute::Deflator::Registry::VERSION = '2.2.2';
13 }
14  
15 # ABSTRACT: Registry class for attribute deflators
16 15 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 has deflators => (
19 traits => ['Hash'],
20 is => 'rw',
21 isa => 'HashRef[CodeRef]',
22 14 ▶ default => sub { {} },
Subroutine __ANON__: called CC=1 SCAR=0.0
23 15 handles => {
24 has_deflator => 'get',
25 get_deflator => 'get',
26 set_deflator => 'set',
27 _add_deflator => 'set',
28 }
29 );
30  
31 has inlined_deflators => (
32 traits => ['Hash'],
33 is => 'rw',
34 isa => 'HashRef[CodeRef]',
35 14 ▶ default => sub { {} },
Subroutine __ANON__: called CC=1 SCAR=0.0
36 15 handles => {
37 has_inlined_deflator => 'get',
38 get_inlined_deflator => 'get',
39 set_inlined_deflator => 'set',
40 _add_inlined_deflator => 'set',
41 }
42 );
43  
44 has inflators => (
45 traits => ['Hash'],
46 is => 'rw',
47 isa => 'HashRef[CodeRef]',
48 14 ▶ default => sub { {} },
Subroutine __ANON__: called CC=1 SCAR=0.0
49 15 handles => {
50 has_inflator => 'get',
51 get_inflator => 'get',
52 set_inflator => 'set',
53 _add_inflator => 'set',
54 }
55 );
56  
57 has inlined_inflators => (
58 traits => ['Hash'],
59 is => 'rw',
60 isa => 'HashRef[CodeRef]',
61 14 ▶ default => sub { {} },
Subroutine __ANON__: called CC=1 SCAR=0.0
62 15 handles => {
63 has_inlined_inflator => 'get',
64 get_inlined_inflator => 'get',
65 set_inlined_inflator => 'set',
66 _add_inlined_inflator => 'set',
67 }
68 );
69  
70 83 ▶sub add_deflator {
Subroutine add_deflator: called CC=2 SCAR=6.9
Pod documented
71 83 my ( $self, $name, $deflator, $inlined ) = @_;
72 83 ▶ $self->_add_inlined_deflator( $name, $inlined ) if ($inlined);
Branch: 1 branch
BranchTrueFalseTotal
if $inlined 79 4 83
73 83 return $self->_add_deflator( $name, $deflator );
74 }
75  
76 171 ▶sub find_deflator {
Subroutine find_deflator: called CC=4 SCAR=14.0
Pod documented
77 171 my ( $self, $constraint, $norecurse ) = @_;
78 171 ( my $name = $constraint->name ) =~ s/\[.*\]/\[\]/;
79 171 my $sub = $self->get_deflator($name);
80 171 ▶ return ( $constraint, $sub, $self->get_inlined_deflator($name) )
Branch: 1 branch
BranchTrueFalseTotal
if $sub 93 78 171
81 if ($sub);
82 78 ▶ return undef if ($norecurse);
Branch: 1 branch
BranchTrueFalseTotal
if $norecurse 0 78 78
83 78 ▶ return $self->find_deflator( $constraint->parent )
Branch: 1 branch
BranchTrueFalseTotal
if $constraint->has_parent 78 0 78
84 if ( $constraint->has_parent );
85 }
86  
87 80 ▶sub add_inflator {
Subroutine add_inflator: called CC=2 SCAR=6.9
Pod documented
88 80 my ( $self, $name, $inflator, $inlined ) = @_;
89 80 ▶ $self->_add_inlined_inflator( $name, $inlined ) if ($inlined);
Branch: 1 branch
BranchTrueFalseTotal
if $inlined 78 2 80
90 80 return $self->_add_inflator( $name, $inflator );
91 }
92  
93 169 ▶sub find_inflator {
Subroutine find_inflator: called CC=4 SCAR=14.0
Pod documented
94 169 my ( $self, $constraint, $norecurse ) = @_;
95 169 ( my $name = $constraint->name ) =~ s/\[.*\]/\[\]/;
96 169 my $sub = $self->get_inflator($name);
97 169 ▶ return ( $constraint, $sub, $self->get_inlined_inflator($name) )
Branch: 1 branch
BranchTrueFalseTotal
if $sub 88 81 169
98 if ($sub);
99 81 ▶ return undef if ($norecurse);
Branch: 1 branch
BranchTrueFalseTotal
if $norecurse 0 81 81
100 81 ▶ return $self->find_inflator( $constraint->parent )
Branch: 1 branch
BranchTrueFalseTotal
if $constraint->has_parent 81 0 81
101 if ( $constraint->has_parent );
102 }
103  
104 15 1;
105  
106  
107  
108 =pod
109  
110 =head1 NAME
111  
112 MooseX::Attribute::Deflator::Registry - Registry class for attribute deflators
113  
114 =head1 VERSION
115  
116 version 2.2.2
117  
118 =head1 DESCRIPTION
119  
120 This class contains a registry for deflator and inflator functions.
121  
122 =head1 ATTRIBUTES
123  
124 =over 4
125  
126 =item B<< inflators ( isa => HashRef[CodeRef] ) >>
127  
128 =item B<< deflators ( isa => HashRef[CodeRef] ) >>
129  
130 =back
131  
132 =head1 METHODS
133  
134 =over 4
135  
136 =item B<< add_inflator( $type_constraint, $coderef ) >>
137  
138 =item B<< add_deflator( $type_constraint, $coderef ) >>
139  
140 =item B<< set_inflator( $type_constraint, $coderef ) >>
141  
142 =item B<< set_deflator( $type_constraint, $coderef ) >>
143  
144 Add a inflator/deflator function for C<$type_constraint>. Existing functions
145 are overwritten.
146  
147 =item B<< has_inflator( $type_constraint ) >>
148  
149 =item B<< has_deflator( $type_constraint ) >>
150  
151 Predicate methods.
152  
153 =item B<< find_inflator( $type_constraint ) >>
154  
155 =item B<< find_deflator( $type_constraint ) >>
156  
157 Finds a suitable deflator/inflator by bubbling up the type hierarchy.
158 it returns the matching type constraint, its deflator an optionally
159 its inlined deflator if it exists.
160  
161 =back
162  
163 =head1 AUTHOR
164  
165 Moritz Onken
166  
167 =head1 COPYRIGHT AND LICENSE
168  
169 This software is Copyright (c) 2012 by Moritz Onken.
170  
171 This is free software, licensed under:
172  
173 The (three-clause) BSD License
174  
175 =cut
176  
177  
178 __END__
« LazyInflator/Meta/Role/Method/Constructor.pm ↑ Summary Deflator/Moose.pm »