Sign in to PrePAN


User's Modules

Getopts::toHash Take/validate command line arguments

I have never submitted a module before but I think this could be useful to other people as I did a search on cpanm for something that would easily pass a hash back of command line arguments and validate them (Validation is optional). Future plans include custom die messages and aliases for aguments. Let me know what you guys think if this would be useful, If you see anything that wouldnt work, possibly some advice on namespace etc. Thanks

--Validation The Module can validate on 7 Different constraints REGEXP - {'REGEXP=>'^[-+]?[0-9]'} - Specify a regex the passed data must comply with. MINMAX - {'MINMAX'=>{min=>20,max=>40}} - Specify minimum and maximum numbers the argument must be. GREATER_THAN - {'GREATER_THAN'=>{min=>20}} - Specify a minimum number the argument must be. LESS_THAN - {'LESS_THAN'=>{max=>40}} - Specify a maximum number the argument must be lower than. ASCII - ['ASCII'] - The argument must be any ASCII text with spaces allowed. NOSPACES - ['NOSPACES'] - The argument must have no spaces. INT - ['INT'] - The argument must be a number. ANY - ['ANY'] - The argument must be defined.

You can validate each argument on as many types of validation as you want by stringing together each array ref or hash. The Argument must pass each constraint

--Example 1 - Validating with a inline object. $Args->validate( '-a'=>[ 'ASCII','NOSPACES',{ 'MINMAX'=>{min=>20,max=>40} } ] );

--Example 2 - Validating with a hash spec. my %spec = ( '-a'=>[ 'ASCII','NOSPACES', {'MINMAX'=>{min=>20,max=>40} } ] ); $Args->validate(%spec);

The module will display error messages and die on failed validation by default. If you dont want this you can pass... $Args->validate( no_errors=>'1','-a'=>[ 'ASCII','NOSPACES',{ 'MINMAX'=>{min=>20,max=>40} } ] );

ammodules@github 3 comments