develooper Front page | perl.perl5.porters | Postings from January 2011

Re: [PATCH] use feature 'method'; (was Re: Proposal: "$->" for implicit invocant)

Thread Previous | Thread Next
January 20, 2011 11:29
Re: [PATCH] use feature 'method'; (was Re: Proposal: "$->" for implicit invocant)
Message ID:
On Thursday 20 January 2011 at 10:32, Zefram  wrote:

> You should prototype this as a CPAN module, using the keyword hook.

How do you use keyword hooks to add 'method' to the imports of

> It also seems very unwise for the core to take the keyword "method" at
> this stage.  We have several CPAN modules supplying "method" keywords
> with various semantics, it's an unresolved area.

To my knowledge, none of them import 'method' from

> As something to go in the core, I do not approve of this shortcut.
> You should definitely build the optree rather than stuff source.

That means:

 * grabbing the optree *already generated* for the body of the sub
 * creating a new lexical $self binding in that optree
 * rummaging through every variable access in that entire optree to find $self, 
if it exists
 * rebinding those package globals to the lexical
 * building up the appropriate optree for 'my $self = shift';
 * splicing the new optree to the existing optree

I've done all of this before with B::Generate activated by a new :method 
attribute on existing subs.  It's fragile and unpleasant enough in Perl, and 
it's a lot of special-purpose code to stuff into perly.y.

The worst part is doing this all in a way that doesn't trip the strict pragma.  
I don't know how to do that.

Alternately, you could take the approach that doesn't add at least a few 
hundred lines of new code to the parser for a special case.  You could use as 
much existing code as possible (code that knows how to build an optree, code 
that knows how to create lexicals, code that knows how to decide $self is 
lexical, et cetera).

-- c

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About