Can perl modules RECIPROCALLY "use" one another?
am 29.06.2005 16:17:50 von unknownPost removed (X-No-Archive: yes)
Post removed (X-No-Archive: yes)
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
Post removed (X-No-Archive: yes)
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/
Post removed (X-No-Archive: yes)
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 ) }
>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.