Attribute::Context

Ovid on 2003-12-12T23:44:54

I've released Attribute::Context (originally called Sub::Attributes. Amongst other things, I eliminated the Iterator attribute. It wasn't very useful, but I've replaced it with a "Custom" attribute. I'll flesh that out more later as I get better ideas, but for the time being, in list context you get your list and in scalar context you get an object.

sub foo : Custom(My::Class) {
    # do stuff
    return @results;
}

# get @results
my @stuff = foo(@data);

# get My::Class->new(\@results)
my $thing = foo(@data);

And there is now more robust dealing with void context:

sub foo : First(WARNVOID) {...}

sub thing : Custom( class => 'My::Class', NOVOID => 1 ) {...}

The Custom attribute will probably grow into something like this:

my %specification = (
    class       => 'My::Class',
    constructor => 'build', # defaults to 'new'
    listref     => 0, # form the contructor argument takes
    args        => \@args, additional args passed in before \@results
    WARNVOID    => 1,
);

sub foo :Custom(%specification) {...}

Of course, there's no point in doing that unless people use it. chromatic's article about open source myths hits the nail on the head when he points out that you're lucky to even hear from people using your software, much less offering suggestions or help.