blib/lib/Type/Tiny/Duck.pm

filter: Statementstmt 88.5% 100 / 113 Branchbran 65.7% 25 / 38 Conditioncond 46.6% 7 / 15 MC/DCmcdc 11.1% 1 / 9 Subroutinesub 95.8% 23 / 24 Podpod 100% 6 / 6 totaltotal 79.0% 162 / 205 CC 28 SCAR 14.2
CC
28
Cov
80%
__ANON__
8.4
_exporter_fail
6.3
new_intersection
5.8
CRAP 4.1
« blib/lib/Error/TypeTiny/Assertion.pm ↑ Summary blib/lib/Type/Tiny/ConstrainedObject.pm »
1 package Type::Tiny::Duck;
2  
3 25 ▶use 5.008001;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 25 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 25 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 25 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
8 25 $Type::Tiny::Duck::AUTHORITY = 'cpan:TOBYINK';
9 25 $Type::Tiny::Duck::VERSION = '2.010001';
10 }
11  
12 25 $Type::Tiny::Duck::VERSION =~ tr/_//d;
13  
14 25 ▶use Scalar::Util qw< blessed >;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 1 ▶sub _croak ($;@) { require Error::TypeTiny; goto \&Error::TypeTiny::croak }
Subroutine _croak: called CC=1 SCAR=0.0
17  
18 25 ▶use Exporter::Tiny 1.004001 ();
Subroutine BEGIN: called CC=1 SCAR=0.0
19 25 ▶use Type::Tiny::ConstrainedObject ();
Subroutine BEGIN: called CC=1 SCAR=0.0
20 25 our @ISA = qw( Type::Tiny::ConstrainedObject Exporter::Tiny );
21  
22 3 ▶sub _short_name { 'Duck' }
Subroutine _short_name: called CC=1 SCAR=0.0
23  
24 1 ▶sub _exporter_fail {
Subroutine _exporter_fail: called CC=5 SCAR=18.4
25 1 my ( $class, $type_name, $methods, $globals ) = @_;
26 1 my $caller = $globals->{into};
27 1 my $type = $class->new(
28 name => $type_name,
29 methods => [ @$methods ],
30 );
31 $INC{'Type/Registry.pm'}
32 ? 'Type::Registry'->for_class( $caller )->add_type( $type, $type_name )
33 : ( $Type::Registry::DELAYED{$caller}{$type_name} = $type )
34 1 ▶ unless( ref($caller) or $caller eq '-lexical' or $globals->{'lexical'} );
Branch: 2 branches
BranchTrueFalseTotal
unless ref $caller or $caller eq "-lexical" or $globals->{"lexical"} 1 0 1
$INC{'Type/Registry.pm'} ? : 0 1 1
Condition33%2/6
ref $caller or $caller eq "-lexical" or $globals->{"lexical"}
l!l&&r!l&&!r
001
ref $caller or $caller eq "-lexical"
l!l&&r!l&&!r
001
MC/DC0%0/3
ref $caller or $caller eq "-lexical" or $globals->{"lexical"}
ref $caller $caller eq "-lexical" $globals->{"lexical"}
Truth table25%1/4
A or B or C
A= ref $callerB= $caller eq "-lexical"C= $globals->{"lexical"}
ABCresult
1XX1
01X1
0011
0000
35 1 return map +( $_->{name} => $_->{code} ), @{ $type->exportables };
36 }
37  
38 53 ▶sub new {
Subroutine new: called CC=5 SCAR=16.3
Pod documented
39 53 my $proto = shift;
40
41 0 ▶ my %opts = ( @_ == 1 ) ? %{ $_[0] } : @_;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 ? : 0 53 53
42 53 ▶ _croak "Need to supply list of methods" unless exists $opts{methods};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $opts{"methods"} 1 52 53
43
44 52 ▶ $opts{methods} = [ $opts{methods} ] unless ref $opts{methods};
Branch: 1 branch
BranchTrueFalseTotal
unless ref $opts{"methods"} 0 52 52
45
46 52 if ( Type::Tiny::_USE_XS ) {
47 52 my $methods = join ",", sort( @{ $opts{methods} } );
48 52 my $xsub = Type::Tiny::XS::get_coderef_for( "HasMethods[$methods]" );
49 52 ▶ $opts{compiled_type_constraint} = $xsub if $xsub;
Branch: 1 branch
BranchTrueFalseTotal
if $xsub 49 3 52
50 }
51 elsif ( Type::Tiny::_USE_MOUSE ) {
52 require Mouse::Util::TypeConstraints;
53 my $maker = "Mouse::Util::TypeConstraints"->can( "generate_can_predicate_for" );
54 $opts{compiled_type_constraint} = $maker->( $opts{methods} ) if $maker;
55 }
56
57 52 return $proto->SUPER::new( %opts );
58 } #/ sub new
59  
60 1 ▶sub new_intersection {
Subroutine new_intersection: called CC=5 SCAR=17.6
Pod documented
61 1 my $proto = shift;
62 0 ▶ my %opts = ( @_ == 1 ) ? %{ $_[0] } : @_;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 ? : 0 1 1
63 1 my @types = @{ delete $opts{type_constraints} };
64 1 my %values; ++$values{$_} for map @{$_->methods}, @types;
65 1 my @values = sort keys %values;
66 1 ▶ if ( $INC{'Types/Standard.pm'} and not keys %opts ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($INC{"Types/Standard.pm"} and not keys %opts) 1 0 1
Condition33%1/3
$INC{"Types/Standard.pm"} and not keys %opts
!ll&&!rl&&r
001
MC/DC0%0/2
$INC{"Types/Standard.pm"} and not keys %opts
$INC{"Types/Standard.pm"} not keys %opts
Truth table33%1/3
A and not(B)
A= $INC{"Types/Standard.pm"}B= not keys %opts
ABresult
0X0
100
111
67 1 return Types::Standard::HasMethods->of( @values );
68 }
69 0 return $proto->new( %opts, methods => \@values );
70 }
71  
72 49 ▶sub _lockdown {
Subroutine _lockdown: called CC=1 SCAR=0.0
73 49 my ( $self, $callback ) = @_;
74 49 $callback->( $self->{methods} );
75 }
76  
77 118 ▶sub methods { $_[0]{methods} }
Subroutine methods: called CC=1 SCAR=0.0
Pod documented
78 205 ▶sub inlined { $_[0]{inlined} ||= $_[0]->_build_inlined }
Subroutine inlined: called CC=2 SCAR=7.2
Pod documented
Condition66%2/3
$_[0]{"inlined"} ||= $_[0]->_build_inlined
l!l&&r!l&&!r
160450
MC/DC0%0/2
$_[0]{"inlined"} ||= $_[0]->_build_inlined
$_[0]{"inlined"} $_[0]->_build_inlined
Truth table66%2/3
A ||= B
A= $_[0]{"inlined"}B= $_[0]->_build_inlined
ABresult
1X1
011
000
79  
80 396 ▶sub has_inlined { !!1 }
Subroutine has_inlined: called CC=1 SCAR=0.0
Pod documented
81  
82 658 ▶sub _is_null_constraint { 0 }
Subroutine _is_null_constraint: called CC=1 SCAR=0.0
83  
84 7 ▶sub _build_constraint {
Subroutine _build_constraint: called CC=1 SCAR=0.0
85 7 my $self = shift;
86 7 my @methods = @{ $self->methods };
87 21 ▶ return sub {
Subroutine __ANON__: called CC=2 SCAR=7.6
88 21 ▶ blessed( $_[0] )
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($_[0]) and not grep((!$_[0]->can($_)), @methods) 21 0 21
89 and not grep( !$_[0]->can( $_ ), @methods );
90 7 };
91 }
92  
93 45 ▶sub _build_inlined {
Subroutine _build_inlined: called CC=1 SCAR=0.0
94 45 my $self = shift;
95 45 my @methods = @{ $self->methods };
96
97 45 my $xsub;
98 45 if ( Type::Tiny::_USE_XS ) {
99 45 my $methods = join ",", sort( @{ $self->methods } );
100 45 $xsub = Type::Tiny::XS::get_subname_for( "HasMethods[$methods]" );
101 }
102
103 205 ▶ sub {
Subroutine __ANON__: called CC=4 SCAR=14.0
104 205 my $var = $_[1];
105 205 local $" = q{ };
106
107 # If $var is $_ or $_->{foo} or $foo{$_} or somesuch, then we
108 # can't use it within the grep expression, so we need to save
109 # it into a temporary variable ($tmp).
110 205 ▶ my $code =
Branch: 1 branch
BranchTrueFalseTotal
$var =~ /\$_/ ? : 51 154 205
111 ( $var =~ /\$_/ )
112 ? qq{ Scalar::Util::blessed($var) and not do { my \$tmp = $var; grep(!\$tmp->can(\$_), qw/@methods/) } }
113 : qq{ Scalar::Util::blessed($var) and not grep(!$var->can(\$_), qw/@methods/) };
114
115 205 ▶ return qq{do { $Type::Tiny::SafePackage use Scalar::Util (); $code }}
Branch: 1 branch
BranchTrueFalseTotal
if $Type::Tiny::AvoidCallbacks 25 180 205
116 if $Type::Tiny::AvoidCallbacks;
117 180 ▶ return "$xsub\($var\)"
Branch: 1 branch
BranchTrueFalseTotal
if $xsub 180 0 180
118 if $xsub;
119 0 $code;
120 45 };
121 } #/ sub _build_inlined
122  
123 0 ▶sub _instantiate_moose_type {
Subroutine _instantiate_moose_type: not called CC=1 SCAR=6.9
124 0 my $self = shift;
125 0 my %opts = @_;
126 0 delete $opts{parent};
127 0 delete $opts{constraint};
128 0 delete $opts{inlined};
129
130 0 require Moose::Meta::TypeConstraint::DuckType;
131 0 return "Moose::Meta::TypeConstraint::DuckType"
132 ->new( %opts, methods => $self->methods );
133 } #/ sub _instantiate_moose_type
134  
135 1 ▶sub validate_explain {
Subroutine validate_explain: called CC=4 SCAR=14.2
Pod documented
136 1 my $self = shift;
137 1 my ( $value, $varname ) = @_;
138 1 ▶ $varname = '$_' unless defined $varname;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $varname 0 1 1
139
140 1 ▶ return undef if $self->check( $value );
Branch: 1 branch
BranchTrueFalseTotal
if $self->check($value) 0 1 1
141 1 ▶ return ["Not a blessed reference"] unless blessed( $value );
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($value) 0 1 1
142
143 1 require Type::Utils;
144 return [
145 sprintf(
146 '"%s" requires that the reference can %s',
147 $self,
148 1 Type::Utils::english_list( map qq["$_"], @{ $self->methods } ),
149 ),
150 map sprintf( 'The reference cannot "%s"', $_ ),
151 grep !$value->can( $_ ),
152 1 @{ $self->methods }
153 ];
154 } #/ sub validate_explain
155  
156 121 ▶push @Type::Tiny::CMP, sub {
Subroutine __ANON__: called CC=8 SCAR=21.3
157 121 my $A = shift->find_constraining_type;
158 121 my $B = shift->find_constraining_type;
159 121 ▶ return Type::Tiny::CMP_UNKNOWN
Branch: 1 branch
BranchTrueFalseTotal
unless $A->isa(__PACKAGE__) and $B->isa(__PACKAGE__) 113 8 121
Condition66%2/3
$A->isa(__PACKAGE__) and $B->isa(__PACKAGE__)
!ll&&!rl&&r
11308
MC/DC50%1/2
$A->isa(__PACKAGE__) and $B->isa(__PACKAGE__)
$A->isa(__PACKAGE__) $B->isa(__PACKAGE__)
Truth table66%2/3
A and B
A= $A->isa(__PACKAGE__)B= $B->isa(__PACKAGE__)
ABresult
0X0
100
111
160 unless $A->isa( __PACKAGE__ ) && $B->isa( __PACKAGE__ );
161
162 8 my %seen;
163 8 for my $word ( @{ $A->methods } ) {
164 21 $seen{$word} += 1;
165 }
166 8 for my $word ( @{ $B->methods } ) {
167 19 $seen{$word} += 2;
168 }
169
170 8 my $values = join( '', CORE::values %seen );
171 8 ▶ if ( $values =~ /^3*$/ ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($values =~ /^3*$/) { } 0 8 8
elsif (not $values =~ /2/) { } 5 3 8
elsif (not $values =~ /1/) { } 3 0 3
172 0 return Type::Tiny::CMP_EQUIVALENT;
173 }
174 elsif ( $values !~ /2/ ) {
175 5 return Type::Tiny::CMP_SUBTYPE;
176 }
177 elsif ( $values !~ /1/ ) {
178 3 return Type::Tiny::CMP_SUPERTYPE;
179 }
180
181 0 return Type::Tiny::CMP_UNKNOWN;
182 25 };
183  
184 25 1;
185  
186 __END__
« blib/lib/Error/TypeTiny/Assertion.pm ↑ Summary blib/lib/Type/Tiny/ConstrainedObject.pm »