On Wed, 28 May 2008, Chris Lewis wrote:

I'm trying to implement a subroutine shared between plugins.

The library routine looks something like:

sub createpattern {}

It needs to be exported from your library, or called with a full package name, how are you doing that?

The most common way is to use Exporter - see the Exporter man page for details.

And is stored under ../qpsmtpd/lib/NTMqplib.pm

qpsmtpd-async is called from the qpsmtpd directory.

Each plugin then calls it thusly:

use NTMqplib;

sub register ... {

    ... = &createpattern(...)

Note that the & in front is a nasty perl4-ism and tends to be frowned upon by other perl coders these days - fine if you're the only one maintaining your script, but will look ugly if someone ever takes over...

What happens is that the first plugin executed works fine, and the next one errors out saying it can't find createpattern().

Looks like the first plugin executed loads the library, and remembers it's loaded. The second one thinks it's loaded, but the symbol table (or whatever) isn't in scope, or some such.

How do you do this properly?

Sounds like you're probably just trying to put it into the current namespace. Keep it in it's own namespace (i.e. have "package NTMqplib;" in your .pm file) and use Exporter, or call it as NTMqplib::createpattern()

Matt.

Reply via email to