Perl / perl5

🐪 The Perl programming language
https://dev.perl.org/perl5/
Other
1.85k stars 527 forks source link

Missing in docs #7741

Closed p5pRT closed 19 years ago

p5pRT commented 19 years ago

Migrated from rt.perl.org#33728 (status was 'resolved')

Searchable as RT33728$

p5pRT commented 19 years ago

From porton@ex-code.com

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.

p5pRT commented 19 years ago

From RandyS@ThePierianSpring.org

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​:: );

p5pRT commented 19 years ago

The RT System itself - Status changed from 'new' to 'open'

p5pRT commented 19 years ago

From Robin.Barker@npl.co.uk

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​: perl5-porters@​perl.org Cc​: bugs-bitbucket@​netlabs.develooper.com 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.


p5pRT commented 19 years ago

From @ysth

On Sun\, Jan 09\, 2005 at 07​:22​:39AM -0500\, Randy W. Sims wrote​:

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' );

can() will also check for inherited methods\, which may or may not be what he wants.

You might also take a look at Module​::Info on CPAN. Additionally\, for a peek inside try​:

use Data​::Dumper; warn Dumper( \%package​:: );

Rather than mess around with symbol tables\, it seems like the straitforward​:

  exists &{"$package​::$subname"} or defined &{"$package​::$subname"}

(there is a slight difference between the two; see perlfunc) will do what's wanted.

p5pRT commented 19 years ago

From @smpeters

[ysth - Sun Jan 09 15​:26​:29 2005]​:

On Sun\, Jan 09\, 2005 at 07​:22​:39AM -0500\, Randy W. Sims wrote​:

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' );

can() will also check for inherited methods\, which may or may not be what he wants.

You might also take a look at Module​::Info on CPAN. Additionally\, for a peek inside try​:

use Data​::Dumper; warn Dumper( \%package​:: );

Rather than mess around with symbol tables\, it seems like the straitforward​:

exists &\{"$package&#8203;::$subname"\}

or defined &{"$package​::$subname"}

(there is a slight difference between the two; see perlfunc) will do what's wanted.

For a further discussion of using C\<can()>\, take a look at perltoot. perlobj also has some additional examples using UNIVERSAL​::can() directly.

p5pRT commented 19 years ago

@smpeters - Status changed from 'open' to 'resolved'