I am trying to write a function which validates the username for an alphanumeric value and in the case of failure it should log my custom error message and return 0 to the called function instead of die-ing:
sub insertUser{
my ( $username, $password, $email, $name) = validate_pos( @_,
{ type => SCALAR,
regex => qr/^\w+$/,
on_fail => { $err->error("username validation failed"),return 0 }
},
{ type => SCALAR },
{ type => SCALAR },
{ type => SCALAR ,optional => 1,default => 99});
print "$username, $password, $email, $name ";
}
With the above code I am facing a problem like it's still returning 0 in the success case. Can anybody please help me in this regard and could anyone explain me why it is doing so?