diff options
author | Nicholas Clark <nick@ccl4.org> | 2009-08-17 13:15:58 +0100 |
---|---|---|
committer | Nicholas Clark <nick@ccl4.org> | 2009-08-18 07:26:14 +0100 |
commit | c5764f70840f5068e5ce459d0b23d3afa4eb65de (patch) | |
tree | 3726d6447d3570e2e1b662ff1c72d69c05015cf1 | |
parent | 672c0ce9f4737708d6146bebe978c334c9647c4d (diff) | |
download | perl-c5764f70840f5068e5ce459d0b23d3afa4eb65de.tar.gz |
Convert perl version check in import() from run time to compile time.
-rw-r--r-- | lib/constant.pm | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/lib/constant.pm b/lib/constant.pm index b3a2e65cac..b77c085db3 100644 --- a/lib/constant.pm +++ b/lib/constant.pm @@ -22,6 +22,15 @@ my $normal_constant_name = qr/^_?[^\W_0-9]\w*$str_end/; my $tolerable = qr/^[A-Za-z_]\w*$str_end/; my $boolean = qr/^[01]?$str_end/; +BEGIN { + # We'd like to do use constant _CAN_PCS => $] > 5.009002 + # but that's a bit tricky before we load the constant module :-) + # By doing this, we save 1 run time check for *every* call to import. + no strict 'refs'; + my $const = $] > 5.009002; + *_CAN_PCS = sub () {$const}; +} + #======================================================================= # import() - import symbols into user's namespace # @@ -38,7 +47,7 @@ sub import { my $pkg = caller; my $symtab; - if ($] > 5.009002) { + if (_CAN_PCS) { no strict 'refs'; $symtab = \%{$pkg . '::'}; }; |