Here's a complete working example:
package Foo; use strict; use warnings; use Errno "EINVAL"; use Tie::Scalar; use AutoLoader; use Carp; sub constant { $!=EINVAL() } 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; } 1; __END__ sub TIESCALAR { goto &Tie::StdScalar::TIESCALAR } sub FETCH { goto &Tie::StdScalar::FETCH } sub STORE { goto &Tie::StdScalar::STORE }
$ perl -wle'use Foo; tie $x, "Foo"; $x="42"; print $x; print for grep +/auto/, values %INC' 42 auto/Foo/autosplit.ix ./auto/Foo/STORE.al ./auto/Foo/TIESCALAR.al ./auto/Foo/FETCH.al
In reply to Re: autoloading tie routines
by ysth
in thread autoloading tie routines
by cmac
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |