Advertisement
happy-barney

ENTER / LEAVE

Jul 20th, 2020
648
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 0.41 KB | None | 0 0
  1.  
  2. use Hook::LexWrap;
  3.  
  4. sub doit { print "[doit:", caller, "]"; return {my=>"data"} }
  5.  
  6. SCOPED: {
  7.         wrap doit =>
  8.                 pre  => sub { print "[pre1: @_]\n" },
  9.                 post => sub { print "[post1:@_]\n"; $_[1]=9; };
  10.  
  11.         my $temporarily = wrap doit =>
  12.                 post => sub { print "[post2:@_]\n" },
  13.                 pre  => sub { print "[pre2: @_]\n  "};
  14.  
  15.         @args = (1,2,3);
  16.         doit(@args);    # pre2->pre1->doit->post1->post2
  17. }
  18.  
  19. @args = (4,5,6);
  20. doit(@args);            # pre1->doit->post1
  21.  
  22. ----------------------------------------------
  23.  
  24. sub doit { print "[doit:", caller, "]"; return {my=>"data"} }
  25.  
  26. ENTER &doit { print "[pre1: @_]\n" }
  27. LEAVE &doit { print "[post1:@_]\n"; $_[1]=9; }
  28.  
  29. SCOPED: {
  30.     ENTER &doit { print "[post2:@_]\n" }
  31.     LEAVE &doit { print "[pre2: @_]\n"}
  32.  
  33.     @args = (1,2,3);
  34.     doit(@args);    # pre2->pre1->doit->post1->post2
  35. }
  36.  
  37. @args = (4,5,6);
  38. doit(@args);            # pre1->doit->post1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement