Public Scratchpad | Download, Select Code To D/L |
1) AUTOLOAD subroutine from Time::Hires.pm
2) What i typed
3) The error message i got
I'm new to Autoloading and i face with a problem which i'd like to solve on my own.
I read the documentation of various things including AutoLoader module, UNIVERSAL class, and others but i still don't understand where constant subroutine comes from.
What i understand is that AUTOLOAD is executed when location of a subroutine failed that's to say the symbol name isn't in the stash %::.
Here, i believe $constname contains this unfound symbol because of the affectation :
($constant = $AUTOLOAD) =~ s/.*:://;
I believe constant($constname) is responsible of this error message as perldiag doesn't describe a similar compilation failure.
1) -- from Time::HiRes.pm :
2) --- what i did :sub AUTOLOAD { my $constname; ($constname = $AUTOLOAD) =~ s/.*:://; die "&Time::HiRes::constant not defined" if $constname eq 'constan +t'; my ($error, $val) = constant($constname); if ($error) { die $error; } { no strict 'refs'; *$AUTOLOAD = sub { $val }; } goto &$AUTOLOAD; }
# perl -MTime::HiRes -e 1
3) --- what i get : ( i deleted what @INC contains in the output )
Can't locate loadable object for module Time::HiRes in @INC (@INC contains: ... ) at -e line 0
Compilation failed in require. BEGIN failed--compilation aborted.