| 1 | 3 | ▶ | use 5.010001; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | package Mite::Attribute::SHV::CodeGen; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | # SHV uses Mite, so cannot be required by Mite during bootstrapping | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 3 | require Mite::Shim; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 3 | ▶ | if ( not Mite::Shim::_is_compiling() ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 3 | require Sub::HandlesVia::CodeGenerator; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 3 | our @ISA = 'Sub::HandlesVia::CodeGenerator'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 6 | ▶ | sub _handle_sigcheck { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_handle_sigcheck: called CC=14 SCAR=30.4
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 6 | my ( $self, $method_name, $handler, $env, $code, $state ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | # If there's a proper signature for the method... | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 6 | ▶ | if ( @{ $handler->signature || [] } ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$handler->signature || []
MC/DC100%1/1
$handler->signature || []
$handler->signature
Truth table100%2/2
A
A= $handler->signature
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | # Generate code using Type::Params to check the signature. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | # We also need to close over the signature. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 1 | require Mite::Signature::Compiler; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | my $compiler = 'Mite::Signature::Compiler'->new_from_compile( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | positional => { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | package => $self->target, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | subname => $method_name, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | is_wrapper => !!0, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | mite_signature => $self->{mite_attribute}, # HasMethods['class'] | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | $state->{shifted_self} | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 0 | ? @{ $handler->signature } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 1 | ▶ | : ( Types::Standard::Object(), @{ $handler->signature } ), | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 1 | my $sigcode = $compiler->coderef->code; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 1 | $sigcode =~ s/^\s+|\s+$//gs; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 1 | ▶ | if ( $sigcode =~ /return/ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 0 | push @$code, sprintf '$__signature ||= %s;', $sigcode; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | push @$code, '@_ = &$__signature;'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 0 | $env->{'$__signature'} = \0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 1 | $sigcode =~ s/^sub/do/; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 1 | push @$code, sprintf '@_ = %s;', $sigcode; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | # As we've now inserted a signature check, we can stop worrying | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | # about signature checks. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 1 | $state->{signature_check_needed} = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | # There is no proper signature, but there's still check the | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | # arity of the method. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | # What is the arity? | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 5 | ▶ | my $min_args = $handler->min_args || 0; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$handler->min_args || 0
MC/DC0%0/1
$handler->min_args || 0
$handler->min_args
Truth table50%1/2
A
A= $handler->min_args
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 5 | my $max_args = $handler->max_args; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 5 | my $plus = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 5 | ▶ | if ( $state->{shifted_self} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | $plus = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | # What usage message do we want to print if wrong arity? | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | my $usg = sprintf( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | '%s("Wrong number of parameters in signature for %s; usage: ".%s)', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | $self->{mite_attribute}->_function_for_croak, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 5 | $method_name, | |||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | B::perlstring( $self->generate_usage_string( $method_name, $handler->usage ) ), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | # Insert the check into the code. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 5 | ▶ | if (defined $min_args and defined $max_args and $min_args==$max_args) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition66%4/6
defined $min_args and defined $max_args and $min_args == $max_args
defined $min_args and defined $max_args
MC/DC33%1/3
defined $min_args and defined $max_args and $min_args == $max_args
defined $min_args
defined $max_args
$min_args == $max_args
Truth table50%2/4
A and B and C
A= defined $min_argsB= defined $max_argsC= $min_args == $max_args
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 1 | push @$code, sprintf('@_==%d or %s;', $min_args + $plus, $usg); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | ▶ | elsif (defined $min_args and defined $max_args) { | |||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
defined $min_args and defined $max_args
MC/DC0%0/2
defined $min_args and defined $max_args
defined $min_args
defined $max_args
Truth table33%1/3
A and B
A= defined $min_argsB= defined $max_args
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | push @$code, sprintf('(@_ >= %d and @_ <= %d) or %s;', $min_args + $plus, $max_args + $plus, $usg); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | ▶ | elsif (defined $min_args and $min_args > 0) { | |||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
defined $min_args and $min_args > 0
MC/DC0%0/2
defined $min_args and $min_args > 0
defined $min_args
$min_args > 0
Truth table33%1/3
A and B
A= defined $min_argsB= $min_args > 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | push @$code, sprintf('@_ >= %d or %s;', $min_args + $plus, $usg); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | # We are still lacking a proper signature check though, so note | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | # that in the state. The information can be used by | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | # additional_validation coderefs. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 5 | $state->{signature_check_needed} = !!1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 6 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 3 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||