| 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
| |||||||||||
| 15 | |||||||||||
| 16 | ## no critic (Subroutines::ProtectPrivateSubs) | ||||||||||
| 17 | 7 | ▶ | Type::Tiny::_croak "Need to supply submeta_type" unless exists $params{submeta_type}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 18 | |||||||||||
| 19 | 5 | ▶ | if (!exists $params{name}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 20 | 4 | ▶ | $params{name} = $params{submeta_type}->submeta_strict_check ? 'StrictSub' : 'Sub'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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
| |||||||||||
| 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__ | ||||||||||