The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

OptionHash - Checking of option hashes

VERSION

version 0.1.0

SYNOPSIS

use OptionHash;

my $cat_def = ohash_define( keys => [qw< tail nose claws teeth>]);

sub cat{ my %options = @_; ohash_check( $cat_def, \%options); # ... }

cat( teeth => 'sharp' ); cat( trunk => 'long'); # Boom, will fail. Cats dont expect to have a trunk.

DESCRIPTION

I like to pass options around in hash form because it's clear and flexible. However it can lead to sloppy mistakes when you typo the keys. OptionHash quickly checks your hashes against a definition and croaks if you've passed in bad keys.

Currently.. That's it! Simple but effective.

EXPORTED SUBS

ohash_define

Define an optionhash specification, sort-of a type:

 my $cat_def = ohash_define( keys => [ qw< teeth claws > ]);

ohash_check

Check a hash against a definition:

  ohash_check( $cat_def, \%options);

If everything is okay things will proceed, otherwise ohash_check will croak (see Carp).

FUTURE

Maybe do the checking part with XS, although honestly it's fast in perl. Might do an extra module as it's nice to have a pure perl version anyway.

Also other checks, like mandatory keys.

AUTHOR

Joe Higton <draxil@gmail.com>

COPYRIGHT AND LICENSE

This software is copyright (c) 2017 by Joe Higton <draxil@gmail.com>.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.