Hey Liz,

Sorry this was a case of me golfing something down then not explaining the
.WHY of what I was originally doing. This is what I was trying to achieve.

multi trait_mod:<is>(Routine:D $meth,:$baz!) {
     $meth.wrap( -> \SELF,$subj {});
};

role Foo {
    method foo is baz { };
}

Obviously traits are run at compile time. To me if you can't use a trait
that wraps a method in a role that's a very weird and annoying
inconsistency.

Also I don't think there is any architectural reason why methods in roles
can't be .wrap'd, I think it's just an edge case that hasn't been tested
for yet. As I showed above it's happening in .clone which for some reason
(which I would love to understand) is not Mu::clone but some bootstrapping
clone:

Lloyds-iMac:~ llfourn$ perl6 -e 'sub foo { }; BEGIN
&foo.^find_method("clone").^name.say'
ForeignCode






On Sat, Jan 2, 2016 at 9:14 PM Elizabeth Mattijsen via RT <
perl6-bugs-follo...@perl.org> wrote:

>
> > 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