473,387 Members | 1,391 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

use/require handler?

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
Jul 19 '05 #1
4 2485
Patrick LeBoutillier wrote:
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 $@;

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

Jul 19 '05 #2
Gunnar Hjalmarsson <no*****@gunnar.cc> wrote in message news:<bs********************@newsb.telia.net>...
Patrick LeBoutillier wrote:
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 $@;


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.") ;
}
Jul 19 '05 #3
Gunnar Hjalmarsson <no*****@gunnar.cc> wrote in message news:<bs********************@newsb.telia.net>...
Patrick LeBoutillier wrote:
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 $@;


Never mind. I found it here:

http://www.perldoc.com/perl5.8.0/pod/func/require.html

It's new in perl 5.8.0:

push @INC, \&my_sub;
sub my_sub {
my ($coderef, $filename) = @_; # $coderef is \&my_sub
...
}
Jul 19 '05 #4
Patrick LeBoutillier wrote:
Never mind. I found it here:

http://www.perldoc.com/perl5.8.0/pod/func/require.html

It's new in perl 5.8.0:

push @INC, \&my_sub;
sub my_sub {
my ($coderef, $filename) = @_; # $coderef is \&my_sub
...
}


Hmm.. Interesting possibility that I was not aware of. Thanks for the
tip. :)

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

Jul 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: steffen staehle | last post by:
Hi, I'm writing a server process which spawns child processes via fork This server process should keep track of the number of children stil running, do the necessary cleanup to avoid zombies,...
13
by: aundro | last post by:
Hello, I've been looking on the web for a solution to this problem: I create a set of checkboxes, and 2 buttons: - one is labeled "All" - the other is labeled "None" Clicking "All" is...
1
by: Tony Riv | last post by:
When Whidbey is released, will I be able to use ASP.NET on an NT server? I heard rumours that it doesnt require IIS and there may be a module for Apache to run ASP.NET I wish microsoft had...
10
by: Wylbur via DotNetMonster.com | last post by:
Hello to all of you geniuses, I'm having a problem trying to get an Init handler to fire for a Placeholder control at the initialization phase. I’ve posted this problem to 3 other ASP.NET...
7
by: Matthew Crouch | last post by:
I'm building a site hosted on Yahoo, and apparently they've got it set so that nothing -- not even fatal errors -- are displayed. I also have an extremely complicated line of code:...
10
by: Sean Dockery | last post by:
I have the following HTML file that I've been using for testing... <html> <head> <script type="text/javascript"> <!-- function handleWindowLoad() { var items = ; for (var i = 0; i < 11; i++)...
4
by: Peter Rilling | last post by:
I am creating a website that uses Forms Authentication. From what I have read, FA uses cookies to store the authentication ticket once logged in. My customer would also like this site to not...
3
by: Alexander Fischer | last post by:
Hi all, sorry for the Newie question: is it possible to require variables in PHP to be defined by the author? I'm used to this from C, and like this "strict" behavior, as otherwise very easily...
6
by: =?Utf-8?B?cHJhZGVlcF9UUA==?= | last post by:
I am trying to create a simple HTTP handler in ASP.net 2.0. I am using VS 2005. I am trying to handle a custom extension file givein in the URL. I have also created the following entry in the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.