[Pdx-pm] how to specify an interface in a .pm file

Chris Dawson cdawson at webiphany.com
Mon Jan 19 01:07:52 CST 2004

Hi there,

I have a software package to which I want to allow third-party library 
upgrades.  By this I mean I want to allow people to upload .pm files 
which implement a certain API interface and then use those .pm files in 
my software package.  I think I am clear about how I dynamically load 
the .pm files, by using an eval once I have retrieved the filename.  
But, I am unclear how I would query a .pm file to determine what 
subroutines are defined, without calling into them.  I am comfortable 
requiring that people provide me with function prototypes, although 
definitely unclear as to how exactly to specify these in the module, and 
even if this gets me closer to a solution.  Does anyone have any 
suggestions, preferably with sample code?

If it wasn't clear, here is some code:

(My API requires these two functions: get_description and process)

package Plugin;
sub process( $$ );
sub process { 1; }
sub get_description( $ );
sub get_description { 1; }

How do I query Plugin.pm and determine if it has both process and 
get_description?  Also, is there a way to not specify "package Plugin;" 
at the top of every file, since in this case it is somewhat redundant as 
the filename is the same.  perl doesn't appear to recognize it as a 
package unless you do this. 

I guess I could use grep, but I would like to understand better how all 
of this works in perl, since it is clear how I would do this using 
function pointers and DLLs with c/c++.


More information about the Pdx-pm-list mailing list