Guest User

Untitled

a guest
Jan 18th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.18 KB | None | 0 0
  1. $ perl -MDevel::Peek -MList::Util=first -e'Dump(&first)'
  2. SV = IV(0x1094e20) at 0x1094e28
  3. REFCNT = 1
  4. FLAGS = (TEMP,ROK)
  5. RV = 0x11183b0
  6. SV = PVCV(0x10ff1f0) at 0x11183b0
  7. REFCNT = 3
  8. FLAGS = (POK,pPOK)
  9. PROTOTYPE = "&@"
  10. COMP_STASH = 0x0
  11. XSUB = 0x7f7ecbdc61b0
  12. XSUBANY = 0
  13. GVGV::GV = 0x11183c8 "List::Util" :: "first"
  14. FILE = "ListUtil.c"
  15. DEPTH = 0
  16. FLAGS = 0x800
  17. OUTSIDE_SEQ = 0
  18. PADLIST = 0x0
  19. OUTSIDE = 0x0 (null)
  20.  
  21. =head2 C<CvGV_name_or_bust> I<coderef>
  22.  
  23. Calls L<Devel::Peek> to try to find the glob the ref lives in; returns
  24. C<undef> if L<Devel::Peek> can't be loaded, or if C<Devel::Peek::CvGV> can't
  25. find a glob for this ref.
  26.  
  27. Returns C<< I<package>::I<glob name> >> if the code ref is found in a glob.
  28.  
  29. =cut
  30.  
  31. sub CvGV_name_or_bust {
  32. my $in = shift;
  33. return unless ref $in;
  34. $in = &$in; # Hard reference...
  35. eval { require Devel::Peek; 1 } or return;
  36. my $gv = Devel::Peek::CvGV($in) or return;
  37. *$gv{PACKAGE} . '::' . *$gv{NAME};
  38. } ## end sub CvGV_name_or_bust
  39.  
  40. =head2 C<CvGV_name_or_bust> I<coderef>
  41.  
  42. Calls L<Devel::Peek> to try to find the glob the ref lives in; returns
  43. C<undef> if L<Devel::Peek> can't be loaded, or if C<Devel::Peek::CvGV> can't
  44. find a glob for this ref.
  45.  
  46. Returns C<< I<package>::I<glob name> >> if the code ref is found in a glob.
  47.  
  48. =cut
  49.  
  50. sub CvGV_name_or_bust {
  51. my $in = shift;
  52. return unless ref $in;
  53. $in = &$in; # Hard reference...
  54. eval { require Devel::Peek; 1 } or return;
  55. my $gv = Devel::Peek::CvGV($in) or return;
  56. *$gv{PACKAGE} . '::' . *$gv{NAME};
  57. } ## end sub CvGV_name_or_bust
  58.  
  59. #! /usr/bin/perl
  60.  
  61. use warnings;
  62. use strict;
  63.  
  64. package Foo;
  65.  
  66. sub bar {}
  67.  
  68. package main;
  69.  
  70. BEGIN { *baz = &Foo::bar }
  71.  
  72. sub CvGV_name_or_bust { ... }
  73.  
  74. print CvGV_name_or_bust(&baz), "n";
  75.  
  76. Foo:bar
  77.  
  78. perl -MEncode -e 'print join "n", @Encode::EXPORT'
  79. decode
  80. decode_utf8
  81. ...
  82.  
  83. use Encode qw[ encode ]; # encode() imported from the Encode module
  84. use Data::Dumper qw[]; # no functions imported from Data::Dumper
  85.  
  86. use Sub::Identify qw/sub_fullname/;
  87. sub foo {
  88. print sub_fullname( &foo ); # main::foo
  89. print sub_fullname( sub{} ); # main::__ANON__
  90. }
  91.  
  92. foo();
Add Comment
Please, Sign In to add comment