Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'callsame' in postcircumfix:<( )> method in routine trait does nothing in Rakudo #3088

Open
p6rt opened this issue Mar 27, 2013 · 4 comments
Labels

Comments

@p6rt
Copy link

p6rt commented Mar 27, 2013

Migrated from rt.perl.org#117377 (status was 'open')

Searchable as RT117377$

@p6rt
Copy link
Author

p6rt commented Mar 27, 2013

From @masak

<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

@p6rt
Copy link
Author

p6rt commented Mar 29, 2013

From @hoelzro

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

@p6rt
Copy link
Author

p6rt commented May 8, 2018

From @skids

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.

@p6rt
Copy link
Author

p6rt commented May 8, 2018

The RT System itself - Status changed from 'new' to 'open'

@p6rt p6rt added the Bug label Jan 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant