File Coverage

blib/lib/MooX/ReturnModifiers.pm
Criterion Covered Total %
statement 36 36 100.0
branch 6 6 100.0
condition 2 2 100.0
subroutine 14 14 100.0
pod 8 8 100.0
total 66 66 100.0


line stmt bran cond sub pod time code
1             package MooX::ReturnModifiers;
2              
3 9     9   1062052 use strict;
  9         19  
  9         328  
4 9     9   40 use warnings;
  9         18  
  9         597  
5 9     9   57 use Carp qw/croak/;
  9         16  
  9         650  
6              
7             our $VERSION = '1.000002';
8              
9 9     9   64 use Exporter 'import';
  9         23  
  9         1551  
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 return_sub/;
13              
14             sub return_modifiers {
15 17     17 1 1347748 my $target = shift;
16 17         38 my %modifiers = ();
17 17   100     103 $_[0] ||= [qw/has with around extends before after sub/];
18 17         31 for ( @{ $_[0] } ) {
  17         57  
19 29 100       86 if ($_ eq 'sub') {
20             $modifiers{$_} = sub {
21 2     2   14 my ($sub, $cb) = @_;
22 9     9   65 no strict 'refs';
  9         24  
  9         3832  
23 2         4 *{"${target}::${sub}"} = $cb;
  2         2378  
24 3         19 };
25 3         8 next;
26             }
27 26 100       213 unless ( $modifiers{$_} = $target->can($_) ) {
28 1         233 croak "Can't find method <$_> in <$target>";
29             }
30             }
31 16 100       117 return $_[1] ? \%modifiers : %modifiers;
32             }
33              
34 1     1 1 1756 sub return_has {return_modifiers($_[0], [qw/has/], 1)->{has}}
35              
36 1     1 1 1699 sub return_with {return_modifiers($_[0], [qw/with/], 1)->{with}}
37              
38 1     1 1 1608 sub return_after {return_modifiers($_[0], [qw/after/], 1)->{after}}
39              
40 1     1 1 2679 sub return_before {return_modifiers($_[0], [qw/before/], 1)->{before}}
41              
42 1     1 1 2281 sub return_around {return_modifiers($_[0], [qw/around/], 1)->{around}}
43              
44 1     1 1 2297 sub return_extends {return_modifiers($_[0], [qw/extends/], 1)->{extends}}
45              
46 1     1 1 6 sub return_sub {return_modifiers($_[0], [qw/sub/], 1)->{sub}}
47              
48             1;
49              
50             __END__