blib/lib/Type/Tiny/Role.pm

filter: Statementstmt 100% 72 / 72 Branchbran 64.2% 18 / 28 Conditioncond 41.6% 5 / 12 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 100% 23 / 23 Podpod 100% 5 / 5 totaltotal 83.6% 123 / 147 CC 19 SCAR 13.1
CC
19
Cov
85%
_exporter_fail
9.1
validate_explain
6.8
__ANON__
3.5
CRAP 3.7
« blib/lib/Type/Tiny/ConstrainedObject.pm ↑ Summary blib/lib/Types/Common/String.pm »
1 package Type::Tiny::Role;
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::Role::AUTHORITY = 'cpan:TOBYINK';
9 25 $Type::Tiny::Role::VERSION = '2.010001';
10 }
11  
12 25 $Type::Tiny::Role::VERSION =~ tr/_//d;
13  
14 25 ▶use Scalar::Util qw< blessed weaken >;
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 { 'Role' }
Subroutine _short_name: called CC=1 SCAR=0.0
23  
24 1 ▶sub _exporter_fail {
Subroutine _exporter_fail: called CC=7 SCAR=22.0
25 1 my ( $class, $name, $opts, $globals ) = @_;
26 1 my $caller = $globals->{into};
27
28 1 ▶ $opts->{name} = $name unless exists $opts->{name}; $opts->{name} =~ s/:://g;
Branch: 1 branch
BranchTrueFalseTotal
unless exists $opts->{"name"} 1 0 1
29 1 ▶ $opts->{role} = $name unless exists $opts->{role};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $opts->{"role"} 1 0 1
30 1 my $type = $class->new($opts);
31
32 $INC{'Type/Registry.pm'}
33 ? 'Type::Registry'->for_class( $caller )->add_type( $type )
34 : ( $Type::Registry::DELAYED{$caller}{$type->name} = $type )
35 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
36 1 return map +( $_->{name} => $_->{code} ), @{ $type->exportables };
37 }
38  
39 25 my %cache;
40  
41 53 ▶sub new {
Subroutine new: called CC=3 SCAR=11.0
Pod documented
42 53 my $proto = shift;
43 53 ▶ my %opts = ( @_ == 1 ) ? %{ $_[0] } : @_;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 ? : 2 51 53
44 53 ▶ _croak "Need to supply role name" unless exists $opts{role};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $opts{"role"} 1 52 53
45 52 return $proto->SUPER::new( %opts );
46 }
47  
48 75 ▶sub role { $_[0]{role} }
Subroutine role: called CC=1 SCAR=0.0
Pod documented
49 385 ▶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
336490
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
50  
51 750 ▶sub has_inlined { !!1 }
Subroutine has_inlined: called CC=1 SCAR=0.0
Pod documented
52  
53 1343 ▶sub _is_null_constraint { 0 }
Subroutine _is_null_constraint: called CC=1 SCAR=0.0
54  
55 15 ▶sub _build_constraint {
Subroutine _build_constraint: called CC=1 SCAR=0.2
56 15 my $self = shift;
57 15 my $role = $self->role;
58 27 ▶ return sub {
Subroutine __ANON__: called CC=3 SCAR=12.5
59 27 ▶ blessed( $_ ) and do {
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($_) and do { my $method = $_->can("DOES") || $_->can("isa"); $_->$method($role) } 27 0 27
60 27 ▶ my $method = $_->can( 'DOES' ) || $_->can( 'isa' );
Condition33%1/3
$_->can('DOES') || $_->can('isa')
l!l&&r!l&&!r
2700
MC/DC0%0/2
$_->can('DOES') || $_->can('isa')
$_->can('DOES') $_->can('isa')
Truth table33%1/3
A || B
A= $_->can('DOES')B= $_->can('isa')
ABresult
1X1
011
000
61 27 $_->$method( $role );
62 }
63 15 };
64 } #/ sub _build_constraint
65  
66 49 ▶sub _build_inlined {
Subroutine _build_inlined: called CC=1 SCAR=0.0
67 49 my $self = shift;
68 49 my $role = $self->role;
69 385 ▶ sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
70 385 my $var = $_[1];
71 385 my $code =
72 qq{Scalar::Util::blessed($var) and do { my \$method = $var->can('DOES')||$var->can('isa'); $var->\$method(q[$role]) }};
73 385 ▶ return qq{do { use Scalar::Util (); $code }} if $Type::Tiny::AvoidCallbacks;
Branch: 1 branch
BranchTrueFalseTotal
if $Type::Tiny::AvoidCallbacks 45 340 385
74 340 $code;
75 49 };
76 } #/ sub _build_inlined
77  
78 2 ▶sub _build_default_message {
Subroutine _build_default_message: called CC=2 SCAR=6.9
79 2 my $self = shift;
80 2 my $c = $self->role;
81 1 ▶ return sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
82 1 sprintf '%s did not pass type constraint (not DOES %s)',
83 Type::Tiny::_dd( $_[0] ), $c;
84 }
85 2 ▶ if $self->is_anon;
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_anon 1 1 2
86 1 my $name = "$self";
87 1 ▶ return sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
88 1 sprintf '%s did not pass type constraint "%s" (not DOES %s)',
89 Type::Tiny::_dd( $_[0] ), $name, $c;
90 1 };
91 } #/ sub _build_default_message
92  
93 2 ▶sub validate_explain {
Subroutine validate_explain: called CC=6 SCAR=19.1
Pod documented
94 2 my $self = shift;
95 2 my ( $value, $varname ) = @_;
96 2 ▶ $varname = '$_' unless defined $varname;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $varname 0 2 2
97
98 2 ▶ return undef if $self->check( $value );
Branch: 1 branch
BranchTrueFalseTotal
if $self->check($value) 0 2 2
99 2 ▶ return ["Not a blessed reference"] unless blessed( $value );
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($value) 0 2 2
100 2 ▶ return ["Reference provides no DOES method to check roles"]
Branch: 1 branch
BranchTrueFalseTotal
unless $value->can("DOES") 0 2 2
101 unless $value->can( 'DOES' );
102
103 2 ▶ my $display_var = $varname eq q{$_} ? '' : sprintf( ' (in %s)', $varname );
Branch: 1 branch
BranchTrueFalseTotal
$varname eq '$_' ? : 2 0 2
104
105 return [
106 2 sprintf( '"%s" requires that the reference does %s', $self, $self->role ),
107 sprintf( "The reference%s doesn't %s", $display_var, $self->role ),
108 ];
109 } #/ sub validate_explain
110  
111 25 1;
112  
113 __END__
« blib/lib/Type/Tiny/ConstrainedObject.pm ↑ Summary blib/lib/Types/Common/String.pm »