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

Re^5: Near-free function currying in Perl

by dragonchild (Archbishop)
on Nov 17, 2004 at 16:20 UTC ( #408458=note: print w/replies, xml ) Need Help??

in reply to Re^4: Near-free function currying in Perl
in thread Near-free function currying in Perl

I like
sub foo : required($$$) { ... }

That allows more than just currying to use the attribute. Also, you can then do something like:

sub foo : required( address, city, state, zip ) { ... }

That way, you can do both parameter validation and named-parameter currying (as per Limbic~Region's comment below). Plus, you're specifying the API, which would allow for something like doxygen to document your API.

An even nicer thing would be to combine this idea of a required() attribute to methods, meaning that you could do something like:

package Foo; sub new : required( attr1, attr2 ) : optional( attr3 ) { ... }

This would behave like Class::MethodMaker and create the attr1(), attr2(), and attr3() mutators, plus require that the first two be passed in to the constructor.

It wouldn't be too hard to come up with a list of useful function/method attributes. Off the top of my head, I can see multiple uses for:

  • required
  • optional
  • deprecated

Being right, does not endow the right to be rude; politeness costs nothing.
Being unknowing, is not the same as being stupid.
Expressing a contrary opinion, whether to the individual or the group, is more often a sign of deeper thought than of cantankerous belligerence.
Do not mistake your goals as the only goals; your opinion as the only opinion; your confidence as correctness. Saying you know better is not the same as explaining you know better.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2020-12-03 07:57 GMT
Find Nodes?
    Voting Booth?
    How often do you use taint mode?

    Results (52 votes). Check out past polls.