Yeah, you can require libraries whenever you want as long as you don't use pieces of them before they've bene loaded. Here's an example from the middle of a program I was looking at yesterday:
eval { require Mail::Box::Manager; };
die "You need to install the Mail::Box module, exiting" if $!;
You could even, if you were a meanie (or awesome), replace the "die" with something like "CPAN::Shell->install("Your::Module::Here");". I can't see that causing any problems whatsoever. 8)
I think what I'd do, were I doing something like this, would be to create a config file (or a flag) that specifies an interface and then switch off of that somewhere early-on. In the block for each interface, require() the appropriate module (and die if it's not there, and maybe even fail gracefully to the bare minimum interface) and then include another file with the function definitions for that type of interface. That's not very OO of me, I guess, but OO is for jerks and stuff.
Mmm. What I am wondering is not so much if it can be done as whether there is a cleaner way, what the accepted idiom is. But Googling suggests this is as good as any.
(no subject)
eval { require Mail::Box::Manager; }; die "You need to install the Mail::Box module, exiting" if $!;You could even, if you were a meanie (or awesome), replace the "die" with something like "CPAN::Shell->install("Your::Module::Here");". I can't see that causing any problems whatsoever. 8)
I think what I'd do, were I doing something like this, would be to create a config file (or a flag) that specifies an interface and then switch off of that somewhere early-on. In the block for each interface, require() the appropriate module (and die if it's not there, and maybe even fail gracefully to the bare minimum interface) and then include another file with the function definitions for that type of interface. That's not very OO of me, I guess, but OO is for jerks and stuff.
There are probably cleaner ways to do it...
(no subject)