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

Discussion in 'Perl Misc' started by Rainer Weikusat, Sep 24, 2012.

  1. bugbear <bugbear@trim_papermule.co.uk_trim> writes:
    > 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" ?


    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.
     
    Rainer Weikusat, Sep 24, 2012
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. sachin
    Replies:
    1
    Views:
    356
    Tjerk Wolterink
    Dec 1, 2005
  2. Merciadri Luca
    Replies:
    4
    Views:
    828
  3. Jim Cain
    Replies:
    7
    Views:
    148
    Brian Candler
    Jul 18, 2003
  4. Steven D'Aprano
    Replies:
    0
    Views:
    105
    Steven D'Aprano
    Dec 23, 2013
  5. Replies:
    3
    Views:
    92
    Gary Herron
    Dec 23, 2013
Loading...

Share This Page