in reply to How to make script die with "Not enough args" on compilation step if args are passed as a hash ref? See inside

I'll just go and assume that your arguments are known at compile time because ... well ... your question doesn't make much sense otherwise. If this checking is really that important to you, you could always try source filtering. With Filter::Simple you could try to find every calls to that function (and I'm not talking about special cases like calling from a sub reference, because there's no prototype checking there either) and check the parameters.

If you call it only like MySub( {key => value, otherKey => value, ... } ) you could do with a regex. And if you call it like MySub(CanYieldAHashRefAtCompileTime); You could use your filter to get the parameters as a string, eval it (which would give you a hashref), make your verification, and even replace the string by its "value" by using Data::Dumper. That probably is a bad idea if your data contains bless references (instances) or tied variables.

So you could do it, and that wouldn't be that difficult provided you read the documentations carefully, but you should still ask yourself if it really is worth the trouble and added complexity to your program.

  • Comment on Re: How to make script die with "Not enough args" on compilation step if args are passed as a hash ref? See inside