Sub/Meta/TypeSub.pm

filter: Statementstmt 100% 43 / 43 Branchbran 100% 10 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 12 / 12 Podpod 100% 4 / 4 totaltotal 100% 69 / 69 CC 6 SCAR 8.3
CC
6
Cov
100%
new
5.0
get_message
2.0
BEGIN
1.0
CRAP 2.3
« Sub/Meta/Finder/SubWrapInType.pm ↑ Summary Sub/Meta/CreatorFunction.pm »
1 package Sub::Meta::TypeSub;
2 3 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use parent qw(Type::Tiny);
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 3 ▶use Types::Standard qw(InstanceOf);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 39 ▶sub submeta_type { my $self = shift; return $self->{submeta_type} }
Subroutine submeta_type: called CC=1 SCAR=0.0
Pod documented
10  
11 ## override
12 7 ▶sub new {
Subroutine new: called CC=5 SCAR=16.1
Pod documented
13 7 my $class = shift;
14 7 ▶ my %params = ( @_ == 1 ) ? %{ $_[0] } : @_;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 ? : 1 6 7
15  
16 ## no critic (Subroutines::ProtectPrivateSubs)
17 7 ▶ Type::Tiny::_croak "Need to supply submeta_type" unless exists $params{submeta_type};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $params{"submeta_type"} 2 5 7
18  
19 5 ▶ if (!exists $params{name}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $params{"name"}) 4 1 5
20 4 ▶ $params{name} = $params{submeta_type}->submeta_strict_check ? 'StrictSub' : 'Sub';
Branch: 1 branch
BranchTrueFalseTotal
$params{'submeta_type'}->submeta_strict_check ? : 1 3 4
21 }
22  
23 5 return $class->SUPER::new(%params);
24 }
25  
26 ## override
27 3 ▶sub can_be_inlined { return !!0 }
Subroutine can_be_inlined: called CC=1 SCAR=0.0
Pod documented
28  
29 ## override
30 3 ▶sub _build_display_name { ## no critic (ProhibitUnusedPrivateSubroutines)
Subroutine _build_display_name: called CC=1 SCAR=0.0
31 3 my $self = shift;
32 3 return sprintf('%s[%s]', $self->name, $self->submeta_type->submeta->display);
33 }
34  
35 ## override
36 3 ▶sub _build_constraint { ## no critic (ProhibitUnusedPrivateSubroutines)
Subroutine _build_constraint: called CC=1 SCAR=0.0
37 3 my $self = shift;
38  
39 16 ▶ return sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
40 16 my $sub = shift;
41 16 my $other_meta = $self->submeta_type->coerce($sub);
42 16 $self->submeta_type->check($other_meta)
43 }
44 3 }
45  
46 ## override
47 2 ▶sub get_message {
Subroutine get_message: called CC=2 SCAR=6.9
Pod documented
48 2 my $self = shift;
49 2 my $sub = shift;
50  
51 2 my $default = $self->SUPER::get_message($sub);
52 2 my $meta = $self->submeta_type->coerce($sub);
53  
54 2 state $SubMeta = InstanceOf['Sub::Meta'];
55  
56 2 my $message = "$default\n";
57 2 ▶ if ($SubMeta->check($meta)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($SubMeta->check($meta)) { } 1 1 2
58 1 $message .= $self->submeta_type->get_detail_message($meta);
59 }
60 else {
61 1 my $s = Type::Tiny::_dd($sub); ## no critic (Subroutines::ProtectPrivateSubs)
62 1 $message .= " Cannot find submeta of `$s`";
63 }
64 2 return $message;
65 }
66  
67 3 1;
68 __END__
« Sub/Meta/Finder/SubWrapInType.pm ↑ Summary Sub/Meta/CreatorFunction.pm »