exporting methods when than one package in a file?

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I am building a small object oriented class set; most of the methods
apply to an instance, and I can handle these OK.

However, some of the classes supply class (or global) functions.

Since none of the classes are large, I would like the whole
class set to be in a single file.

Question; what is the best way that I can:

* make sure each global function is available throughout
the source file?

* export (EXPORT!) all the global functions
when the class set is "used" ?


Re: exporting methods when than one package in a file?

Quoted text here. Click to load it

You could add them all to the @EXPORT array. But if they're really
'class methods' I think you should be calling them like class methods,
that is, by either using an object of the proper class or the name of
it on the left side of a ->. When a subroutine is exported, what
really happens is that the coderef currently assigned to the
subroutine slot of the glob in question is assigned to the subroutine
slot of another glob. But since Perl is a dynamic language the
association between the original glob and the original coderef isn't
necessarily permanent: Any method could redefine any other method by
assigning a different coderef to the corresponding glob and such
changes will become visible to users of the class when they use
proper method calls to invoke methods but not if they import methods
as subroutines instead.

Site Timeline