Skip Menu |
Report information
Id: 127112
Status: open
Priority: 0/
Queue: perl6

Owner: Nobody
Requestors: lloyd.fourn [at] gmail.com
Cc:
AdminCc:

Severity: (no value)
Tag: (no value)
Platform: (no value)
Patch Status: (no value)
VM: (no value)



To: "rakudobug [...] perl.org" <rakudobug [...] perl.org>
From: Lloyd Fournier <lloyd.fourn [...] gmail.com>
Date: Fri, 01 Jan 2016 16:48:48 +0000
Subject: .wrap doesn't work for routines declared in roles
role Foo {
    sub foo { };
    BEGIN &foo.wrap(-> {});
}
To: perl6-bugs-followup [...] perl.org
From: Lloyd Fournier <lloyd.fourn [...] gmail.com>
Date: Fri, 01 Jan 2016 16:58:41 +0000
Subject: Re: [perl #127112] AutoReply: .wrap doesn't work for routines declared in roles
Download (untitled) / with headers
text/plain 949b
should have mentioned, this is the error msg:

===SORRY!=== Error while compiling 
  Cannot invoke this object

On Sat, Jan 2, 2016 at 3:49 AM perl6 via RT <perl6-bugs-followup@perl.org> wrote:
Show quoted text
Greetings,

This message has been automatically generated in response to the
creation of a trouble ticket regarding:
        ".wrap doesn't work for routines declared in roles",
a summary of which appears below.

There is no need to reply to this message right now.  Your ticket has been
assigned an ID of [perl #127112].

Please include the string:

         [perl #127112]

in the subject line of all future correspondence about this issue. To do so,
you may reply to this message.

                        Thank you,
                        perl6-bugs-followup@perl.org

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

Subject: Re: [perl #127112] AutoReply: .wrap doesn't work for routines declared in roles
Date: Sat, 02 Jan 2016 09:47:45 +0000
From: Lloyd Fournier <lloyd.fourn [...] gmail.com>
To: perl6-bugs-followup [...] perl.org
Download (untitled) / with headers
text/plain 1.4k
I golfed this down to:

p6 -e 'role {sub foo {};  BEGIN &foo.clone() }'

===SORRY!=== Error while compiling -e
An exception occurred while evaluating a BEGIN
at -e:1
Exception details:
  ===SORRY!=== Error while compiling 
  Cannot invoke this object
  at :

For reasons I don't quite understand it's not using the right clone. If you use Mu::clone directly it works:

p6 -e 'role {sub foo {};  BEGIN &foo.Mu::clone() }'

On Sat, Jan 2, 2016 at 3:58 AM Lloyd Fournier <lloyd.fourn@gmail.com> wrote:
Show quoted text
should have mentioned, this is the error msg:

===SORRY!=== Error while compiling 
  Cannot invoke this object

On Sat, Jan 2, 2016 at 3:49 AM perl6 via RT <perl6-bugs-followup@perl.org> wrote:
Greetings,

This message has been automatically generated in response to the
creation of a trouble ticket regarding:
        ".wrap doesn't work for routines declared in roles",
a summary of which appears below.

There is no need to reply to this message right now.  Your ticket has been
assigned an ID of [perl #127112].

Please include the string:

         [perl #127112]

in the subject line of all future correspondence about this issue. To do so,
you may reply to this message.

                        Thank you,
                        perl6-bugs-followup@perl.org

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

From: Elizabeth Mattijsen <liz [...] dijkmat.nl>
To: "Lloyd Fournier (via RT)" <perl6-bugs-followup [...] perl.org>
Subject: Re: [perl #127112] .wrap doesn't work for routines declared in roles
Date: Sat, 2 Jan 2016 11:13:55 +0100
Download (untitled) / with headers
text/plain 1.2k
Show quoted text
> On 01 Jan 2016, at 17:49, Lloyd Fournier (via RT) <perl6-bugs-followup@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
To: perl6-bugs-followup [...] perl.org
From: Lloyd Fournier <lloyd.fourn [...] gmail.com>
Subject: Re: [perl #127112] .wrap doesn't work for routines declared in roles
Date: Sat, 02 Jan 2016 10:27:01 +0000
Download (untitled) / with headers
text/plain 2.2k
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-followup@perl.org> wrote:
Show quoted text

> On 01 Jan 2016, at 17:49, Lloyd Fournier (via RT) <perl6-bugs-followup@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



This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

For issues related to this RT instance (aka "perlbug"), please contact perlbug-admin at perl.org