use
5.010001;
if
( not Mite::Shim::_is_compiling() ) {
our
@ISA
=
'Sub::HandlesVia::CodeGenerator'
;
}
sub
_handle_sigcheck {
my
(
$self
,
$method_name
,
$handler
,
$env
,
$code
,
$state
) =
@_
;
if
( @{
$handler
->signature || [] } ) {
my
$compiler
=
'Mite::Signature::Compiler'
->new_from_compile(
positional
=> {
package
=>
$self
->target,
subname
=>
$method_name
,
is_wrapper
=> !!0,
mite_signature
=>
$self
->{mite_attribute},
},
$state
->{shifted_self}
? @{
$handler
->signature }
: ( Types::Standard::Object(), @{
$handler
->signature } ),
);
my
$sigcode
=
$compiler
->coderef->code;
$sigcode
=~ s/^\s+|\s+$//gs;
if
(
$sigcode
=~ /
return
/ ) {
push
@$code
,
sprintf
'$__signature ||= %s;'
,
$sigcode
;
push
@$code
,
'@_ = &$__signature;'
;
$env
->{
'$__signature'
} = \0;
}
else
{
$sigcode
=~ s/^
sub
/
do
/;
push
@$code
,
sprintf
'@_ = %s;'
,
$sigcode
;
}
$state
->{signature_check_needed} = 0;
}
else
{
my
$min_args
=
$handler
->min_args || 0;
my
$max_args
=
$handler
->max_args;
my
$plus
= 1;
if
(
$state
->{shifted_self} ) {
$plus
= 0;
}
my
$usg
=
sprintf
(
'%s("Wrong number of parameters in signature for %s; usage: ".%s)'
,
$self
->{mite_attribute}->_function_for_croak,
$method_name
,
B::perlstring(
$self
->generate_usage_string(
$method_name
,
$handler
->usage ) ),
);
if
(
defined
$min_args
and
defined
$max_args
and
$min_args
==
$max_args
) {
push
@$code
,
sprintf
(
'@_==%d or %s;'
,
$min_args
+
$plus
,
$usg
);
}
elsif
(
defined
$min_args
and
defined
$max_args
) {
push
@$code
,
sprintf
(
'(@_ >= %d and @_ <= %d) or %s;'
,
$min_args
+
$plus
,
$max_args
+
$plus
,
$usg
);
}
elsif
(
defined
$min_args
and
$min_args
> 0) {
push
@$code
,
sprintf
(
'@_ >= %d or %s;'
,
$min_args
+
$plus
,
$usg
);
}
$state
->{signature_check_needed} = !!1;
}
return
$self
;
}
1;