Hi Zapp,

On Thu, 12 Apr 2012 18:29:09 +0800
Zapp <zapp.pref...@gmail.com> wrote:

> I had try it, codes is here:
> 
> #!/usr/local/bin/perl -w
> 
> use Class::Inspector;
> use IO::File;
> 
> my @methods = Class::Inspector->methods('IO::File', 'full', 'public');
> 
> print "@methods";
> 
> but it Only print this: ARRAY(0xaa4bc8)
> Why?

I tried this code (a somewhat more idiomatic and safer version of yours in the
debugger):

[CODE]

#!/usr/bin/perl

use strict;
use warnings;

use Class::Inspector;
use IO::File;

my @methods = Class::Inspector->methods('IO::File', 'full', 'public');

print "@methods\n";

[/CODE]

shlomif@lap:~$ perl -d Test-Class-Inspector.pl

Loading DB routines from perl5db.pl version 1.33
Editor support available.

Enter h or `h h' for help, or `man perldebug' for more help.

main::(Test-Class-Inspector.pl:9):
9:      my @methods = Class::Inspector->methods('IO::File', 'full', 'public');
  DB<2881> n
main::(Test-Class-Inspector.pl:11):
11:     print "@methods\n";
  DB<2881> x @methods
0  ARRAY(0x15bf5c0)
   0  'IO::Handle::DESTROY'
   1  'IO::File::O_ACCMODE'
   2  'IO::File::O_APPEND'
   3  'IO::File::O_ASYNC'
   4  'IO::File::O_BINARY'
   5  'IO::File::O_CREAT'
   6  'IO::File::O_DIRECT'
   7  'IO::File::O_DIRECTORY'
   8  'IO::File::O_DSYNC'
   9  'IO::File::O_EXCL'
[SNIP]

Apparently Class::Inspector always returns a single array reference (including
in list context) that contains the list of all the methods (some of which
appear to be plain subroutines) and so the example given in the Stack Overflow
post was misleading.

For more information see:

http://perl-begin.org/topics/references/

This made me thinking that maybe we should write a comprehensive online guide
on troubleshooting Perl code and potential pitfalls/errors/warnings.

Regards,

        Shlomi Fish 
> 
> 于 2012-4-11 20:34, Shlomi Fish 写道:
> > Hi Zapp,
> >
> > On Wed, 11 Apr 2012 16:12:22 +0800
> > Zapp<zapp.pref...@gmail.com>  wrote:
> >
> >> How Can I find all kinds of methods a Object support?
> >> For example:
> >>
> >> my $fh = IO::File->new("/path/to/file");
> >>
> >> how manny kinds of methods does the $fh have ?
> >>
> >> I try perldoc IO::File , but didn't find what I want.
> >>
> > See:
> >
> > http://stackoverflow.com/questions/910430/how-do-i-list-available-methods-on-a-given-object-or-package-in-perl
> >
> > The best answer there, in my humble opinion, is to use the Class::Inspector
> > CPAN module:
> >
> > my @methods = Class::Inspector->methods( 'Foo::Class', 'full', 'public' );
> >
> > Regards,
> >
> >     Shlomi Fish
> >
> 



-- 
-----------------------------------------------------------------
Shlomi Fish       http://www.shlomifish.org/
The Case for File Swapping - http://shlom.in/file-swap

We have nothing to fear but fear itself. Fear has nothing to fear but XSLT.

Please reply to list if it's a mailing list post - http://shlom.in/reply .

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to