File Coverage

blib/lib/MooX/Role/Parameterized/Mop.pm
Criterion Covered Total %
statement 51 51 100.0
branch 1 2 50.0
condition 1 3 33.3
subroutine 17 17 100.0
pod 0 9 0.0
total 70 82 85.3


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