Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > How to get a listing of module functions

Reply
Thread Tools

How to get a listing of module functions

 
 
Web Surfer
Guest
Posts: n/a
 
      01-29-2004
[This followup was posted to comp.lang.perl.misc]

I know that you can get a listing of all the modules that are installed
in your perl installation by doing something like this :

#!/usr/bin/perl -w

use ExtUtils::Installed;

my $inst = ExtUtils::Installed->new();
my @modules = $inst->modules();

$total = @modules;
print "$total modules detected\n\n";
print join("\n",@modules),"\n";

exit 0;


But, given this list of modules how can you determine the functions that
are "defined" in any one paticular module ?

 
Reply With Quote
 
 
 
 
Ben Morrow
Guest
Posts: n/a
 
      01-29-2004

Web Surfer <(E-Mail Removed)> wrote:
> [This followup was posted to comp.lang.perl.misc]
>
> I know that you can get a listing of all the modules that are installed
> in your perl installation by doing something like this :
>
> #!/usr/bin/perl -w
>
> use ExtUtils::Installed;
>
> my $inst = ExtUtils::Installed->new();
> my @modules = $inst->modules();
>
> $total = @modules;
> print "$total modules detected\n\n";
> print join("\n",@modules),"\n";
>
> exit 0;


Unnecessary.

> But, given this list of modules how can you determine the functions that
> are "defined" in any one paticular module ?


One way is to check the symbol table:

my $module = "Carp";

eval "require $module" or die $@;
{
no strict 'refs';
for (keys %{"${module}::"}) {
print if exists &{"${module}::$_"};
}
}

This won't find functions that are defined in some different package
from the module name.

Ben

--
Every twenty-four hours about 34k children die from the effects of poverty.
Meanwhile, the latest estimate is that 2800 people died on 9/11, so it's like
that image, that ghastly, grey-billowing, double-barrelled fall, repeated
twelve times every day. Full of children. [Iain Banks] http://www.velocityreviews.com/forums/(E-Mail Removed)
 
Reply With Quote
 
 
 
 
Brian McCauley
Guest
Posts: n/a
 
      01-29-2004
Web Surfer <(E-Mail Removed)> writes:

> [This followup was posted to comp.lang.perl.misc]
>
> I know that you can get a listing of all the modules that are installed
> in your perl installation by doing something like this :
>
> #!/usr/bin/perl -w
>
> use ExtUtils::Installed;
>
> my $inst = ExtUtils::Installed->new();
> my @modules = $inst->modules();
>
> $total = @modules;
> print "$total modules detected\n\n";
> print join("\n",@modules),"\n";
>
> exit 0;
>
>
> But, given this list of modules how can you determine the functions that
> are "defined" in any one paticular module ?


You look in the documentation. Why do you think that you could want
to know what functions are defined without knowing what they do?

Are you sure you meant to say "functions" not "packages"?

--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
 
Reply With Quote
 
James Willmore
Guest
Posts: n/a
 
      01-30-2004
On Thu, 29 Jan 2004 11:13:00 -0600, Web Surfer wrote:

<snip>
> But, given this list of modules how can you determine the functions that
> are "defined" in any one paticular module ?


Why? Are you looking for something in particular?

After creating a reference to an object, the reference applies to *only*
that module. So, if you have two modules that have a method that's the
same name, only one will be called.

For example:

use Foo;
use Bar;

my $foo = new Foo;
my $bar = new Bar;

$foo->method(); #calls to Foo::method
$bar->method(); #calls to Bar::method

This *may* not apply if you import the methods into your namespace. In
most cases, AFAIK, Perl will let you know if there's a problem. Or, you
just use a method call like ...

Foo::method();
Bar::method();

But I doubt there are too many situations in which you'll have an issue or
have a need to call methods in this manner.

I said all this because I get the impression that you are trying to avoid
using a method name that's already in use by another module.

If that's not the case, the best bet on seeing what methods are available
in a module is to RTM on the module.

Of course, you *could* fashion a script to read each files of the module
(as listed in the packing list) and search for each instance of 'sub'
But, that will take a long time and, IMHO, it doesn't have any real payoff
in the end.

HTH and please, someone correct me if I'm wrong.

--
Jim

Copyright notice: all code written by the author in this post is
released under the GPL. http://www.gnu.org/licenses/gpl.txt
for more information.

a fortune quote ...
When God endowed human beings with brains, He did not intend to
guarantee them.

 
Reply With Quote
 
Ben Morrow
Guest
Posts: n/a
 
      01-30-2004

(E-Mail Removed) wrote:
> On Thu, 29 Jan 2004 11:13:00 -0600, Web Surfer wrote:
>
> <snip>
> > But, given this list of modules how can you determine the functions that
> > are "defined" in any one paticular module ?

>
> Why? Are you looking for something in particular?
>
> After creating a reference to an object, the reference applies to *only*
> that module. So, if you have two modules that have a method that's the
> same name, only one will be called.


module != package != class.

Modules are not necessarily OO.

> For example:
>
> use Foo;
> use Bar;
>
> my $foo = new Foo;
> my $bar = new Bar;
>
> $foo->method(); #calls to Foo::method
> $bar->method(); #calls to Bar::method
>
> This *may* not apply if you import the methods into your namespace.


You cannot import a method. You import a sub into your namespace.

> In most cases, AFAIK, Perl will let you know if there's a problem.


Nope. You will get the last to be imported.

> Or, you just use a method call like ...
>
> Foo::method();
> Bar::method();


This is not a method call, it is a sub call.

> If that's not the case, the best bet on seeing what methods are available
> in a module is to RTM on the module.


Yes.

Ben

--
Razors pain you / Rivers are damp
Acids stain you / And drugs cause cramp. [Dorothy Parker]
Guns aren't lawful / Nooses give
Gas smells awful / You might as well live. (E-Mail Removed)
 
Reply With Quote
 
Tassilo v. Parseval
Guest
Posts: n/a
 
      01-30-2004
Also sprach Ben Morrow:

> (E-Mail Removed) wrote:


>> After creating a reference to an object, the reference applies to *only*
>> that module. So, if you have two modules that have a method that's the
>> same name, only one will be called.


[...]

>> Or, you just use a method call like ...
>>
>> Foo::method();
>> Bar::method();

>
> This is not a method call, it is a sub call.


I haven't followed this thread very closely, but maybe it's a good time
to mention that also methods can be package qualified:

ethan@ethan:~$ perl -l
package p1;
sub test { print __PACKAGE__ }
package p2;
sub test { print __PACKAGE__ }
package main;
my $o = bless {} => "p1";
$o->test;
$o->p2::test;
__END__
p1
p2

As I said, I am not sure how useful this is in the context of this
thread.

Tassilo
--
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus}) !JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexi ixesixeseg;y~\n~~dddd;eval
 
Reply With Quote
 
James Willmore
Guest
Posts: n/a
 
      01-30-2004
On Fri, 30 Jan 2004 09:56:24 +0000, Ben Morrow wrote:


> (E-Mail Removed) wrote:
>> On Thu, 29 Jan 2004 11:13:00 -0600, Web Surfer wrote:

<snip>

>> After creating a reference to an object, the reference applies to
>> *only* that module. So, if you have two modules that have a method
>> that's the same name, only one will be called.

>
> module != package != class.
>
> Modules are not necessarily OO.
>
>> For example:
>>
>> use Foo;
>> use Bar;
>>
>> my $foo = new Foo;
>> my $bar = new Bar;
>>
>> $foo->method(); #calls to Foo::method $bar->method(); #calls to
>> Bar::method
>>
>> This *may* not apply if you import the methods into your namespace.

>
> You cannot import a method. You import a sub into your namespace.


<snip>

>> Or, you just use a method call like ...
>>
>> Foo::method();
>> Bar::method();

>
> This is not a method call, it is a sub call.


Okay ... I'll go back and read some more.

I get the impression from your post I'm not alone in mixing terms.

--
Jim

Copyright notice: all code written by the author in this post is
released under the GPL. http://www.gnu.org/licenses/gpl.txt
for more information.

a fortune quote ...
Mustgo, n.: Any item of food that has been sitting in the
refrigerator so long it has become a science project. --
Sniglets, "Rich Hall & Friends"
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
ctypes listing dll functions marc.wyburn@googlemail.com Python 1 09-09-2006 06:16 AM
Listing of declared variables and functions ohms377 Python 3 05-11-2005 11:08 AM
Listing functions in a file IN ORDER Ian Sparks Python 6 07-02-2004 02:45 PM
please help me in distinguish redefining functions, overloading functions and overriding functions. Xiangliang Meng C++ 1 06-21-2004 03:11 AM



Advertisments