Skip Menu |

This queue is for tickets about the Function-Parameters CPAN distribution.

Report information
The Basics
Id: 81178
Status: rejected
Priority: 0/
Queue: Function-Parameters

People
Owner: Nobody in particular
Requestors: perl [...] toby.ink
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: (no value)
Fixed in: (no value)



Subject: Definition callback
Yet another wishlist item... use Function::Parameters before => { name => 'required', shift => [qw( $self )], check_argument_count => 1, definition => sub { my $info = shift; # Function::Parameters::Info __PACKAGE__->meta->add_before_method_modifier( $info->name, $info->body, ); }, }; The idea being that if the "before" keyword is created as above, then this: before foo () { ...; } Then rather than "before" actually creating a sub in the current package, it passes the coderef, the name, etc to the definition callback. It still does all the shifting, argument checking, etc - the only thing it leaves the definition callback to do is add the coderef to the package's symbol table (or choose not to).
Subject: Re: [rt.cpan.org #81178] Definition callback
Date: Fri, 16 Nov 2012 14:22:54 +0100
To: bug-Function-Parameters [...] rt.cpan.org
From: Lukas Mai <l.mai [...] web.de>
On 14.11.2012 22:50, Toby Inkster via RT wrote: Show quoted text
> Yet another wishlist item... > > use Function::Parameters before => { > name => 'required', > shift => [qw( $self )], > check_argument_count => 1, > definition => sub { > my $info = shift; # Function::Parameters::Info > __PACKAGE__->meta->add_before_method_modifier( > $info->name, > $info->body, > ); > }, > }; > > The idea being that if the "before" keyword is created as above, then > this: > > before foo () { > ...; > } > > Then rather than "before" actually creating a sub in the current > package, it passes the coderef, the name, etc to the definition > callback. > > It still does all the shifting, argument checking, etc - the only thing > it leaves the definition callback to do is add the coderef to the > package's symbol table (or choose not to).
Sounds a bit like decorators, but it seems like an abuse of F:P because 'before' would be a keyword for defining functions that doesn't actually define those functions (that is, 'before foo {}' doesn't actually create a sub foo here). It would be annoying to implement because - the code currently simply calls the perl API function newATTRSUB(floor, name, proto, attrs, body), which takes care of all the details. This part would need a rewrite. - keyword properties are currently stored in %^H (yay, lexical pragmas). This is easy because they're all numbers/strings. But %^H can't store references (including coderefs such as the proposed 'definition' property). Given all that, wouldn't it be much easier (and arguably more readable) to just say: before foo => method () { }; ?