use/require handler?

  • Thread starter Patrick LeBoutillier
  • Start date
P

Patrick LeBoutillier

Hi all,

Is there anyway to be notified when the use/require of a module fails?

Basically I would like to setup a sub that gets called whenever a
use/require call doesn't find what it is looking for. Sort of an
AUTOLOAD but for use/require.

Any ideas?

Patrick LeBoutillier
 
G

Gunnar Hjalmarsson

Patrick said:
Is there anyway to be notified when the use/require of a module
fails?

Basically I would like to setup a sub that gets called whenever a
use/require call doesn't find what it is looking for. Sort of an
AUTOLOAD but for use/require.

Any ideas?

eval "use Some::Module";
mysub() if $@;
 
P

Patrick LeBoutillier

Gunnar Hjalmarsson said:
eval "use Some::Module";
mysub() if $@;

That's good, but I would like this to happen transparently behind the scenes, i.e.:

BEGIN {
# Hook up the sub "no_such_module" to be called when use/require
# fails
}


use IO::File ; # nothing happens
use File::Find ; # nothing happens
use Absent::Module # "no_such_module" called with arg "Absent::Module" ;

sub no_such_module {
my $module = shift ;

warn("Module $module not found.") ;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top