in reply to Using sub routines or AUTOLOAD for XS constants
If you're getting the error message "can't locate exported subroutine $name via $class" from Sub::Exporter's default_generator(), the best option is to override can() in your package when you use AUTOLOAD(). That's a good practice anyway, though.
I haven't tested this code, but something like this should work:
sub can { my ($class, $name) = @_; return if $name eq 'constant'; my ($error, $val) = constant($name); return if $error; my $sub = sub () { $val }; { no strict 'refs'; *{ $class . '::' . $name } = $sub; } return $sub; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Using sub routines or AUTOLOAD for XS constants
by ikegami (Patriarch) on Jan 01, 2010 at 22:23 UTC | |
by chromatic (Archbishop) on Jan 02, 2010 at 10:25 UTC | |
by ikegami (Patriarch) on Jan 02, 2010 at 19:55 UTC | |
|
Re^2: Using sub routines or AUTOLOAD for XS constants
by aflott (Beadle) on Jan 01, 2010 at 20:54 UTC |