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

Proposal: "$->" for implicit invocant

Thread Next
From:
Chia-liang Kao
Date:
January 18, 2011 20:24
Subject:
Proposal: "$->" for implicit invocant
Message ID:
A0ACB9F6-CDC0-4257-9D4D-7471A6F1506F@bestpractical.com
Hi,

I just released the invoker module on cpan, and i'd like to
propose the syntax to be included in future perls.

why: with the blooming modules providing the "method" keyword, we
no longer need to have "my $self = shift" everywhere.  however
this makes "$self" now the most repeated code.

Here's the idea:

"use feature 'invocant'" enables the $-> operator.  There are two
variants:

- "use invocant '$self" looks for the specific lexical variable
   named $self in the current context, and bails out in compile
   time if not found.

- "use invocant 'auto'" looks for the first real pad entry in the
   nearest scope as the default invocant.

I am not sure which one suites as better default behaviour.  the
latter seems less intrusive on insisiting variable names by can
be a bit confusing.

Conflicts:

$-> can be parsed as $- > ($- greater than .. ), so we need to
deprecate the use of $- (and hopefully the whole format system by
requiring use of formats to add additional "use format" line.)
the feature can install a warning when accessing $- before such
deprecation.

What do people think?

Cheers,
CLK


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About