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