Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Using pseudohash for argument list validation

by rinceWind (Monsignor)
on Apr 28, 2002 at 10:42 UTC ( #162645=perlquestion: print w/replies, xml ) Need Help??

rinceWind has asked for the wisdom of the Perl Monks concerning the following question:

Monks,

There has been much discussion recently about argument passing, see Shift versus Sanity and Sub::HashWrap.

Glancing at the Camel book, I was reminded of the pragmatic module use fields in the context of validating data fields in an object at compile time. The underlying mechanism used is a pseudohash.

I was wondering whether something similar could be used for named arguments to a sub or method, detecting typos at compile time.

I also understand that phashes are an experimental feature from 5.5 on, which could change. Are they here to stay? Are they OK so long as you use fields::phash?

Thoughts please. --rW

Replies are listed 'Best First'.
Re: Using pseudohash for argument list validation
by particle (Vicar) on Apr 28, 2002 at 12:30 UTC
(crazyinsomniac) Re: Using pseudohash for argument list validation
by crazyinsomniac (Prior) on Apr 29, 2002 at 09:51 UTC
    It is experimental, and you ought to drop a line to the perl devel mailing list (or Dominus) for info about the future. Experimental things do actually go away sometimes.

    Also, I'd like to point you to ArrayHashMonster from the M.J.Dominus ( http://perl.plover.com) which says ( in README)

    It's alive! It's Aliiiive! Is it an array, or is it a hash? Neither! Both! It's a disgusting frankenstein's monster made by sewing together bits and pieces of arrays and hashes into a monstrous and unholy creation! What does it do? It manufactures an object that can be used as either an array reference or a hash reference. Why would you ever want such a thing? Well, it's the natural way to present an ordered hash. You could then use $orderedhash->[7] to get item number seven, or $orderedhash->{key} to get the item with the specified key. Or for example you could have an object that represents a directory. $dir->[3] gets the name of file number 3 from the directory, so it is easy to iterate over the files in the directory, and $dir->{name} gets the stat information for the file named `$name'. The test.pl file has a demonstration of how to do this. Discovery of how this works is left as an exercise for the reader.

     
    ______crazyinsomniac_____________________________
    Of all the things I've lost, I miss my mind the most.
    perl -e "$q=$_;map({chr unpack qq;H*;,$_}split(q;;,q*H*));print;$q/$q;"

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (3)
As of 2023-02-04 01:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I prefer not to run the latest version of Perl because:







    Results (30 votes). Check out past polls.

    Notices?