| 1 | 16 | ▶ | use 5.010001; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 2 | 16 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 3 | 16 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||
| 5 | package Mite::Signature; | ||||||||||||||||||||||||||||||||||||||||
| 6 | 16 | ▶ | use Mite::Miteception -all; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||
| 8 | 16 | our $AUTHORITY = 'cpan:TOBYINK'; | |||||||||||||||||||||||||||||||||||||||
| 9 | 16 | our $VERSION = '0.013000'; | |||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||
| 11 | 16 | has class => | |||||||||||||||||||||||||||||||||||||||
| 12 | is => ro, | ||||||||||||||||||||||||||||||||||||||||
| 13 | isa => MitePackage, | ||||||||||||||||||||||||||||||||||||||||
| 14 | weak_ref => true; | ||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||
| 16 | 16 | has compiling_class => | |||||||||||||||||||||||||||||||||||||||
| 17 | init_arg => undef, | ||||||||||||||||||||||||||||||||||||||||
| 18 | is => rw, | ||||||||||||||||||||||||||||||||||||||||
| 19 | isa => MitePackage, | ||||||||||||||||||||||||||||||||||||||||
| 20 | local_writer => true; | ||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||
| 22 | 16 | has method_name => | |||||||||||||||||||||||||||||||||||||||
| 23 | is => ro, | ||||||||||||||||||||||||||||||||||||||||
| 24 | isa => Str, | ||||||||||||||||||||||||||||||||||||||||
| 25 | required => true; | ||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||
| 27 | 16 | has named => | |||||||||||||||||||||||||||||||||||||||
| 28 | is => ro, | ||||||||||||||||||||||||||||||||||||||||
| 29 | isa => ArrayRef->plus_coercions( HashRef, q([%$_]) ), | ||||||||||||||||||||||||||||||||||||||||
| 30 | predicate => 'is_named'; | ||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||
| 32 | 16 | has positional => | |||||||||||||||||||||||||||||||||||||||
| 33 | is => ro, | ||||||||||||||||||||||||||||||||||||||||
| 34 | isa => ArrayRef, | ||||||||||||||||||||||||||||||||||||||||
| 35 | alias => 'pos', | ||||||||||||||||||||||||||||||||||||||||
| 36 | predicate => 'is_positional'; | ||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||
| 38 | 16 | has method => | |||||||||||||||||||||||||||||||||||||||
| 39 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||
| 40 | isa => Bool, | ||||||||||||||||||||||||||||||||||||||||
| 41 | default => true; | ||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||
| 43 | has head => | ||||||||||||||||||||||||||||||||||||||||
| 44 | is => lazy, | ||||||||||||||||||||||||||||||||||||||||
| 45 | isa => ArrayRef | Int, | ||||||||||||||||||||||||||||||||||||||||
| 46 | 8 | ▶ | builder => sub { shift->method ? [ Defined, { name => 'invocant' } ] : [] }; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||
| 48 | 16 | has tail => | |||||||||||||||||||||||||||||||||||||||
| 49 | is => ro, | ||||||||||||||||||||||||||||||||||||||||
| 50 | isa => ArrayRef | Int; | ||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||
| 52 | 16 | has named_to_list => | |||||||||||||||||||||||||||||||||||||||
| 53 | is => ro, | ||||||||||||||||||||||||||||||||||||||||
| 54 | isa => Bool | ArrayRef, | ||||||||||||||||||||||||||||||||||||||||
| 55 | default => false; | ||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||
| 57 | 16 | has compiler => | |||||||||||||||||||||||||||||||||||||||
| 58 | init_arg => undef, | ||||||||||||||||||||||||||||||||||||||||
| 59 | is => lazy, | ||||||||||||||||||||||||||||||||||||||||
| 60 | isa => Object, | ||||||||||||||||||||||||||||||||||||||||
| 61 | builder => true, | ||||||||||||||||||||||||||||||||||||||||
| 62 | handles => [ qw( has_head has_tail has_slurpy ) ]; | ||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||
| 64 | has should_bless => | ||||||||||||||||||||||||||||||||||||||||
| 65 | init_arg => undef, | ||||||||||||||||||||||||||||||||||||||||
| 66 | is => lazy, | ||||||||||||||||||||||||||||||||||||||||
| 67 | isa => Bool, | ||||||||||||||||||||||||||||||||||||||||
| 68 | 9 | ▶ | builder => sub { !!( $_[0]->is_named && !$_[0]->named_to_list ) }; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
Condition100%3/3
$_[0]->is_named && !$_[0]->named_to_list
MC/DC100%2/2
$_[0]->is_named && !$_[0]->named_to_list
$_[0]->is_named
!$_[0]->named_to_list
Truth table100%3/3
A && not(B)
A= $_[0]->is_namedB= !$_[0]->named_to_list
| |||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||
| 70 | 9 | ▶ | sub BUILD { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BUILD: called CC=3 SCAR=11.7
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||
| 71 | 9 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||
| 73 | 9 | ▶ | croak 'Method cannot be both named and positional' | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->is_named and $self->is_positional
MC/DC0%0/2
$self->is_named and $self->is_positional
$self->is_named
$self->is_positional
Truth table66%2/3
A and B
A= $self->is_namedB= $self->is_positional
| |||||||||||||||||||||||||||||||||||||||||
| 74 | if $self->is_named && $self->is_positional; | ||||||||||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||
| 77 | 9 | ▶ | sub autolax { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
autolax: called CC=4 SCAR=15.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||
| 78 | 9 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||
| 80 | 9 | ▶ | my $class = $self->compiling_class || $self->class; | ||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$self->compiling_class || $self->class
MC/DC0%0/2
$self->compiling_class || $self->class
$self->compiling_class
$self->class
Truth table66%2/3
A || B
A= $self->compiling_classB= $self->class
| |||||||||||||||||||||||||||||||||||||||||
| 81 | 9 | ▶ | return if not $class; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 82 | 9 | ▶ | return if not eval { $class->project->config->data->{autolax} }; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | return sprintf '%s::STRICT', $class->project->config->data->{shim}; | |||||||||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||
| 86 | 9 | ▶ | sub _build_compiler { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_compiler: called CC=8 SCAR=21.3
| |||||||||||||||||||||||||||||||||||||||||
| 87 | 9 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||
| 89 | 9 | local $Type::Tiny::AvoidCallbacks = 1; | |||||||||||||||||||||||||||||||||||||||
| 90 | 9 | local $Type::Tiny::SafePackage = sprintf( 'package %s;', $self->class->shim_name ); | |||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||
| 92 | 9 | require Mite::Signature::Compiler; | |||||||||||||||||||||||||||||||||||||||
| 93 | my $c = 'Mite::Signature::Compiler'->new_from_compile( | ||||||||||||||||||||||||||||||||||||||||
| 94 | $self->is_named ? 'named' : 'positional', | ||||||||||||||||||||||||||||||||||||||||
| 95 | { | ||||||||||||||||||||||||||||||||||||||||
| 96 | package => $self->class->name, | ||||||||||||||||||||||||||||||||||||||||
| 97 | subname => $self->method_name, | ||||||||||||||||||||||||||||||||||||||||
| 98 | ( $self->head ? ( head => $self->head ) : () ), | ||||||||||||||||||||||||||||||||||||||||
| 99 | ( $self->tail ? ( tail => $self->tail ) : () ), | ||||||||||||||||||||||||||||||||||||||||
| 100 | named_to_list => $self->named_to_list, | ||||||||||||||||||||||||||||||||||||||||
| 101 | strictness => scalar( $self->autolax // 1 ), | ||||||||||||||||||||||||||||||||||||||||
| 102 | goto_next => true, | ||||||||||||||||||||||||||||||||||||||||
| 103 | mite_signature => $self, | ||||||||||||||||||||||||||||||||||||||||
| 104 | $self->should_bless | ||||||||||||||||||||||||||||||||||||||||
| 105 | ? ( bless => sprintf '%s::__NAMED_ARGUMENTS__::%s', $self->class->name, $self->method_name ) | ||||||||||||||||||||||||||||||||||||||||
| 106 | : (), | ||||||||||||||||||||||||||||||||||||||||
| 107 | }, | ||||||||||||||||||||||||||||||||||||||||
| 108 | $self->is_named | ||||||||||||||||||||||||||||||||||||||||
| 109 | 6 | ? @{ $self->named } | |||||||||||||||||||||||||||||||||||||||
| 110 | 9 | ▶ | : @{ $self->positional }, | ||||||||||||||||||||||||||||||||||||||
|
Branch: 5 branches
Condition50%1/2
$self->autolax // 1
MC/DC0%0/1
$self->autolax // 1
$self->autolax
Truth table50%1/2
A
A= $self->autolax
| |||||||||||||||||||||||||||||||||||||||||
| 111 | ); | ||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||
| 113 | 9 | $c->coderef; | |||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||
| 115 | 9 | ▶ | if ( keys %{ $c->coderef->{env} } ) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | croak "Signature could not be inlined properly; bailing out"; | |||||||||||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||
| 119 | 9 | return $c; | |||||||||||||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||
| 122 | 10 | ▶ | sub _compile_coderef { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
_compile_coderef: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||
| 123 | 10 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||
| 125 | 10 | ▶ | if ( $self->compiling_class and $self->compiling_class != $self->class ) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->compiling_class and $self->compiling_class != $self->class
MC/DC50%1/2
$self->compiling_class and $self->compiling_class != $self->class
$self->compiling_class
$self->compiling_class != $self->class
Truth table66%2/3
A and B
A= $self->compiling_classB= $self->compiling_class != $self->class
| |||||||||||||||||||||||||||||||||||||||||
| 126 | 1 | return sprintf( '$%s::SIGNATURE_FOR{%s}', $self->class->name, B::perlstring( $self->method_name ) ); | |||||||||||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||
| 129 | 9 | my $code = $self->compiler->coderef->code; | |||||||||||||||||||||||||||||||||||||||
| 130 | 9 | $code =~ s/^\s+|\s+$//gs; | |||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||
| 132 | 9 | return $code; | |||||||||||||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||
| 135 | 10 | ▶ | sub _compile_support { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
_compile_support: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||
| 136 | 10 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||
| 138 | 10 | ▶ | if ( $self->compiling_class and $self->compiling_class != $self->class ) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->compiling_class and $self->compiling_class != $self->class
MC/DC50%1/2
$self->compiling_class and $self->compiling_class != $self->class
$self->compiling_class
$self->compiling_class != $self->class
Truth table66%2/3
A and B
A= $self->compiling_classB= $self->compiling_class != $self->class
| |||||||||||||||||||||||||||||||||||||||||
| 139 | 1 | return; | |||||||||||||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||
| 142 | 9 | ▶ | return unless $self->should_bless; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 143 | 5 | return $self->compiler->make_class_pp_code; | |||||||||||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||
| 146 | 1 | ▶ | sub clone { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
clone: called CC=12 SCAR=33.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||
| 147 | 1 | my ( $self, %args ) = @_; | |||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||
| 149 | # alias | ||||||||||||||||||||||||||||||||||||||||
| 150 | 1 | ▶ | $args{positional} = $args{pos} if exists $args{pos}; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||
| 152 | 1 | ▶ | if ( $self->has_slurpy and $args{positional} ) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
Condition33%1/3
$self->has_slurpy and $args{"positional"}
MC/DC0%0/2
$self->has_slurpy and $args{"positional"}
$self->has_slurpy
$args{"positional"}
Truth table33%1/3
A and B
A= $self->has_slurpyB= $args{"positional"}
| |||||||||||||||||||||||||||||||||||||||||
| 153 | 0 | croak "Cannot add new positional parameters when extending an existing signature with a slurpy parameter"; | |||||||||||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||||||||||||
| 155 | ▶ | elsif ( $self->has_slurpy and $args{named} ) { | |||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$self->has_slurpy and $args{"named"}
MC/DC0%0/2
$self->has_slurpy and $args{"named"}
$self->has_slurpy
$args{"named"}
Truth table33%1/3
A and B
A= $self->has_slurpyB= $args{"named"}
| |||||||||||||||||||||||||||||||||||||||||
| 156 | 0 | croak "Cannot add new named parameters when extending an existing signature with a slurpy parameter"; | |||||||||||||||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||||||||||||||
| 158 | ▶ | elsif ( $self->is_named and $args{positional} ) { | |||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$self->is_named and $args{"positional"}
MC/DC0%0/2
$self->is_named and $args{"positional"}
$self->is_named
$args{"positional"}
Truth table33%1/3
A and B
A= $self->is_namedB= $args{"positional"}
| |||||||||||||||||||||||||||||||||||||||||
| 159 | 0 | croak "Cannot add positional parameters when extending an existing signature which has named parameters"; | |||||||||||||||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||||||||||||||
| 161 | ▶ | elsif ( !$self->is_named and $args{named} ) { | |||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
not $self->is_named and $args{"named"}
MC/DC0%0/2
not $self->is_named and $args{"named"}
not $self->is_named
$args{"named"}
Truth table33%1/3
not(A) and B
A= not $self->is_namedB= $args{"named"}
| |||||||||||||||||||||||||||||||||||||||||
| 162 | 0 | croak "Cannot add named parameters when extending an existing signature which has positional parameters"; | |||||||||||||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||
| 165 | 1 | ▶ | if ( $args{positional} ) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 166 | 0 | $args{positional} = [ @{ $self->positional }, @{ $args{positional} } ]; | |||||||||||||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||||
| 169 | 1 | ▶ | if ( $args{named} ) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 170 | 1 | $args{named} = [ @{ $self->named }, @{ $args{named} } ]; | |||||||||||||||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||
| 173 | 1 | my %new_args = ( %$self, %args ); | |||||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||||||
| 175 | # Rebuild these | ||||||||||||||||||||||||||||||||||||||||
| 176 | 1 | delete $new_args{compiler}; | |||||||||||||||||||||||||||||||||||||||
| 177 | 1 | delete $new_args{should_bless}; | |||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||||
| 179 | 1 | return __PACKAGE__->new( %new_args ); | |||||||||||||||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||||
| 182 | 16 | 1; | |||||||||||||||||||||||||||||||||||||||