caver has asked for the wisdom of the Perl Monks concerning the following question:

General question:
Does anyone know of a location I can go to find out
what methods are available in a particular module?
Specific problem:
I am trying to put debug statements to find out what
i did wrong in a module called
user_manage
I looked at CPAN under HTTPD::RealmManager user_manage
but could not decifer it???

I am looking for a method that will return a value
telling me what GROUP a particular username is in.

How can I tell if one already exists, or if I need to code something myself?
I am obviously new to oo programming...

Thanks,

Daniel

  • Comment on oo programming-how do I find existing methods?

Replies are listed 'Best First'.
(tye)Re: oo programming-how do I find existing methods?
by tye (Sage) on Dec 05, 2001 at 04:58 UTC

    In the Perl debugger, the "m" command lists the available methods, including following @ISA and showing you XS routines that are not apparent in the *.pm source code.

    Update: For your specific question, it appears that the group() method is what you want. However, a user can belong to more than one group. If you can't deal with more than one group, then you might want to just deal with the first group name returned:

    my $group= ( $db->group( -user => $user ) )[0]; # or my( $group )= $db->group( -user => $user );

            - tye (but my friends call me "Tye")
Listen To PDP-1 Kenobi (was Re: oo programming-how do I find existing methods?)
by chip (Curate) on Dec 05, 2001 at 04:46 UTC
    Use The Source, Luke.

        -- Chip Salzenberg, Free-Floating Agent of Chaos

      To expand on chip's point, perldoc has the handy '-m' switch which lists the entire module as found by perl in @INC.

      $ perldoc -m HTTPD::RealmManager # paged listing follows
      Look at @EXPORT and @EXPORT_OK near the top for names. If your $ENV{'PAGER'} supports searching, you can go directly to the definition you want.

      su

      After Compline,
      Zaxo

Re: oo programming-how do I find existing methods?
by Fastolfe (Vicar) on Dec 05, 2001 at 05:00 UTC
    The UNIVERSAL 'can' method should tell you this. From perlobj:
    Sometimes you want to call a method when you don't know the method name ahead of time. You can use the arrow form, replacing the method name with a simple scalar variable containing the method name or a reference to the function. $method = $fast ? "findfirst" : "findbest"; $fred->$method(@args); # call by name if ($coderef = $fred->can($parent . "::findbest")) { $self->$coderef(@args); # call by coderef }
    Basically:
    $obj->method(1, 2, 3); # general case if ($obj->can('method')) { print "Yep, \$obj has a method named 'method'\n"; } if ($sub = $obj->can('method')) { $sub->($obj, 1, 2, 3); # same effect as general case }
Re: oo programming-how do I find existing methods?
by runrig (Abbot) on Dec 05, 2001 at 04:48 UTC
    Take a look at this to get an idea of how to tell what subroutines are in a package. Then you'll have to recursively search the package's @ISA and see what method's are inherited from other packages. But even that won't include methods which are AUTOLOAD'ed in a package.

    Or just do like chip says, and just look. Duh :-)