I don't understand what you are trying to achieve here. What the code
above will actually do is: any code compiled in package 'main' after the
BEGIN block runs, that calls 'exit' or 'exec', will call your custom
subs instead. Is that what you meant?
I have no package explicitely named 'main',
so obviously I have misunderstood something
you wrote earlier.
Now, this makes indeed the 'redefine' errors
'self-explanatory' as you say.
Or... maybe not quite. I understood I was
redefining the meaning of a global 'exec'
in different package contexts.
(Exporting into a specific package
like that is usually a very mad idea.
What if your caller isn't main::
but some other package?)
Sorry, but what is 'main'? Is there a main?
In C, there is a 'main' symbol. It is
garanteed to be unique, in the context of
every program. This is what I understood.
In fact, I would still believe this is OK.
So, it is now that I must be misunderstanding
you...
At least I don't get errors mentioning
'*main::'...
I am writing a wrapper for a command line
tool, so my caller will be 'main'...
The caller is the 'cleartool.plx' script.
When you say 'member' you mean 'method', or perhaps 'function'? Method
calls to ClearCase::Argv->exec won't be affected. Calls to 'exit' or
'exec' from within the ClearCase::Argv package won't be affected, they
will call the builtin as usual.
'Method' is the word Smalltalk used.
'Member' (function) is the word for C++.
'Function' is the C word for something
slightly different (but called 'procedure'
in Fortran). OK, there are functions in Lisp
as well, and there are significant
differences... The terminology is very
confusing. By member, I mean a function
in the restricted namespace of a class
(aka package). In addition, I assume that it
takes a first (syntactically implicit)
argument being a reference to an instance
of the class. This aspect is irrelevant here.
Overrides of builtins must be imported while in another package, in an
attempt to stop you doing it accidentally. That is,
package Foo;
*main::exec = sub {...};
will be recognized as an override while in package main, but
package main;
*exec = sub {...};
won't. Since I presume your module starts with
package ClearCase::Argv;
you shouldn't need another package statement inside the BEGIN block.
I have:
- a toplevl script: cleartool.plx (the wrapper)
- a ClearCase::Wrapper module, which does
define some functions, and use exit and exec
in ways I want to override
- a ClearCase::Argv module, which is used to
implement the functions, and offers one 'exec'
among other, which itself uses exit, in a way
which I want to override
- two specialized wrapper modules:
- ClearCase::Wrapper:
SB which defines more
functions (among which the 'des' which I use
in my tests), and does use exit and exec in
ways I want to override.
- ClearCase::Wrapper::MGI of which I am the
author, and thus does *not* use exit nor
exec .
These two modules are 'discovered' dynamically
and loaded by ClearCase::Wrapper.
There could in theory be more of them.
So, my understanding is that I must override
exec and exit in at least 3 packages:
ClearCase::Argv
ClearCase::Wrapper
ClearCase::Wrapper:
SB
(and probably in a 4th one: Argv, which is used
by ClearCase::Argv).
Where do I do this, and how do I prefix the
2 names?
So far, I thought the functions I was overriding
were global main:: functions, and I had to do it
*in* every package.
Obviously, this was wrong...
Thanks
Marc