#!/usr/bin/perl use strict; use Class::ParmList qw (simple_parms parse_parms); my_sub( handle => 'Test', 'thing' => 'something'); other_sub( handle => 'Test', 'other' => 'oops'); sub my_sub { my ($handle, $thing) = simple_parms([qw(handle thing)], @_); print "HANDLE: $handle\nTHING: $thing\n"; } sub other_sub { my ($handle, $thing, $other) = parse_parms( -parms => \@_, -legal => ['handle','thing'], -required => ['other'], -defaults => {'thing' => 'uncle'}, )->get('handle','thing','other'); print "HANDLE: $handle\nTHING: $thing\nOTHER: $other\n"; } #### #!/usr/bin/perl use strict; use Params::Named; my_sub( handle => 'Test', 'thing' => 'something'); sub my_sub { MAPARGS \my($handle, $thing); print "HANDLE: $handle\nTHING: $thing\n"; } #### #!/usr/bin/perl use strict; use Params::Smart; my_sub( handle => 'Test', 'thing' => 'something'); sub my_sub { my %args = Params(qw(handle thing ?other))->args(@_); print "HANDLE: $args{handle}\nTHING: $args{thing}\nOTHER: $args{other}\n"; } #### #!/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"; } #### #!/usr/bin/perl use strict; my_sub( handle => 'Test', 'thing' => 'something'); sub my_sub { my %args = @_; my ($handle, $thing) = @args{'handle','thing'}; print "HANDLE: $handle\nTHING: $thing\n"; }