Advertisement
Guest User

Untitled

a guest
Sep 18th, 2019
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. This is due to the indirect-object syntax, and is a more elaborate variation on [this example](https://stackoverflow.com/a/11695310/4653379).
  2.  
  3. The ["indirect object notation"](https://perldoc.perl.org/perlobj.html#Invoking-Class-Methods) allows code
  4.  
  5. method Package @args;
  6.  
  7. method { $invocant } @args;
  8.  
  9. to be used instead of
  10.  
  11. Package->method(@args);
  12.  
  13. $invocant->method(@args);
  14.  
  15. So the "try" and "catch" words don't matter. The interesting bit here is the more involved and extended syntax, with two parts, each in this indirect object notation.
  16.  
  17. This means that
  18.  
  19. try {
  20. call_a( 'x' );
  21. } catch {
  22. die "ACTUALLY die $_";
  23. };
  24.  
  25. is equivalent to
  26.  
  27. (do {
  28. call_a( 'x' );
  29. })->try(
  30. do({
  31. die("ACTUALLY die $_");
  32. })->catch();
  33. );
  34.  
  35. which simplifies to
  36.  
  37. call_a( 'x' )->try( die("ACTUALLY die $_")->catch() );
  38.  
  39. The code is interpreted with valid syntax (!) and it is the _contents of the block after `try` that runs first_ --- so the program dies and never gets to go for the "method" `try`.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement