Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $ perl -MDevel::Peek -MList::Util=first -e'Dump(&first)'
- SV = IV(0x1094e20) at 0x1094e28
- REFCNT = 1
- FLAGS = (TEMP,ROK)
- RV = 0x11183b0
- SV = PVCV(0x10ff1f0) at 0x11183b0
- REFCNT = 3
- FLAGS = (POK,pPOK)
- PROTOTYPE = "&@"
- COMP_STASH = 0x0
- XSUB = 0x7f7ecbdc61b0
- XSUBANY = 0
- GVGV::GV = 0x11183c8 "List::Util" :: "first"
- FILE = "ListUtil.c"
- DEPTH = 0
- FLAGS = 0x800
- OUTSIDE_SEQ = 0
- PADLIST = 0x0
- OUTSIDE = 0x0 (null)
- =head2 C<CvGV_name_or_bust> I<coderef>
- Calls L<Devel::Peek> to try to find the glob the ref lives in; returns
- C<undef> if L<Devel::Peek> can't be loaded, or if C<Devel::Peek::CvGV> can't
- find a glob for this ref.
- Returns C<< I<package>::I<glob name> >> if the code ref is found in a glob.
- =cut
- sub CvGV_name_or_bust {
- my $in = shift;
- return unless ref $in;
- $in = &$in; # Hard reference...
- eval { require Devel::Peek; 1 } or return;
- my $gv = Devel::Peek::CvGV($in) or return;
- *$gv{PACKAGE} . '::' . *$gv{NAME};
- } ## end sub CvGV_name_or_bust
- =head2 C<CvGV_name_or_bust> I<coderef>
- Calls L<Devel::Peek> to try to find the glob the ref lives in; returns
- C<undef> if L<Devel::Peek> can't be loaded, or if C<Devel::Peek::CvGV> can't
- find a glob for this ref.
- Returns C<< I<package>::I<glob name> >> if the code ref is found in a glob.
- =cut
- sub CvGV_name_or_bust {
- my $in = shift;
- return unless ref $in;
- $in = &$in; # Hard reference...
- eval { require Devel::Peek; 1 } or return;
- my $gv = Devel::Peek::CvGV($in) or return;
- *$gv{PACKAGE} . '::' . *$gv{NAME};
- } ## end sub CvGV_name_or_bust
- #! /usr/bin/perl
- use warnings;
- use strict;
- package Foo;
- sub bar {}
- package main;
- BEGIN { *baz = &Foo::bar }
- sub CvGV_name_or_bust { ... }
- print CvGV_name_or_bust(&baz), "n";
- Foo:bar
- perl -MEncode -e 'print join "n", @Encode::EXPORT'
- decode
- decode_utf8
- ...
- use Encode qw[ encode ]; # encode() imported from the Encode module
- use Data::Dumper qw[]; # no functions imported from Data::Dumper
- use Sub::Identify qw/sub_fullname/;
- sub foo {
- print sub_fullname( &foo ); # main::foo
- print sub_fullname( sub{} ); # main::__ANON__
- }
- foo();
Add Comment
Please, Sign In to add comment