Can perl modules RECIPROCALLY "use" one another?

Can perl modules RECIPROCALLY "use" one another?

am 29.06.2005 16:17:50 von unknown

Post removed (X-No-Archive: yes)

Re: Can perl modules RECIPROCALLY "use" one another?

am 29.06.2005 16:35:43 von Gunnar Hjalmarsson

Ignoramus4093 wrote:
> Can I have a perl module
>
> package A;
> use B;
>
>
> and another module
>
> package B;
> use A;
>
>
> would they be able to call one another's subroutines?

Yes.

(What happened when you tried it?...)

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

Re: Can perl modules RECIPROCALLY "use" one another?

am 29.06.2005 17:15:30 von unknown

Post removed (X-No-Archive: yes)

Re: Can perl modules RECIPROCALLY "use" one another?

am 29.06.2005 17:39:08 von Peter Scott

On Wed, 29 Jun 2005 14:17:50 +0000, Ignoramus4093 wrote:

> Can I have a perl module
>
> package A;
> use B;
>
>
> and another module
>
> package B;
> use A;
>
>
> would they be able to call one another's subroutines?

If both export subroutines, the second module won't get the first one's
names exported because %INC has already been set when the first one was
loaded. This is a known problem. It's not hard to write an example.

> And if that's not the case, how would I implement a similar pattern?

The general consensus is to not do cyclic dependencies between
exporting modules. If you must, call the other module's routines
with package-qualified names.

--
Peter Scott
http://www.perlmedic.com/
http://www.perldebugged.com/

Re: Can perl modules RECIPROCALLY "use" one another?

am 29.06.2005 17:51:10 von unknown

Post removed (X-No-Archive: yes)

Re: Can perl modules RECIPROCALLY "use" one another?

am 29.06.2005 22:11:18 von Brian McCauley

Peter Scott wrote:

> On Wed, 29 Jun 2005 14:17:50 +0000, Ignoramus4093 wrote:
>
>>Can I have a perl module
>>
>>package A;
>>use B;
>>
>>and another module
>>
>>package B;
>>use A;
>>
>>would they be able to call one another's subroutines?
>
> If both export subroutines, the second module won't get the first one's
> names exported because %INC has already been set when the first one was
> loaded. This is a known problem. It's not hard to write an example.
>
> The general consensus is to not do cyclic dependencies between
> exporting modules. If you must, call the other module's routines
> with package-qualified names.

Whilst I agree that cyclic dependancies are best avoided, it is not
necessary to fully qualify names. It is sufficient to assign @EXPORT
inside a BEGIN block.

BEGIN { our @EXPORT = qw( all those functions ) }

Re: Can perl modules RECIPROCALLY "use" one another?

am 02.07.2005 02:59:29 von Big and Blue

>Ignoramus4093 wrote:

>>>Can I have a perl module
>>>
>>>package A;
>>>use B;
>>>
>>>
>>>and another module
>>>
>>>package B;
>>>use A;
>>
>>(What happened when you tried it?...)
>
> I tried it inside mod_perl, and had all kinds of errors "subroutine
> not defined", even though these subs were indeed defined.

If you really called them A and B then you may well have had a problem
because Perl already has a B module, which may well have been found ahead
of yours.




--
Just because I've written it doesn't mean that
either you or I have to believe it.