> On 01 Jan 2016, at 17:49, Lloyd Fournier (via RT) 
> <perl6-bugs-follo...@perl.org> wrote:
> 
> # New Ticket Created by  Lloyd Fournier 
> # Please include the string:  [perl #127112]
> # in the subject line of all future correspondence about this issue. 
> # <URL: https://rt.perl.org/Ticket/Display.html?id=127112 >
> 
> 
> role Foo {
>    sub foo { };
>    BEGIN &foo.wrap(-> {});
> }

One should realize that a role is nothing but a place-holder for code to be 
inserted when it is either does’d by a class, or punned into a class.   It 
doesn't execute code in the mainline of the role after it has been parsed.  
Unless you use BEGIN of course.

If you remove the BEGIN from you example, I *think* it does what you expect it 
to:

role Foo {
    sub foo { };
    &foo.wrap(-> { "foo" });

    say "mainline";

    method a { foo }
}

BEGIN say "role done";

say Foo.a
==============================
role done
mainline
foo

Note that the “mainline” is executed *after* the BEGIN block after the role.

Disallowing BEGIN blocks inside a role, might be an option.  OTOH, there might 
be valid uses for that as well, doing MOPpy things.


So, all in all, I think this is a case of an LTA error.   Is that what you 
intended to report?




Liz

Reply via email to