File Coverage

blib/lib/MooX/Role/Parameterized/Mop.pm
Criterion Covered Total %
statement 49 49 100.0
branch 1 2 50.0
condition 1 3 33.3
subroutine 16 16 100.0
pod 0 9 0.0
total 67 79 84.8


line stmt bran cond sub pod time code
1             package MooX::Role::Parameterized::Mop;
2              
3 13     13   82 use strict;
  13         40  
  13         534  
4 13     13   67 use warnings;
  13         22  
  13         796  
5 13     13   72 use Carp qw(croak);
  13         22  
  13         838  
6 13     13   71 use Scalar::Util qw(blessed);
  13         66  
  13         8403  
7              
8             our $VERSION = "0.5O1";
9              
10             # ABSTRACT: small proxy to offer mop methods like has, with, requires, etc.
11              
12             =head1 DESCRIPTION
13              
14             L<MooX::Role::Parameterized::Mop> is a proxy to the target class.
15              
16             This proxy offer C<has>, C<with>, C<before>, C<around>, C<after>, C<requires> and C<method> to avoid inject magic around the L<apply>
17              
18             It also provides C<meta> as an alias of TARGET_PACKAGE->meta
19             =cut
20              
21             sub new {
22 25     25 0 99 my ( $klass, %args ) = @_;
23              
24 25         151 return bless { target => $args{target}, role => $args{role} }, $klass;
25             }
26              
27             sub has {
28 25     25 0 221 my $self = shift;
29 25         47 goto &{ $self->{target} . '::has' };
  25         220  
30             }
31              
32             sub with {
33 4     4 0 43 my $self = shift;
34 4         19 goto &{ $self->{target} . '::with' };
  4         33  
35             }
36              
37             sub before {
38 1     1 0 21 my $self = shift;
39 1         2 goto &{ $self->{target} . '::before' };
  1         6  
40             }
41              
42             sub around {
43 1     1 0 46 my $self = shift;
44 1         3 goto &{ $self->{target} . '::around' };
  1         6  
45             }
46              
47             sub after {
48 1     1 0 29 my $self = shift;
49 1         2 goto &{ $self->{target} . '::after' };
  1         8  
50             }
51              
52             sub meta {
53 1     1 0 8 my $self = shift;
54              
55 1         9 return $self->{target}->meta;
56             }
57              
58             sub requires {
59 9     9 0 37149 my $self = shift;
60              
61 9         44 goto &{ $self->{role} . '::requires' };
  9         64  
62             }
63              
64             sub method {
65 24     24 0 85625 my ( $self, $name, $code ) = @_;
66 24         62 my $target = $self->{target};
67              
68 24 50 33     102 carp("method ${target}::${name} already exists, overriding...")
69             if $MooX::Role::Parameterized::VERBOSE && $target->can($name);
70              
71             {
72 13     13   99 no strict 'refs';
  13         25  
  13         602  
  24         41  
73 13     13   2156 no warnings 'redefine';
  13         28  
  13         737  
74 13     13   68 use warnings FATAL => 'uninitialized';
  13         55  
  13         2197  
75              
76 24         47 *{ ${target} . '::' . ${name} } = $code;
  24         217  
77             }
78             }
79              
80             1;