cons-discuss
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Packages and cons


From: Frank Thomas
Subject: Re: Packages and cons
Date: Wed, 18 Jul 2001 13:07:20 +0200

Hi,

I'd suggest "use Exporter;" instead of "require Exporter;" because it's less overhead.

Bye
        Frank

Am Mittwoch, 18. Juli 2001 um 12:54 schrieb Johan Holmberg:


On Wed, 18 Jul 2001, Frank Thomas wrote:

I would just call "use Cons-subs;" or something similar because this
would not load it again every time but just import the symbols into your
namespace.


I also think this is the right way to go.
Write your "cons_subs.pm" file something like:

#----------------------------------------------------------------------
package cons_subs;

require Exporter;
@ISA = qw(Exporter);
@EXPORT = qw(cons_subs_fun $cons_subs_scalar);

$cons_subs_scalar = "123";

sub cons_subs_fun
{
  # ....
}

1;

#----------------------------------------------------------------------

and add a line:

    use cons_subs;

to every "Construct/Conscript" that needs your module.

I think it is a *good thing* that you explicitly declare what your
Conscript files depends on. As I understand it, one of the original
goals of the Cons design was to avoid the mess you get in when using
"global variables" in an uncontrolled way across different files.

Variables/functions should be shared in a controlled way, and since
"use" is the normal way to do it in Perl, I think it should be used
in Conscript files too.

As far as I  know, the current handling of "Construct/Conscript" in
Cons (where the files are evaluated in the "script" package, and
the package is cleared after every Construct/Conscript file read)
works well together with Perls "use" mechanism.

/Johan Holmberg





reply via email to

[Prev in Thread] Current Thread [Next in Thread]