in reply to autoloading tie routines
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: autoloading tie routines
by cmac (Monk) on Feb 02, 2009 at 08:46 UTC | |
by cmac (Monk) on Feb 02, 2009 at 09:46 UTC | |
by ysth (Canon) on Feb 03, 2009 at 01:21 UTC | |
by ysth (Canon) on Feb 03, 2009 at 01:24 UTC |