blib/lib/Function/Interface/Types.pm

filter: Statementstmt 62.5% 20 / 32 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 66.6% 6 / 9 Podpod n/a totaltotal 55.3% 26 / 47 CC 5 SCAR 18.2
CC
5
Cov
53%
__ANON__
12.0
__ANON__
12.0
__ANON__
2.0
CRAP 6.2
« blib/lib/Function/Interface/Impl.pm ↑ Summary blib/lib/Function/Interface/Info/Function.pm »
1 package Function::Interface::Types;
2  
3 1 ▶use v5.14.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 our $VERSION = "0.04";
7  
8 1 use Type::Library -base,
9 1 ▶ -declare => qw( ImplOf );
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 ▶use Types::Standard -types;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use Class::Load qw(is_class_loaded);
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 __PACKAGE__->add_type({
16 name => 'ImplOf',
17 parent => ClassName | Object,
18 constraint_generator => sub {
19 0 ▶ my $self = $Type::Tiny::parameterize_type;
Subroutine __ANON__: not called CC=1 SCAR=6.9
20 0 my @interfaces = @_;
21  
22 0 my $display_name = $self->name_generator->($self, @interfaces);
23  
24 my %options = (
25 constraint => sub {
26 0 ▶ my ($package) = @_;
Subroutine __ANON__: not called CC=3 SCAR=24.8
27 0 for (@interfaces) {
28 0 ▶ return unless Function::Interface::Impl::impl_of($package, $_);
Branch: 1 branch
BranchTrueFalseTotal
unless Function::Interface::Impl::impl_of($package, $_) 0 0 0
29 }
30 0 return !!1;
31 },
32 display_name => $display_name,
33 parameters => [@interfaces],
34 message => sub {
35 0 ▶ my $package = ref $_ ? blessed($_) : $_;
Subroutine __ANON__: not called CC=3 SCAR=24.8
Branch: 1 branch
BranchTrueFalseTotal
ref $_ ? : 0 0 0
36 0 ▶ return "$package is not loaded" if !is_class_loaded($package);
Branch: 1 branch
BranchTrueFalseTotal
unless is_class_loaded($package) 0 0 0
37 0 return sprintf '%s did not pass type constraint "%s"', Type::Tiny::_dd($_), $display_name;
38 },
39 0 );
40  
41 0 return $self->create_child_type(%options);
42 },
43 1 });
44  
45 1 __PACKAGE__->meta->make_immutable;
46  
47 __END__
« blib/lib/Function/Interface/Impl.pm ↑ Summary blib/lib/Function/Interface/Info/Function.pm »