source: trunk/essentials/dev-lang/perl/lib/constant.pm@ 3310

Last change on this file since 3310 was 3181, checked in by bird, 19 years ago

perl 5.8.8

File size: 11.0 KB
Line 
1package constant;
2
3use strict;
4use 5.006_00;
5use warnings::register;
6
7our($VERSION, %declared);
8$VERSION = '1.05';
9
10#=======================================================================
11
12# Some names are evil choices.
13my %keywords = map +($_, 1), qw{ BEGIN INIT CHECK END DESTROY AUTOLOAD };
14
15my %forced_into_main = map +($_, 1),
16 qw{ STDIN STDOUT STDERR ARGV ARGVOUT ENV INC SIG };
17
18my %forbidden = (%keywords, %forced_into_main);
19
20#=======================================================================
21# import() - import symbols into user's namespace
22#
23# What we actually do is define a function in the caller's namespace
24# which returns the value. The function we create will normally
25# be inlined as a constant, thereby avoiding further sub calling
26# overhead.
27#=======================================================================
28sub import {
29 my $class = shift;
30 return unless @_; # Ignore 'use constant;'
31 my %constants = ();
32 my $multiple = ref $_[0];
33
34 if ( $multiple ) {
35 if (ref $_[0] ne 'HASH') {
36 require Carp;
37 Carp::croak("Invalid reference type '".ref(shift)."' not 'HASH'");
38 }
39 %constants = %{+shift};
40 } else {
41 $constants{+shift} = undef;
42 }
43