Sub/Meta/Type.pm

filter: Statementstmt 100% 67 / 67 Branchbran 100% 20 / 20 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 21 / 21 Podpod 100% 9 / 9 totaltotal 100% 117 / 117 CC 11 SCAR 11.6
CC
11
Cov
100%
new
8.0
get_detail_message
4.0
BEGIN
1.0
CRAP 3.2
« Sub/Meta.pm ↑ Summary Sub/Meta/Creator.pm »
1 package Sub::Meta::Type;
2 5 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 5 ▶use parent qw(Type::Tiny);
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 5 ▶use Type::Coercion;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 5 ▶use Types::Standard qw(Ref InstanceOf);
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 26 ▶sub submeta { my $self = shift; return $self->{submeta} }
Subroutine submeta: called CC=1 SCAR=0.0
Pod documented
12 10 ▶sub submeta_strict_check { my $self = shift; return $self->{submeta_strict_check} }
Subroutine submeta_strict_check: called CC=1 SCAR=0.0
Pod documented
13 19 ▶sub find_submeta { my $self = shift; return $self->{find_submeta} }
Subroutine find_submeta: called CC=1 SCAR=0.0
Pod documented
14  
15 ## override
16 13 ▶sub new {
Subroutine new: called CC=8 SCAR=20.8
Pod documented
17 13 my $class = shift;
18 13 ▶ my %params = ( @_ == 1 ) ? %{ $_[0] } : @_;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 ? : 1 12 13
19  
20 ## no critic (Subroutines::ProtectPrivateSubs)
21 13 ▶ Type::Tiny::_croak "Need to supply submeta" unless exists $params{submeta};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $params{"submeta"} 2 11 13
22 11 ▶ Type::Tiny::_croak "Need to supply submeta_strict_check" unless exists $params{submeta_strict_check};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $params{"submeta_strict_check"} 1 10 11
23 10 ▶ Type::Tiny::_croak "Need to supply find_submeta" unless exists $params{find_submeta};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $params{"find_submeta"} 1 9 10
24 ## use critic
25  
26 9 ▶ if (!exists $params{name}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $params{"name"}) 8 1 9
27 8 ▶ $params{name} = $params{submeta_strict_check} ? 'StrictSubMeta' : 'SubMeta';
Branch: 1 branch
BranchTrueFalseTotal
$params{'submeta_strict_check'} ? : 2 6 8
28 }
29  
30 $params{inlined} = $params{submeta_strict_check}
31 2 ▶ ? sub { my ($self, $var) = @_; $self->submeta->is_strict_same_interface_inlined($var) }
Subroutine __ANON__: called CC=1 SCAR=0.0
32 9 ▶ : sub { my ($self, $var) = @_; $self->submeta->is_relaxed_same_interface_inlined($var) };
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
$params{'submeta_strict_check'} ? : 2 7 9
33  
34 9 return $class->SUPER::new(%params);
35 }
36  
37 ## override
38 16 ▶sub has_parent { return !!0 }
Subroutine has_parent: called CC=1 SCAR=0.0
Pod documented
39 20 ▶sub can_be_inlined { return !!1 }
Subroutine can_be_inlined: called CC=1 SCAR=0.0
Pod documented
40 20 ▶sub has_coercion { return !!1 }
Subroutine has_coercion: called CC=1 SCAR=0.0
Pod documented
41 12 ▶sub _is_null_constraint { return !!0 } ## no critic (ProhibitUnusedPrivateSubroutines)
Subroutine _is_null_constraint: called CC=1 SCAR=0.0
42  
43 ## override
44 4 ▶sub _build_display_name { ## no critic (ProhibitUnusedPrivateSubroutines)
Subroutine _build_display_name: called CC=1 SCAR=0.0
45 4 my $self = shift;
46 4 return sprintf('%s[%s]', $self->name, $self->submeta->display);
47 }
48  
49 #
50 # e.g.
51 # Reference bless( sub { "DUMMY" }, 'Sub::WrapInType' ) did not pass type constraint "SubMeta"
52 # Reason : invalid scalar return. got: Str, expected: Int
53 # Expected : sub (Int,Int) => Int
54 # Got : sub (Int,Int) => Str
55 #
56 ## override
57 4 ▶sub get_message {
Subroutine get_message: called CC=1 SCAR=0.0
Pod documented
58 4 my $self = shift;
59 4 my $other_meta = shift;
60  
61 4 my $default_message = $self->SUPER::get_message($other_meta);
62 4 my $detail_message = $self->get_detail_message($other_meta);
63  
64 4 my $message = <<"```";
65 $default_message
66 $detail_message
67 ```
68  
69 4 return $message;
70 }
71  
72 5 ▶sub get_detail_message {
Subroutine get_detail_message: called CC=4 SCAR=13.9
Pod documented
73 5 my $self = shift;
74 5 my $other_meta = shift;
75  
76 5 state $SubMeta = InstanceOf['Sub::Meta'];
77  
78 5 my ($error_message, $expected, $got);
79 5 ▶ if ($self->submeta_strict_check) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->submeta_strict_check) { } 2 3 5
80 2 $error_message = $self->submeta->error_message($other_meta);
81 2 $expected = $self->submeta->display;
82 2 ▶ $got = $SubMeta->check($other_meta) ? $other_meta->display : "";
Branch: 1 branch
BranchTrueFalseTotal
$SubMeta->check($other_meta) ? : 1 1 2
83 }
84 else {
85 3 $error_message = $self->submeta->relaxed_error_message($other_meta);
86 3 $expected = $self->submeta->display;
87 3 ▶ $got = $SubMeta->check($other_meta) ? $other_meta->display : "";
Branch: 1 branch
BranchTrueFalseTotal
$SubMeta->check($other_meta) ? : 2 1 3
88 }
89  
90 5 my $message = <<"```";
91 Reason : $error_message
92 Expected : $expected
93 Got : $got
94 ```
95  
96 5 return $message;
97 }
98  
99 ## override
100 4 ▶sub _build_coercion { ## no critic (Subroutines::ProhibitUnusedPrivateSubroutines)
Subroutine _build_coercion: called CC=1 SCAR=0.0
101 4 my $self = shift;
102  
103 return Type::Coercion->new(
104 display_name => "to_${self}",
105 type_constraint => $self,
106 type_coercion_map => [
107 18 ▶ Ref['CODE'] => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
108 18 my $sub = shift;
109 18 return $self->find_submeta->($sub);
110 },
111 4 ],
112 );
113 }
114  
115 5 1;
116 __END__
« Sub/Meta.pm ↑ Summary Sub/Meta/Creator.pm »