Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re^8: disable functions if module not installed

by almut (Canon)
on Nov 04, 2008 at 15:29 UTC ( #721423=note: print w/replies, xml ) Need Help??


in reply to Re^7: disable functions if module not installed
in thread disable functions if module not installed

Endless recursion would occur, if constant() is not being found - for whatever reason... Normally, the routine is provided by the XS code, but in case the wrong shared library is being loaded, or the symbol isn't exported properly, or something like that, the call to constant() would be routed to AUTOLOAD itself, leading to the next level of recursion...

Quick proof of concept code:

#!/usr/bin/perl package Image::Magick; sub AUTOLOAD { # This AUTOLOAD is used to 'autoload' constants from the constant( +) # XS function. If a constant is not found then control is passed # to the AUTOLOAD in AutoLoader. my $constname; ($constname = $AUTOLOAD) =~ s/.*:://; print STDERR "$constname "; # DEBUG my $val = constant($constname, @_ ? $_[0] : 0); # the following code from the original sub is irrelevant (never re +ached) #if ($! != 0) { # if ($! =~ /Invalid/) { # $AutoLoader::AUTOLOAD = $AUTOLOAD; # goto &AutoLoader::AUTOLOAD; # } # else { # my($pack,$file,$line) = caller; # die "Your vendor has not defined PerlMagick macro $pack\: +\:$constname, used at $file line $line.\n"; # } #} #eval "sub $AUTOLOAD { $val }"; #goto &$AUTOLOAD; } package main; Image::Magick::not_there(); # starts endless recursion

I'm not sure why lepetitalbert's respective print statement doesn't print anything, but maybe it's just that STDOUT isn't connected to the terminal here, or some such...

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://721423]
help
Chatterbox?
Discipulus DWIWSTM is a Perl7 feature
Discipulus DoWhatIWasSupposed ToMean

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (9)
As of 2017-09-20 15:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    During the recent solar eclipse, I:









    Results (237 votes). Check out past polls.

    Notices?