Skip to content

Instantly share code, notes, and snippets.

@Xliff
Created February 22, 2019 00:25
Show Gist options
  • Save Xliff/74a448e07fed4014c8326d8bd14a41d8 to your computer and use it in GitHub Desktop.
Save Xliff/74a448e07fed4014c8326d8bd14a41d8 to your computer and use it in GitHub Desktop.

Hey there, Perl6'ers!

Can anyone tell me if this is seriously slow? If so, is there a better way to write it?

  method CALLING-METHOD($nf is copy = 3) {
    my $c = callframe($nf).code;
    while $c !~~ Routine {
      my $cf = callframe(++$nf);
      die 'Exceeded backtrace when searching for calling routine' 
        if $cf ~~ Failure;
      $c = $cf.code;
      next if $c.^name eq 'Block';
      # Special casing is hell!
      if 
        $c.package.^name eq 'GLOBAL' || 
        'is-hidden-from-backtrace'  $c.^roles.map( *.^name )
      { 
        $c = False;
        next;
      }
    }
    "{ $c.package.^name }.{ $c.name }";
  }
@Xliff
Copy link
Author

Xliff commented Feb 22, 2019

OK, so I ended up with this:

  method CALLING-METHOD($nf is copy = 3) {
    my $c = callframe($nf).code;
    while $c !~~ Routine {
      my $cf = callframe(++$nf);
      die 'Exceeded backtrace when searching for calling routine' 
        if $cf ~~ Failure;
      $c = $cf.code;
      next if $c.^name eq 'Block';
      # Special casing is hell! -- Allow for shortcircuit
      unless  
        $c.package.^name ne <
          GLOBAL Any::IterateOneWithoutPhasers List
        >.any
        ##||
        #'is-hidden-from-backtrace' ∈ $c.^roles.map( .^name )
      { 
        $c = False;
        next;
      }
    }
    "{ $c.package.^name }.{ $c.name }";
  }

It seems to work well enough, but I do dislike the special casing required to get it working.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment