What you want are C< defined &{$pack.'::'.$sub} >
and C< $pack->can($sub) > depending you want subroutines
defined in the package or methods callable from the package.
Robin
>perl -lwe "my($pack,$sub) = @ARGV; \
unless(eval 'require '.$pack) {print 'No package '.$pack} \
elsif( defined &{$pack.'::'.$sub} ) { print 'Subroutine' }\
elsif( $pack->can($sub) ){ print 'Method' }" IO::File printf
Method
-----Original Message-----
From: Randy W. Sims
To: [email protected]
Cc: [EMAIL PROTECTED]
Sent: 09/01/05 12:22
Subject: Re: [perl #33728] Missing in docs
Victor Porton,,, (via RT) wrote:
> # New Ticket Created by "Victor Porton,,,"
> # Please include the string: [perl #33728]
> # in the subject line of all future correspondence about this issue.
> # <URL: http://rt.perl.org:80/rt3/Ticket/Display.html?id=33728 >
>
>
> In Perl docs (such as perlmod manpage) there are missing
> an explanation (or at least is too hard to find) how to
> do the following think:
>
> Having two strings, check whether in the package with
> given name (first string) there are a subroutine with
> given name (second string).
>
> I've already tried about ten variants neither works.
> Even if one could work, I'm not sure that it will be
> compatible with future versions of Perl 5.
>
> So, we need docs clearly explain how to check for
> existence of a subroutine in a package having package
> name and subroutine name as strings.
perldoc UNIVERSAL
package->can( 'foo' );
$obj->can( 'foo' );
You might also take a look at Module::Info on CPAN. Additionally, for a
peek inside try:
use Data::Dumper;
warn Dumper( \%package:: );
-------------------------------------------------------------------
This e-mail and any attachments may contain confidential and/or
privileged material; it is for the intended addressee(s) only.
If you are not a named addressee, you must not use, retain or
disclose such information.
NPL Management Ltd cannot guarantee that the e-mail or any
attachments are free from viruses.
NPL Management Ltd. Registered in England and Wales. No: 2937881
Registered Office: Teddington, Middlesex, United Kingdom TW11 0LW.
-------------------------------------------------------------------