[Israel.pm] Implicit $self variable without Source Filters

Gaal Yahas gaal at forum2.org
Tue Nov 7 02:37:50 PST 2006


On Tue, Nov 07, 2006 at 08:55:27AM +0000, Ran Eilam wrote:
> But there are other problems with source filters. What else does the
> .pmc approach solve?

Filters using Module::Compile technology are of course source filters,
but they don't break as easily as traditional ones. They are composable,
and line numbers don't get screwed up. The .pmc file is shippable.

This talk mentions it, I think:

    http://pugs.blogs.com/talks/boston-deploying-perl6.pdf

> > The more immediate downside is perhaps that since $self is not a lexical,
> > it cannot be further closed upon. Unless it is copied, but that sort of
> > misses the point of this magic. Still, this is pretty cool.
> 
> I don't understand the downside you are pointing at. What difference
> does it make if $self is lexical or dynamic here?

Say I want to write a method that returns a closure closing on the
invocant.

    sub mk_tagger {
        my($widget, $tag) = @_;
        return sub {
            my $text = $widget->get_active_text;
            return "<$tag>$text</$tag>";
        }
    }

A little backwards perhaps, but you'll notice that the returned closure
doesn't need to receive the widget as an argument in future invocations,
because it's closed upon. This might be useful when you're handing off
this closure to be called by some callback mechanism and you want to
save the argument slot for something else.

Since $widget (or $self) here would be a package var under Shlomi's
scheme, this would break.

-- 
Gaal Yahas <gaal at forum2.org>
http://gaal.livejournal.com/



More information about the Perl mailing list