in reply to Re: How do I make one package use a module from another package?
in thread How do I make one package use a module from another package?

It's a lot harder if you require the code to work. -- to you for no disclaimer.

--Bob Niederman, http://bob-n.com
  • Comment on Re: Re: How do I make one package use a module from another package?

Replies are listed 'Best First'.
Re: Re: Re: How do I make one package use a module from another package?
by jryan (Vicar) on Jul 23, 2003 at 01:46 UTC

    Excuse me, that should have been (caller)[0]. However, -- to you for condemning the code without understanding that it was essentially correct sans a typo.

    The code I provided is the code that you want to use in this situation.

      The code I provided is the code that you want to use in this situation.

      No the code you initially provided was broken in multiple ways.

      Once you "fixed" it, it exported. This is interesting, and it's worth understanding how you did it, so I'm glad you made that contributuion. (I still think it's a really bad idea for reasons stated elsewhere.)

      Also, even "fixed", its "use strict" and "use warnings" still have no effect, which is expected from an understanding that these pragma apply lexically.

      I often test code before I post it here. If I don't test it, I usually manage to remember to say "untested" somewhere, in a noticeable fashion. I think doing one of those 2 things is important. But I may have been "over the top" in my previous.

      --Bob Niederman, http://bob-n.com

        The code was not broken in several ways. It was broken in a single way; it referenced (caller)[1], the calling program name, rather than (caller)[0], the calling package name. As I said before, it was a mistype. I'm sorry to have caused you so much anger over it.

        The pragmas do export lexically, this is correct. You are also correct in saying that my module doesn't import them into the current lexical scope. It imports them into the current package scope. However, based on inferences from the AM poster (and conversations that I had with his non-AM identity later), he wasn't interested in the lexical behaivor of strict. He was interested in binding several modules together in a single use statement, which is really only possible with Perl5 by using the technique above, short of XS. So, in this case, you are correct in that my solution is not perfect, but then there is no perfect solution to this scenerio.

        As to whether the "use strict" and "use warnings" importation works, I *REALLY* suggest you try an example. Really. It does work. If you need help writing a test case, I can assist you.

        I normally do test code, but I was in a meeting and didn't have time to. I only posted because I was sure of the solution, and that I had noticed almost a dozen incorrect or unhelpful posts in the thread. Unfortunately, I made a mistake in typing the solution, and so here we are.