| 1 | package Sub::Meta::Param; | ||||||||||||||||||||||||||||||||
| 2 | 45 | ▶ | use 5.010; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 3 | 45 | ▶ | use strict; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 4 | 45 | ▶ | use warnings; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||
| 6 | 45 | our $VERSION = "0.15"; | |||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||
| 8 | 45 | ▶ | use Scalar::Util (); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||
| 10 | use overload | ||||||||||||||||||||||||||||||||
| 11 | 45 | ▶ | fallback => 1, | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 12 | eq => \&is_same_interface, | ||||||||||||||||||||||||||||||||
| 13 | 45 | ; | |||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||
| 15 | 45 | my %DEFAULT = ( named => 0, optional => 0, invocant => 0 ); | |||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||
| 17 | 255 | ▶ | sub new { | ||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||||||||
| 18 | 255 | my ($class, @args) = @_; | |||||||||||||||||||||||||||||||
| 19 | 255 | my $v = $args[0]; | |||||||||||||||||||||||||||||||
| 20 | 255 | ▶ | my %args = @args == 1 ? ref $v && (ref $v eq 'HASH') ? %{$v} | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
ref $v and ref $v eq "HASH"
MC/DC100%2/2
ref $v and ref $v eq "HASH"
ref $v
ref $v eq "HASH"
Truth table100%3/3
A and B
A= ref $vB= ref $v eq "HASH"
| |||||||||||||||||||||||||||||||||
| 21 | : ( type => $v ) | ||||||||||||||||||||||||||||||||
| 22 | : @args; | ||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||
| 24 | 255 | ▶ | $args{optional} = !delete $args{required} if exists $args{required}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 25 | 255 | ▶ | $args{named} = !delete $args{positional} if exists $args{positional}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 26 | 255 | ▶ | $args{type} = delete $args{isa} if exists $args{isa}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||
| 28 | 255 | %args = (%DEFAULT, %args); | |||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||
| 30 | 255 | return bless \%args => $class; | |||||||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||
| 33 | 165 | ▶ | sub name() { my $self = shift; return $self->{name} // '' } | ||||||||||||||||||||||||||||||
|
Subroutine
name: called CC=2 SCAR=6.9
Pod
documented
Condition100%2/2
$self->{"name"} // ""
MC/DC100%1/1
$self->{"name"} // ""
$self->{"name"}
Truth table100%2/2
A
A= $self->{"name"}
| |||||||||||||||||||||||||||||||||
| 34 | 583 | ▶ | sub type() { my $self = shift; return $self->{type} } | ||||||||||||||||||||||||||||||
|
Subroutine
type: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 35 | 61 | ▶ | sub default() { my $self = shift; return $self->{default} } ## no critic (ProhibitBuiltinHomonyms) | ||||||||||||||||||||||||||||||
|
Subroutine
default: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 36 | 61 | ▶ | sub coerce() { my $self = shift; return $self->{coerce} } | ||||||||||||||||||||||||||||||
|
Subroutine
coerce: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 37 | 581 | ▶ | sub optional() { my $self = shift; return !!$self->{optional} } | ||||||||||||||||||||||||||||||
|
Subroutine
optional: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 38 | 144 | ▶ | sub required() { my $self = shift; return !$self->{optional} } | ||||||||||||||||||||||||||||||
|
Subroutine
required: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 39 | 654 | ▶ | sub named() { my $self = shift; return !!$self->{named} } | ||||||||||||||||||||||||||||||
|
Subroutine
named: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 40 | 217 | ▶ | sub positional() { my $self = shift; return !$self->{named} } | ||||||||||||||||||||||||||||||
|
Subroutine
positional: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 41 | 61 | ▶ | sub invocant() { my $self = shift; return !!$self->{invocant} } | ||||||||||||||||||||||||||||||
|
Subroutine
invocant: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||
| 43 | 548 | ▶ | sub has_name() { my $self = shift; return defined $self->{name} } | ||||||||||||||||||||||||||||||
|
Subroutine
has_name: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 44 | 433 | ▶ | sub has_type() { my $self = shift; return defined $self->{type} } | ||||||||||||||||||||||||||||||
|
Subroutine
has_type: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 45 | 61 | ▶ | sub has_default() { my $self = shift; return defined $self->{default} } | ||||||||||||||||||||||||||||||
|
Subroutine
has_default: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 46 | 61 | ▶ | sub has_coerce() { my $self = shift; return defined $self->{coerce} } | ||||||||||||||||||||||||||||||
|
Subroutine
has_coerce: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||
| 48 | 3 | ▶ | sub set_name { my ($self, $v) = @_; $self->{name} = $v; return $self } | ||||||||||||||||||||||||||||||
|
Subroutine
set_name: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 49 | 4 | ▶ | sub set_type { my ($self, $v) = @_; $self->{type} = $v; return $self } | ||||||||||||||||||||||||||||||
|
Subroutine
set_type: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 50 | 4 | ▶ | sub set_default { my ($self, $v) = @_; $self->{default} = $v; return $self } | ||||||||||||||||||||||||||||||
|
Subroutine
set_default: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 51 | 4 | ▶ | sub set_coerce { my ($self, $v) = @_; $self->{coerce} = $v; return $self } | ||||||||||||||||||||||||||||||
|
Subroutine
set_coerce: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 52 | 6 | ▶ | sub set_optional { my ($self, $v) = @_; $self->{optional} = !!(defined $v ? $v : 1); return $self } | ||||||||||||||||||||||||||||||
|
Subroutine
set_optional: called CC=2 SCAR=6.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 53 | 6 | ▶ | sub set_required { my ($self, $v) = @_; $self->{optional} = !(defined $v ? $v : 1); return $self } | ||||||||||||||||||||||||||||||
|
Subroutine
set_required: called CC=2 SCAR=6.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 54 | 6 | ▶ | sub set_named { my ($self, $v) = @_; $self->{named} = !!(defined $v ? $v : 1); return $self } | ||||||||||||||||||||||||||||||
|
Subroutine
set_named: called CC=2 SCAR=6.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 55 | 6 | ▶ | sub set_positional { my ($self, $v) = @_; $self->{named} = !(defined $v ? $v : 1); return $self } | ||||||||||||||||||||||||||||||
|
Subroutine
set_positional: called CC=2 SCAR=6.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 56 | 71 | ▶ | sub set_invocant { my ($self, $v) = @_; $self->{invocant} = !!(defined $v ? $v : 1); return $self } | ||||||||||||||||||||||||||||||
|
Subroutine
set_invocant: called CC=2 SCAR=6.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||
| 58 | # alias | ||||||||||||||||||||||||||||||||
| 59 | sub isa_() :method; # NOT isa | ||||||||||||||||||||||||||||||||
| 60 | 45 | *isa_ = \&type; | |||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||
| 62 | sub set_isa; | ||||||||||||||||||||||||||||||||
| 63 | 45 | *set_isa = \&set_type; | |||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||
| 65 | 117 | ▶ | sub is_same_interface { | ||||||||||||||||||||||||||||||
|
Subroutine
is_same_interface: called CC=12 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||
| 66 | 117 | my ($self, $other) = @_; | |||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||
| 68 | 117 | ▶ | return unless Scalar::Util::blessed($other) && $other->isa('Sub::Meta::Param'); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
builtin::blessed($other) and $other->isa("Sub::Meta::Param")
MC/DC100%2/2
builtin::blessed($other) and $other->isa("Sub::Meta::Param")
builtin::blessed($other)
$other->isa("Sub::Meta::Param")
Truth table100%3/3
A and B
A= builtin::blessed($other)B= $other->isa("Sub::Meta::Param")
| |||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||
| 70 | 107 | ▶ | if ($self->has_name) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 71 | 16 | ▶ | return unless $self->name eq $other->name | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||
| 73 | else { | ||||||||||||||||||||||||||||||||
| 74 | 91 | ▶ | return if $other->has_name | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||
| 77 | 97 | ▶ | if ($self->has_type) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 78 | 68 | ▶ | return unless $self->type eq ($other->type // ''); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$other->type // ""
MC/DC100%1/1
$other->type // ""
$other->type
Truth table100%2/2
A
A= $other->type
| |||||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||
| 80 | else { | ||||||||||||||||||||||||||||||||
| 81 | 29 | ▶ | return if $other->has_type | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||
| 84 | 73 | ▶ | return unless $self->optional eq $other->optional; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||
| 86 | 68 | ▶ | return unless $self->named eq $other->named; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||
| 88 | 63 | return !!1; | |||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||
| 91 | 98 | ▶ | sub is_relaxed_same_interface { | ||||||||||||||||||||||||||||||
|
Subroutine
is_relaxed_same_interface: called CC=10 SCAR=23.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 92 | 98 | my ($self, $other) = @_; | |||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||
| 94 | 98 | ▶ | return unless Scalar::Util::blessed($other) && $other->isa('Sub::Meta::Param'); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
builtin::blessed($other) and $other->isa("Sub::Meta::Param")
MC/DC100%2/2
builtin::blessed($other) and $other->isa("Sub::Meta::Param")
builtin::blessed($other)
$other->isa("Sub::Meta::Param")
Truth table100%3/3
A and B
A= builtin::blessed($other)B= $other->isa("Sub::Meta::Param")
| |||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||
| 96 | 96 | ▶ | if ($self->has_name) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 97 | 14 | ▶ | return unless $self->name eq $other->name | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||
| 100 | 91 | ▶ | if ($self->has_type) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 101 | 57 | ▶ | return unless $self->type eq ($other->type // ''); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$other->type // ""
MC/DC100%1/1
$other->type // ""
$other->type
Truth table100%2/2
A
A= $other->type
| |||||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||
| 104 | 71 | ▶ | return unless $self->optional eq $other->optional; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||
| 106 | 66 | ▶ | return unless $self->named eq $other->named; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||
| 108 | 61 | return !!1; | |||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||
| 111 | 24 | ▶ | sub is_same_interface_inlined { | ||||||||||||||||||||||||||||||
|
Subroutine
is_same_interface_inlined: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 112 | 24 | my ($self, $v) = @_; | |||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||
| 114 | 24 | my @src; | |||||||||||||||||||||||||||||||
| 115 | 24 | push @src => sprintf("Scalar::Util::blessed(%s) && %s->isa('Sub::Meta::Param')", $v, $v); | |||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||
| 117 | 24 | ▶ | push @src => $self->has_name ? sprintf("'%s' eq %s->name", $self->name, $v) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 118 | : sprintf('!%s->has_name', $v); | ||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||
| 120 | 24 | ▶ | push @src => $self->has_type ? sprintf("'%s' eq (%s->type // '')", "@{[$self->type]}", $v) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 121 | : sprintf('!%s->has_type', $v); | ||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||
| 123 | 24 | push @src => sprintf("'%s' eq %s->optional", $self->optional, $v); | |||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||
| 125 | 24 | push @src => sprintf("'%s' eq %s->named", $self->named, $v); | |||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||
| 127 | 24 | return join "\n && ", @src; | |||||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||
| 130 | 30 | ▶ | sub is_relaxed_same_interface_inlined { | ||||||||||||||||||||||||||||||
|
Subroutine
is_relaxed_same_interface_inlined: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 131 | 30 | my ($self, $v) = @_; | |||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||
| 133 | 30 | my @src; | |||||||||||||||||||||||||||||||
| 134 | 30 | push @src => sprintf("Scalar::Util::blessed(%s) && %s->isa('Sub::Meta::Param')", $v, $v); | |||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||
| 136 | 30 | ▶ | push @src => sprintf("'%s' eq %s->name", $self->name, $v) if $self->has_name; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||
| 138 | 30 | ▶ | push @src => sprintf("'%s' eq (%s->type // '')", "@{[$self->type]}", $v) if $self->has_type; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||
| 140 | 30 | push @src => sprintf("'%s' eq %s->optional", $self->optional, $v); | |||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||
| 142 | 30 | push @src => sprintf("'%s' eq %s->named", $self->named, $v); | |||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||
| 144 | 30 | return join "\n && ", @src; | |||||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||
| 147 | 66 | ▶ | sub display { | ||||||||||||||||||||||||||||||
|
Subroutine
display: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||
| 148 | 66 | my $self = shift; | |||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||
| 150 | 66 | my $s = ''; | |||||||||||||||||||||||||||||||
| 151 | 66 | ▶ | $s .= $self->type if $self->has_type; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 152 | 66 | ▶ | if ($self->has_name) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 153 | 10 | ▶ | $s .= sprintf("%s%s%s", | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 154 | $self->has_type ? ' ' : '', | ||||||||||||||||||||||||||||||||
| 155 | $self->named ? ':' : '', | ||||||||||||||||||||||||||||||||
| 156 | $self->name); | ||||||||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||||||
| 158 | 66 | return $s; | |||||||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||
| 162 | 45 | 1; | |||||||||||||||||||||||||||||||
| 163 | __END__ | ||||||||||||||||||||||||||||||||