I'm developing a package that can be used with tied variables, but can't seem to make autoloading work on the tie routines (TIEWHATSIT, FETCH, STORE...).
As long as I keep these routines ahead of the __END__ statement my tests work well, but when I put them after, perl complains that it can't find them. My package contains the following AUTOLOAD routine:
our $AUTOLOAD;
sub AUTOLOAD {
# this 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/.*:://;
croak "& not defined" if $constname eq 'constant';
my $val = constant($constname, @_ ? $_[0] : 0);
if ($! != 0) {
if ($! =~ /Invalid/ || $!{EINVAL}) {
$AutoLoader::AUTOLOAD = $AUTOLOAD;
goto &AutoLoader::AUTOLOAD;
} else {
croak "Your vendor has not defined MMA macro $constname";
} }
eval "sub $AUTOLOAD { $val }";
goto &$AUTOLOAD;
}
Also things seem to work the same whether there's a
require AutoLoader or
use AutoLoader near the start of my package.
The routine above is slightly different than the one shown on
the perl.org Autoloader page. When I tried to edit mine to be exactly like the one on the perl.org page, big trouble broke loose, with complaints about constants not being allowed to be used under strict (and such). Of course I may have edited the routine imperfectly.
My Makefile.PL file uses ExtUtils::MakeMaker, and the right things seem to happen during make, like splitting into the right .al files.
Is there anything incompatible between tie subroutines and autoloading? If not, how should I proceed toward making autoloading work?
cmac
www.animalhead.com
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.