Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: How best to validate the keys of hashref arguments?

by haukex (Archbishop)
on Mar 16, 2017 at 09:39 UTC ( [id://1184851]=note: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    use Carp;
    my %FOO_KNOWN_ARGS = map {$_=>1} qw/ quz baz /;
    ...
    }
    foo(quz=>1,baz=>1);
    foo(quz=>1,baz=>1,bar=>1); # dies
    
  2. or download this
    use Hash::Util qw/lock_ref_keys/;
    my $foo = {};
    lock_ref_keys($foo, qw/ quz baz /);
    $foo->{quz} = 1;
    $foo->{bar} = 1; # dies
    
  3. or download this
    {   package Foo;
        use Moo;
    ...
        die "Not a Foo" unless blessed($foo) && $foo->isa('Foo');
        print "baz2, the foo is ",$foo->foo,"\n";
    }
    

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1184851]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (3)
As of 2024-04-25 07:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found