From: Nicholas Clark Date: Mon, 17 Aug 2009 12:15:58 +0000 (+0100) Subject: Convert perl version check in import() from run time to compile time. X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=c5764f70840f5068e5ce459d0b23d3afa4eb65de;p=p5sagit%2Fp5-mst-13.2.git Convert perl version check in import() from run time to compile time. --- diff --git a/lib/constant.pm b/lib/constant.pm index b3a2e65..b77c085 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 . '::'}; };