I'm trying to create a signature_for an import method that should be called like:
MyPackage->import(qw(symbol1 symbol2 symbol3));
I need to validate that: It's a proper method call (class name first) Followed by at least one non-empty string argument But I want the arguments to remain as individual scalars in @_, not get wrapped into an arrayref. Every approach I've tried with slurpy ends up forcing the string arguments into an arrayref:
Is there a way to make signature_for validate the method signature but leave the variable argument list as individual scalars in @_? Or is Type::Params fundamentally designed around restructuring arguments into containers?use Type::Params qw( signature_for ); use Types::Standard qw( slurpy Any ); signature_for import => ( method => 1, pos => [ slurpy Any ], ); sub import { warn "Args: ", join(", ", map { ref($_) || $_ } @_), "\n"; # Shows: Args: MyPackage, ARRAY(0x...) }
Currently using Params::Validate which works fine, but curious if Type::Params can handle this use case.
In reply to Type::Params signature_for - can it handle method + variable string args without arrayref wrapping? by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |