Sub::Attributes

Ovid on 2003-12-09T22:54:12

Just playing around, I wrote a small package that will let you do things like this:

use base 'Sub::Attributes';

sub reverse_me : Arrayref(NOVOID) {
    reverse @_;
}

The above function, if called in void context, will die. If called in list context will return its arguments. If called in scalar context will return a reference to its arguments. This is to solve the problem people face when they try to figure out which of twenty different ways to handle scalar context should they use this week. Return a reference, the first item (like &CGI::param), the last item, a count of items, etc. Currently, I only have the arrayref and an iterator implemented.

API suggestions and code critique are welcome.


Want.pm light

djberg96 on 2003-12-09T23:27:27

Looks like a lightweight version of Want.pm. Not bad, though, as Want may be overkill for some folks.

Re:Want.pm light

Ovid on 2003-12-10T00:29:51

Imagine if Want and Regexp::Common had sex. You have a handy predefined list of common behaviors that a user can assign to a subroutine without worrying about getting the exact syntax perfect. Just figure out which behavior you want for a given context and ask for it. You won't actually have to set up the behaviors for the different contexts, though. It gets done for you, thus lowering the number of bugs.