in reply to Re: Do I have to export all variables and functions from my PM file?
in thread Do I have to export all variables and functions from my PM file?

In fact, it is probably better to make the variables lexical (i.e. 'my' rather than 'our'). The 'our' variables are still accessible using their fully-qualified names. The 'my' variables are not accessible at all from outside the scope that declares them, unless some code in that scope passes them out.

  • Comment on Re^2: Do I have to export all variables and functions from my PM file?

Replies are listed 'Best First'.
Re^3: Do I have to export all variables and functions from my PM file?
by LanX (Saint) on Mar 07, 2022 at 15:51 UTC
    Yes, in general one is better off to
    • always default to private vars with my
    • only use public our when really needed

    But this is not always so, there are always exceptions to the rule.

    Some modules use package vars for external config, e.g. Text::Glob or Data::Dumper °

    Some even export readonly vars to be used as constants (instead of barewords without sigils)

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery

    °) of course TIMTOWTDI, these design patterns date back to the Perl4 times, which had neither OOP nor private lexical vars. Data::Dumper for instance has a dual API.

Re^3: Do I have to export all variables and functions from my PM file?
by Anonymous Monk on Mar 08, 2022 at 10:15 UTC
    The 'my' variables are not accessible at all from outside the scope that declares them, unless some code in that scope passes them out.

    PadWalker