blib/lib/Moose/Meta/TypeConstraint/DuckType.pm

filter: Statementstmt 78.6% 59 / 75 Branchbran 28.5% 4 / 14 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 87.5% 14 / 16 Podpod 100% 4 / 4 totaltotal 71.9% 82 / 114 CC 9 SCAR 20.4
CC
9
Cov
70%
equals
30.0
get_message
4.1
new
2.0
CRAP 7.7
« blib/lib/Class/MOP/Method/Inlined.pm ↑ Summary blib/lib/Moose/Exporter.pm »
1 package Moose::Meta::TypeConstraint::DuckType;
2 398 our $VERSION = '2.4001';
3  
4 398 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 398 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 398 ▶use metaclass;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 398 ▶use B;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 398 ▶use Scalar::Util 'blessed';
Subroutine BEGIN: called CC=1 SCAR=0.0
10 398 ▶use List::Util 1.33 qw(all);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 398 ▶use Moose::Util 'english_list';
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 398 ▶use Moose::Util::TypeConstraints ();
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 398 ▶use parent 'Moose::Meta::TypeConstraint';
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 398 __PACKAGE__->meta->add_attribute('methods' => (
18 accessor => 'methods',
19 Class::MOP::_definition_context(),
20 ));
21  
22 48 ▶my $inliner = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
23 48 my $self = shift;
24 48 my $val = shift;
25  
26 return $self->parent->_inline_check($val)
27 . ' && do {' . "\n"
28 . 'my $val = ' . $val . ';' . "\n"
29 . '&List::Util::all(' . "\n"
30 . 'sub { $val->can($_) },' . "\n"
31 48 . join(', ', map { B::perlstring($_) } @{ $self->methods })
32 . ');' . "\n"
33 . '}';
34 398 };
35  
36 25 ▶sub new {
Subroutine new: called CC=2 SCAR=6.9
Pod documented
37 25 my ( $class, %args ) = @_;
38  
39 $args{parent}
40 25 = Moose::Util::TypeConstraints::find_type_constraint('Object');
41  
42 25 my @methods = @{ $args{methods} };
43 8 ▶ $args{constraint} = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
44 8 my $val = $_[0];
45 8 ▶ return all { $val->can($_) } @methods;
Subroutine __ANON__: called CC=1 SCAR=0.0
46 25 };
47  
48 25 $args{inlined} = $inliner;
49  
50 25 my $self = $class->SUPER::new(\%args);
51  
52 25 ▶ $self->compile_type_constraint()
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_has_compiled_type_constraint 0 25 25
53 unless $self->_has_compiled_type_constraint;
54  
55 25 return $self;
56 }
57  
58 0 ▶sub equals {
Subroutine equals: not called CC=5 SCAR=34.0
Pod documented
59 0 my ( $self, $type_or_name ) = @_;
60  
61 0 my $other = Moose::Util::TypeConstraints::find_type_constraint($type_or_name);
62  
63 0 ▶ return unless $other->isa(__PACKAGE__);
Branch: 1 branch
BranchTrueFalseTotal
unless $other->isa(__PACKAGE__) 0 0 0
64  
65 0 my @self_methods = sort @{ $self->methods };
66 0 my @other_methods = sort @{ $other->methods };
67  
68 0 ▶ return unless @self_methods == @other_methods;
Branch: 1 branch
BranchTrueFalseTotal
unless @self_methods == @other_methods 0 0 0
69  
70 0 ▶ while ( @self_methods ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@self_methods) 0 0 0
71 0 my $method = shift @self_methods;
72 0 my $other_method = shift @other_methods;
73  
74 0 ▶ return unless $method eq $other_method;
Branch: 1 branch
BranchTrueFalseTotal
unless $method eq $other_method 0 0 0
75 }
76  
77 0 return 1;
78 }
79  
80 0 ▶sub create_child_type {
Subroutine create_child_type: not called CC=1 SCAR=6.9
Pod documented
81 0 my ($self, @args) = @_;
82 0 return Moose::Meta::TypeConstraint->new(@args, parent => $self);
83 }
84  
85 31 ▶sub get_message {
Subroutine get_message: called CC=4 SCAR=14.2
Pod documented
86 31 my $self = shift;
87 31 my ($value) = @_;
88  
89 31 ▶ if ($self->has_message) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_message) 0 31 31
90 0 return $self->SUPER::get_message(@_);
91 }
92  
93 31 ▶ return $self->SUPER::get_message($value) unless blessed($value);
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($value) 24 7 31
94  
95 7 my @methods = grep { !$value->can($_) } @{ $self->methods };
96 7 my $class = blessed $value;
97 7 ▶ $class ||= $value;
Condition33%1/3
$class ||= $value
l!l&&r!l&&!r
700
MC/DC0%0/2
$class ||= $value
$class $value
Truth table33%1/3
A ||= B
A= $classB= $value
ABresult
1X1
011
000
98  
99 return $class
100 . " is missing methods "
101 7 . english_list(map { "'$_'" } @methods);
102 }
103  
104 398 1;
105  
106 # ABSTRACT: Type constraint for duck typing
107  
108 __END__
« blib/lib/Class/MOP/Method/Inlined.pm ↑ Summary blib/lib/Moose/Exporter.pm »