Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Can I find out which package a subroutine is from, originally?

by tye (Sage)
on Jan 03, 2001 at 06:13 UTC ( [id://49436]=note: print w/replies, xml ) Need Help??


in reply to Can I find out which package a subroutine is from, originally?

In Re: Validating a Code Reference I mention my favorite, Devel::Peek::CvGV(), which I just tested and using it on \&main::ImportedFunction appears to give you the original package name.

You could also try some of the other solutions mentioned in that thread.

Update: Now that I got first post (j/k), here is some tested code:

#!/usr/bin/perl -w use strict; use Devel::Peek "CvGV"; my $x= CvGV(\&CvGV); print "$x\n"; $x =~ s/^\*//; $x =~ s/::[^:]+$//; print "CvGV came from $x.\n";
which prints "*Devel::Peek::CvGV" then "CvGV came from Devel::Peek."

        - tye (but my friends call me "Tye")

Replies are listed 'Best First'.
Re: Re: Can I find out which package a subroutine is from, originally?
by nate (Monk) on Jan 03, 2001 at 07:22 UTC
    Dang, you so smoove!

    Revised code as so:

    use Devel::Peek "CvGV"; my $module = "Everything::Node::user"; #a bit of code clipped from the perl cookbook use no strict; local *stash; *stash = *{ "${module}::" }; #this is assuming the module has been "use"d -- which it has my @modfuncs; foreach(keys %stash) { my $glob = CvGV(\&{$stash{$_}}); $glob =~ s/^\*//; push (@modfuncs, $_) if defined &{ $stash{$_} } and $glob eq "$module\:\:$_"; } @modfuncs; #only the functions in my module!

    And it works! Thanks...

    --nate

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://49436]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2024-04-25 19:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found