lib/Types/Interface.pm

filter: Statementstmt 100% 48 / 48 Branchbran 83.3% 10 / 12 Conditioncond 66.6% 4 / 6 MC/DCmcdc 50.0% 2 / 4 Subroutinesub 100% 12 / 12 Podpod n/a totaltotal 92.6% 76 / 82 CC 10 SCAR 10.0
CC
10
Cov
94%
__ANON__
4.0
__ANON__
4.0
__ANON__
4.0
CRAP 2.7
↑ Summary
1 1 ▶use 5.008;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 package Types::Interface;
6  
7 1 our $AUTHORITY = 'cpan:TOBYINK';
8 1 our $VERSION = '0.002';
9  
10 1 ▶use Carp qw( croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Role::Inspector qw( get_role_info );
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use Type::Library -base, -declare => qw( ClassDoesInterface ObjectDoesInterface );
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use Types::LoadableClass qw( LoadableClass );
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use Types::Standard qw( Object );
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 my %common = (
17 4 ▶ constraint_generator => sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
18 4 my ($role, %opts) = @_;
19 4 ▶ my $info = get_role_info($role)
Branch: 1 branch
BranchTrueFalseTotal
my $info = get_role_info($role) or croak("$role does not seem to be a role") 4 0 4
20 or croak("$role does not seem to be a role");
21 4 my @methods = @{$info->{api}};
22 @methods = grep(!/\A_/, @methods)
23 4 ▶ if exists($opts{private}) && !$opts{private};
Branch: 1 branch
BranchTrueFalseTotal
if exists $opts{"private"} and not $opts{"private"} 2 2 4
Condition66%2/3
exists $opts{"private"} and not $opts{"private"}
!ll&&!rl&&r
202
MC/DC50%1/2
exists $opts{"private"} and not $opts{"private"}
exists $opts{"private"} not $opts{"private"}
Truth table66%2/3
A and not(B)
A= exists $opts{"private"}B= not $opts{"private"}
ABresult
0X0
100
111
24
25 20 ▶ return sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
26 20 ▶ $_->DOES($role) or do {
Branch: 1 branch
BranchTrueFalseTotal
$_->DOES($role) or do { my $ok = 1; foreach my $method (@methods) { $_->can($method) or $ok = 0, next; } ; $ok } 8 12 20
27 12 my $ok = 1;
28 12 for my $method (@methods) {
29 30 ▶ $_->can($method) or ($ok=0, next);
Branch: 1 branch
BranchTrueFalseTotal
$_->can($method) or $ok = 0, next 18 12 30
30 }
31 12 $ok;
32 };
33 4 };
34 },
35
36 4 ▶ inline_generator => sub {
Subroutine __ANON__: called CC=4 SCAR=14.0
37 4 my ($role, %opts) = @_;
38 4 ▶ my $info = get_role_info($role)
Branch: 1 branch
BranchTrueFalseTotal
my $info = get_role_info($role) or croak("$role does not seem to be a role") 4 0 4
39 or croak("$role does not seem to be a role");
40 4 my @methods = @{$info->{api}};
41 @methods = grep(!/\A_/, @methods)
42 4 ▶ if exists($opts{private}) && !$opts{private};
Branch: 1 branch
BranchTrueFalseTotal
if exists $opts{"private"} and not $opts{"private"} 2 2 4
Condition66%2/3
exists $opts{"private"} and not $opts{"private"}
!ll&&!rl&&r
202
MC/DC50%1/2
exists $opts{"private"} and not $opts{"private"}
exists $opts{"private"} not $opts{"private"}
Truth table66%2/3
A and not(B)
A= exists $opts{"private"}B= not $opts{"private"}
ABresult
0X0
100
111
43
44 84 ▶ return sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
45 84 my $var = $_[1];
46 return (
47 undef,
48 84 sprintf(
49 '(%s->DOES(%s) or (%s))',
50 $var,
51 B::perlstring($role),
52 join(
53 ' and ',
54 map(
55 sprintf('%s->can(%s)', $var, B::perlstring($_)),
56 @methods,
57 ),
58 ),
59 ),
60 );
61 4 };
62 },
63 1 );
64  
65 1 __PACKAGE__->meta->add_type({
66 name => ClassDoesInterface,
67 parent => LoadableClass,
68 %common,
69 });
70  
71 1 __PACKAGE__->meta->add_type({
72 name => ObjectDoesInterface,
73 parent => Object,
74 %common,
75 });
76  
77 1 1;
78  
79 __END__
↑ Summary