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 0.601;
2              
3 13     13   175 use v5.12;
  13         87  
4 13     13   68 use strict;
  13         29  
  13         374  
5 13     13   80 use warnings;
  13         19  
  13         648  
6 13     13   76 use Carp qw(croak);
  13         34  
  13         743  
7 13     13   1663 use Scalar::Util qw(blessed);
  13         23  
  13         7905  
8              
9             # ABSTRACT: small proxy to offer mop methods like has, with, requires, etc.
10              
11             =head1 DESCRIPTION
12              
13             L is a proxy to the target class.
14              
15             This proxy offer C, C, C, C, C, C and C to avoid inject magic around the L
16              
17             It also provides C as an alias of TARGET_PACKAGE->meta
18             =cut
19              
20             sub new {
21 25     25 0 96 my ( $klass, %args ) = @_;
22              
23 25         137 return bless { target => $args{target}, role => $args{role} }, $klass;
24             }
25              
26             sub has {
27 25     25 0 228 my $self = shift;
28 25         41 goto &{ $self->{target} . '::has' };
  25         221  
29             }
30              
31             sub with {
32 4     4 0 49 my $self = shift;
33 4         8 goto &{ $self->{target} . '::with' };
  4         30  
34             }
35              
36             sub before {
37 1     1 0 21 my $self = shift;
38 1         3 goto &{ $self->{target} . '::before' };
  1         6  
39             }
40              
41             sub around {
42 1     1 0 22 my $self = shift;
43 1         3 goto &{ $self->{target} . '::around' };
  1         5  
44             }
45              
46             sub after {
47 1     1 0 25 my $self = shift;
48 1         3 goto &{ $self->{target} . '::after' };
  1         6  
49             }
50              
51             sub meta {
52 1     1 0 8 my $self = shift;
53              
54 1         8 return $self->{target}->meta;
55             }
56              
57             sub requires {
58 9     9 0 24247 my $self = shift;
59              
60 9         34 goto &{ $self->{role} . '::requires' };
  9         88  
61             }
62              
63             sub method {
64 24     24 0 91635 my ( $self, $name, $code ) = @_;
65 24         64 my $target = $self->{target};
66              
67 24 50 33     99 carp("method ${target}::${name} already exists, overriding...")
68             if $MooX::Role::Parameterized::VERBOSE && $target->can($name);
69              
70             {
71 13     13   94 no strict 'refs';
  13         23  
  13         691  
  24         77  
72 13     13   81 no warnings 'redefine';
  13         30  
  13         2802  
73 13     13   2239 use warnings FATAL => 'uninitialized';
  13         25  
  13         1403  
74              
75 24         101 *{ ${target} . '::' . ${name} } = $code;
  24         224  
76             }
77             }
78              
79             1;