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

Owner: Nobody
Requestors: masak <cmasak [at] gmail.com>
Cc:
AdminCc:

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



Subject: [BUG] 'callsame' in postcircumfix:<( )> method in routine trait does nothing in Rakudo
Date: Wed, 27 Mar 2013 16:21:53 +0100
To: rakudobug [...] perl.org
From: Carl Mäsak <cmasak [...] gmail.com>
Download (untitled) / with headers
text/plain 1.3k
<hoelzro> callsame from method in a role will call the original method from the class, won't it? <hoelzro> I'm trying to create a routine trait for doing something after the original routine has returned <PerlJam> hoelzro: show us? <hoelzro> https://gist.github.com/hoelzro/5254952 multi trait_mod:<is>(Routine:D $r, :$pre-check) { $r does role { method postcircumfix:<( )>(|) { say 'before'; my $result = callsame; say 'after'; say "result = $result"; $result } } } sub mysub is pre-check { say 'there'; 17 } mysub(); <hoelzro> so how do I do this? =) <masak> looks compeltely right what you're doing. <hoelzro> well, it doesn't work =( * masak runs code locally $ perl6 that-gist-there before after result = <masak> huh. <hoelzro> doesn't work for you either? <masak> r: class C { method foo { say "there"; 17 } }; my $x = C.new but role { method foo { my $result = callsame; say "after $result" } }; $x.foo <p6eval> rakudo a23458: OUTPUT«there␤after 17␤» <masak> I postulate that the trouble is with postcircumfix:<( )> somehow. <hoelzro> I see... <masak> it doesn't seem that 'callsame' in your code even calls the original sub. <hoelzro> it doesn't <hoelzro> that's the issue =/ <hoelzro> it just skips over the line with callsame * masak submits rakudobug
Download (untitled) / with headers
text/plain 798b
Hi everyone, I spent a lot of time yesterday looking at this bug, and I believe I've figured out what's going on. So Code objects do not actually have a postcircumfix:<( )> method; they rely on an 'invoke' hook in Parrot to invoke the block associated with their $!do attribute. I've tried to add the method as a fallback point for callsame and friends, but Rakudo fails to build when I do so. Hopefully someone more experienced with Rakudo will be able to take advantage of my research and fix things up! Location of invoke hook stuff: search BOOTSTRAP.pm for Code.HOW. add_parrot_vtable_mapping and Code.HOW.add_parrot_vtable_handler_mapping Attempt #1 to add postcircumfix:<( )> to Code.pm: https://gist.github.com/hoelzro/5272331 Attempt #2: https://gist.github.com/hoelzro/5272341 -Rob
Download (untitled) / with headers
text/plain 699b
This is a very old ticket and we no longer have postcircumfix:<( )> for objects. If you redo the example to use CALL-ME it still does not call the original class method, however, CALL-ME is defined as a submethod, not a method, and testing the difference: $ perl6 -e 'class S { method x { "Sx".say } }; role T { method x { "Sy".say; callsame } }; class V is S does T { }; my $v = V.new; $v.x' Sy Sx $ perl6 -e 'class S { submethod x { "Sx".say } }; role T { method x { "Sy".say; callsame } }; class V is S does T { }; my $v = V.new; $v.x' Sy ...so while there may still be an "issue" if there's no way to "do that" in a modern rakudo, perhaps best to write up a new github issue and close this.


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