cons-discuss
[Top][All Lists]
Advanced

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

Re: Perl function in a Command method


From: Steven Knight
Subject: Re: Perl function in a Command method
Date: Wed, 22 Nov 2000 13:48:27 -0600 (CST)

On Wed, 22 Nov 2000, Gary Oberbrunner wrote:
> >>>>> "ZD" == Zachary Deretsky <address@hidden> writes:
>   ZD> Is there a way to call a perl subroutine defined in the same
>   ZD> Conscript file from a command method?
> 
> Funny you should ask; I have a patch for this also.  You just put
> [perl] in the front of your command, then it's executed directly in
> your perl.  Hope it's not too obnoxious to send it to the whole list.

For the record, Gary's patch is what was integrated into the latest
checked-in version (soon to be blessed and released as 2.2.0, actually).

> *HOWEVER*, there are some issues regarding name spaces with this kind
> of thing (same kind of thing happens with perl code in QuickScans).
> Cons reads each Conscript into the "script" package, after deleting
> all vars from that package (to clear cruft left around in other
> Conscripts).  This makes it more difficult to refer to variables in
> the Conscript.  Specifically, you can't refer to the cons
> environments: they're gone by the time commands are run.  I've been
> kicking around some ideas about putting each Conscript into its *own*
> package rather than reusing "script" each time, but I don't really
> know what kinds of issues this would create.  (Anyone else but me care
> about this?)

Actually, yes.  Johan Holmberg sent in a patch that put each Conscript
in its own package, just like you describe.  Unfortunately, it broke some
existing Conscripts at FORE/Marconi which were using subsidiary packages
that had specific knowledge that Conscripts were executed in the "script"
package.  So we had to get creative to try to satisfy both requirements.

Consequently, the 2.2.0 version solves this problem in a different way.
Instead of wiping out the package variables after each Conscript, it has
logic to save-restore the variables from the "script" package namespace
as needed, using typeglobs in a friendlier way than the previous code.

Upshot: Gary's "perl" patch as integrated in 2.2.0 can execute code that
uses all the variables and subroutines in force when the Conscript file
was finished being processed.  And it does this while they're all still
in the "script" package, so (if you really want to you) you can pull
in external code that knows how to manipulate values in that namespace.

        --SK




reply via email to

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