File Coverage

blib/lib/MooX/ReturnModifiers.pm
Criterion Covered Total %
statement 32 32 100.0
branch 3 4 75.0
condition 2 3 66.6
subroutine 12 12 100.0
pod 7 7 100.0
total 56 58 96.5


line stmt bran cond sub pod time code
1             package MooX::ReturnModifiers;
2              
3 8     8   142021 use strict;
  8         14  
  8         225  
4 8     8   35 use warnings;
  8         11  
  8         253  
5 8     8   32 use Carp qw/croak/;
  8         14  
  8         689  
6              
7             our $VERSION = '0.09';
8              
9 8     8   37 use Exporter 'import';
  8         10  
  8         586  
10              
11             our @EXPORT = qw/return_modifiers/;
12             our @EXPORT_OK = qw/return_modifiers return_has return_with return_around return_extends return_before return_after/;
13              
14             our $moo_modifiers;
15 8     8   2861 BEGIN { $moo_modifiers = [qw/has with around extends before after/] }
16              
17             sub return_modifiers {
18 15     15 1 3200 my %modifiers = ();
19 15   66     41 $_[1] ||= $moo_modifiers; # ???
20 15         19 for ( @{ $_[1] } ) {
  15         37  
21 20 100       94 unless ( $modifiers{$_} = $_[0]->can($_) ) {
22 1         129 croak "Can't find method <$_> in <$_[0]>";
23             }
24             }
25 14 50       72 return $_[2] ? \%modifiers : %modifiers;
26             }
27              
28             sub return_has {
29 1     1 1 1634 my %mod = return_modifiers( $_[0], [qw/has/] );
30 1         5 return $mod{has};
31             }
32              
33             sub return_with {
34 1     1 1 1314 my %mod = return_modifiers( $_[0], [qw/with/] );
35 1         4 return $mod{with};
36             }
37              
38             sub return_around {
39 1     1 1 1318 my %mod = return_modifiers( $_[0], [qw/around/] );
40 1         6 return $mod{around};
41             }
42              
43             sub return_extends {
44 1     1 1 1331 my %mod = return_modifiers( $_[0], [qw/extends/] );
45 1         4 return $mod{extends};
46             }
47              
48             sub return_before {
49 1     1 1 1342 my %mod = return_modifiers( $_[0], [qw/before/] );
50 1         5 return $mod{before};
51             }
52              
53             sub return_after {
54 1     1 1 1503 my %mod = return_modifiers( $_[0], [qw/after/] );
55 1         4 return $mod{after};
56             }
57              
58             =head1 NAME
59              
60             MooX::ReturnModifiers - Returns Moo Modifiers as a Hash
61              
62             =head1 VERSION
63              
64             Version 0.09
65              
66             =head1 SYNOPSIS
67              
68             use MooX::ReturnModifiers;
69              
70             sub import {
71             my $target = caller;
72             my %modifiers = return_modifiers($target);
73            
74             ...
75             $modifers{has}->();
76             $modifers{with}->();
77             $modifers{extends}->();
78             $modifers{around}->();
79             $modifers{before}->();
80             $modifers{after}->();
81             }
82              
83             .... OR ......
84              
85             use MooX::ReturnModifiers qw/return_has/
86            
87             sub import {
88             my $target = caller;
89             my $has = return_has($target);
90            
91             $has->( .... );
92             }
93              
94              
95             =head1 EXPORT
96              
97             =head2 return_modifiers
98              
99             Return a list of Moo modifers. You can optionally pass your own ArrayRef of keys as the second argument.
100              
101             my %modifiers = return_modifiers($target, [qw/has/]);
102              
103             ....
104              
105             # (
106             # has => sub { ... }
107             # )
108              
109             =head2 EXPORT OK
110              
111             =head2 return_has
112              
113             my $has = return_has($target);
114              
115             =head2 return_extends
116              
117             my $extends = return_extends($target);
118              
119             =head2 return_with
120              
121             my $with = return_with($target);
122              
123             =head2 return_around
124              
125             my $around = return_around($target);
126              
127             =head2 return_before
128              
129             my $before = return_before($target);
130              
131             =head2 return_after
132              
133             my $after = return_after($target);
134              
135             =head1 AUTHOR
136              
137             Robert Acock, C<< >>
138              
139             =head1 BUGS
140              
141             Please report any bugs or feature requests to C, or through
142             the web interface at L. I will be notified, and then you'll
143             automatically be notified of progress on your bug as I make changes.
144              
145             =head1 SUPPORT
146              
147             You can find documentation for this module with the perldoc command.
148              
149             perldoc MooX::ReturnModifiers
150              
151             You can also look for information at:
152              
153             =over 4
154              
155             =item * RT: CPAN's request tracker (report bugs here)
156              
157             L
158              
159             =item * AnnoCPAN: Annotated CPAN documentation
160              
161             L
162              
163             =item * CPAN Ratings
164              
165             L
166              
167             =item * Search CPAN
168              
169             L
170              
171             =back
172              
173              
174             =head1 ACKNOWLEDGEMENTS
175              
176              
177             =head1 LICENSE AND COPYRIGHT
178              
179             Copyright 2017 Robert Acock.
180              
181             This program is free software; you can redistribute it and/or modify it
182             under the terms of the the Artistic License (2.0). You may obtain a
183             copy of the full license at:
184              
185             L
186              
187             Any use, modification, and distribution of the Standard or Modified
188             Versions is governed by this Artistic License. By using, modifying or
189             distributing the Package, you accept this license. Do not use, modify,
190             or distribute the Package, if you do not accept this license.
191              
192             If your Modified Version has been derived from a Modified Version made
193             by someone other than you, you are nevertheless required to ensure that
194             your Modified Version complies with the requirements of this license.
195              
196             This license does not grant you the right to use any trademark, service
197             mark, tradename, or logo of the Copyright Holder.
198              
199             This license includes the non-exclusive, worldwide, free-of-charge
200             patent license to make, have made, use, offer to sell, sell, import and
201             otherwise transfer the Package with respect to any patent claims
202             licensable by the Copyright Holder that are necessarily infringed by the
203             Package. If you institute patent litigation (including a cross-claim or
204             counterclaim) against any party alleging that the Package constitutes
205             direct or contributory patent infringement, then this Artistic License
206             to you shall terminate on the date that such litigation is filed.
207              
208             Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER
209             AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
210             THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
211             PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY
212             YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR
213             CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR
214             CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE,
215             EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
216              
217              
218             =cut
219              
220             1; # End of MooX::ReturnModifiers