print <<'ESQ';
);
# Generate proxy constant subroutines for all the values.
- # We assume at this point that our symbol table is empty.
+ # Well, almost all the values. Unfortunately we can't assume that at this
+ # point that our symbol table is empty, as code such as if the parser has
+ # seen code such as C<exists &Errno::EINVAL>, it will have created the
+ # typeglob.
# Doing this before defining @EXPORT_OK etc means that even if a platform is
# crazy enough to define EXPORT_OK as an error constant, everything will
# still work, because the parser will upgrade the PCS to a real typeglob.
# We rely on the subroutine definitions below to update the internal caches.
# Don't use %each, as we don't want a copy of the value.
foreach my $name (keys %err) {
- $Errno::{$name} = \$err{$name};
+ if ($Errno::{$name}) {
+ # We expect this to be reached fairly rarely, so take an approach
+ # which uses the least compile time effort in the common case:
+ eval "sub $name() { $err{$name} }; 1" or die $@;
+ } else {
+ $Errno::{$name} = \$err{$name};
+ }
}
}
#!./perl -w
-use Test::More tests => 10;
+use Test::More tests => 12;
+
+# Keep this before the use Errno.
+my $has_einval = exists &Errno::EINVAL;
BEGIN {
use_ok("Errno");
# through Acme::MetaSyntactic::batman
is($!{EFLRBBB}, "");
ok(! exists($!{EFLRBBB}));
+
+SKIP: {
+ skip("Errno does not have EINVAL", 1)
+ unless grep {$_ eq 'EINVAL'} @Errno::EXPORT_OK;
+ is($has_einval, 1,
+ 'exists &Errno::EINVAL compiled before Errno is loaded works fine');
+}
+
+SKIP: {
+ skip("Errno does not have EBADF", 1)
+ unless grep {$_ eq 'EBADF'} @Errno::EXPORT_OK;
+ is(exists &Errno::EBADF, 1,
+ 'exists &Errno::EBADF compiled after Errno is loaded works fine');
+}