vitoco has asked for the wisdom of the Perl Monks concerning the following question:
I want to use a module M from another module X, only if the calling program P currently uses it.
I have the following test case that works, but X asumes that P uses M:
P.pl:
#!perl use strict; use warnings; use M; use X; hello("world"); bye();
M.pm:
package M; require Exporter; @ISA = (Exporter); @EXPORT = qw(hello); use warnings; use strict; sub hello { print "Hello @_!\n"; }
X.pm:
package X; require Exporter; @ISA = (Exporter); @EXPORT = qw(bye); use warnings; use strict; sub bye { M::hello("again"); # if exists M:hello(); print "That's all, folks!\n"; }
What should be checked in X to recognize that M is loaded and available? If it's not, do nothing!
BTW, in real life, M could be any CPAN's module.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Use a module only if it is in use
by almut (Canon) on Sep 02, 2009 at 14:45 UTC | |
by vitoco (Hermit) on Sep 02, 2009 at 14:57 UTC | |
by ikegami (Patriarch) on Sep 02, 2009 at 15:13 UTC | |
|
Re: Use module only if it is in use
by ikegami (Patriarch) on Sep 02, 2009 at 14:27 UTC | |
by vitoco (Hermit) on Sep 02, 2009 at 14:50 UTC | |
by JavaFan (Canon) on Sep 02, 2009 at 15:56 UTC | |
by bart (Canon) on Sep 02, 2009 at 18:32 UTC | |
by ikegami (Patriarch) on Sep 02, 2009 at 19:29 UTC | |
by ikegami (Patriarch) on Sep 02, 2009 at 16:08 UTC | |
by vitoco (Hermit) on Sep 02, 2009 at 16:08 UTC | |
by ikegami (Patriarch) on Sep 02, 2009 at 15:20 UTC | |
by vitoco (Hermit) on Sep 02, 2009 at 15:47 UTC | |
by ikegami (Patriarch) on Sep 02, 2009 at 16:13 UTC | |
|