You need to set $ _ [0]:
call_me => sub { $_[0] = 99 if not defined $_[0] }
@_ is flattened with the parameters passed, so you can use this as a link to the original.
Moreover,
$args{bar} ||= 99;
there will be a reset bar, even if it is 0 or `` '' (empty string), which is not like what you want. Using
$args{bar}
if you use perl 5.10 or later, do what you want.
, , , :
sub foo
{
unshift @_, bar => undef;
my %args = validate(@_,
{
bar => {
optional => 1,
callbacks => {
call_me => sub { $_[0] = 99 unless defined $_[0] },
},
},
},
);
print Dumper \%args;
}
, - .