#!/usr/bin/perl use strict; use Params::Check qw(check); my_sub( handle => 'Test', 'thing' => 'something'); other_sub( handle => 'Test', 'other' => 'oops'); sub my_sub { my %hash = @_; my $x; my $tmpl = { handle => { required => 1 }, thing => { required => 1 }, }; my $args = check( $tmpl, \%hash ) or die("Failed to parse args"); print "HANDLE: $args->{handle}\nTHING: $args->{thing}\n"; } sub other_sub { my %hash = @_; my $x; my $tmpl = { handle => { required => 0 }, thing => { required => 0, default => 'uncle' }, other => { required => 1 }, }; my $args = check( $tmpl, \%hash ) or die("Failed to parse args"); print "HANDLE: $args->{handle}\nTHING: $args->{thing}\nOTHER: $args->{other}\n"; }