← Index
Performance Profile   « block view • line view • sub view »
For /wise/base/deliv/dev/bin/getfix
  Run on Thu May 20 15:30:03 2010
Reported on Thu May 20 16:25:32 2010

File/opt/wise/lib/perl5/5.10.0/constant.pm
Statements Executed2140
Total Time0.00467700000000002 seconds

Subroutines — ordered by exclusive time
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
929280.003660.00437constant::import
00000constant::BEGIN
00000constant::__ANON__[:115]
00000constant::__ANON__[:119]
00000constant::__ANON__[:121]

LineStmts.Exclusive
Time
Avg.Code
1package constant;
234.2e-51.4e-5use 5.005;
332.4e-58.0e-6use strict;
# spent 8µs making 1 call to strict::import
433.2e-51.1e-5use warnings::register;
# spent 109µs making 1 call to warnings::register::import
5
630.000154.8e-5use vars qw($VERSION %declared);
# spent 33µs making 1 call to vars::import
711.0e-61.0e-6$VERSION = '1.13';
8
9#=======================================================================
10
11# Some names are evil choices.
1219.0e-69.0e-6my %keywords = map +($_, 1), qw{ BEGIN INIT CHECK END DESTROY AUTOLOAD };
1314.0e-64.0e-6$keywords{UNITCHECK}++ if $] > 5.009;
14
1517.0e-67.0e-6my %forced_into_main = map +($_, 1),
16 qw{ STDIN STDOUT STDERR ARGV ARGVOUT ENV INC SIG };
17
1817.0e-67.0e-6my %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#=======================================================================
28
# spent 4.37ms (3.66+710µs) within constant::import which was called 92 times, avg 47µs/call: # once (80µs+10µs) at line 41 of /opt/wise/lib/perl5/5.10.0/x86_64-linux-thread-multi/IO/Compress/Base/Common.pm # once (81µs+8µs) at line 14 of /opt/wise/lib/perl5/5.10.0/x86_64-linux-thread-multi/IO/Uncompress/Base.pm # once (69µs+11µs) at line 65 of /opt/wise/lib/perl5/5.10.0/x86_64-linux-thread-multi/IO/Compress/Gzip/Constants.pm # once (59µs+16µs) at line 28 of /opt/wise/lib/perl5/5.10.0/Time/Local.pm # once (65µs+8µs) at line 54 of /opt/wise/lib/perl5/5.10.0/x86_64-linux-thread-multi/Compress/Zlib.pm # once (65µs+6µs) at line 68 of /wise/base/deliv/dev/lib/perl/FITSIO.pm # once (55µs+11µs) at line 55 of /wise/base/static/lib/perl5/site_perl/5.10.0/Astro/Coord.pm # once (56µs+8µs) at line 130 of /opt/wise/lib/perl5/5.10.0/x86_64-linux-thread-multi/IO/Compress/Base/Common.pm # once (43µs+21µs) at line 463 of /opt/wise/lib/perl5/5.10.0/x86_64-linux-thread-multi/IO/Compress/Base/Common.pm # once (53µs+10µs) at line 66 of /wise/base/deliv/dev/lib/perl/FITSIO.pm # once (54µs+7µs) at line 67 of /wise/base/deliv/dev/lib/perl/FITSIO.pm # once (51µs+9µs) by Astro::Coord::pm or Astro::Coord::BEGIN at line 2023 of /wise/base/static/lib/perl5/site_perl/5.10.0/Astro/Coord.pm # once (51µs+7µs) at line 90 of /opt/wise/lib/perl5/5.10.0/x86_64-linux-thread-multi/IO/Compress/Gzip/Constants.pm # once (50µs+7µs) at line 86 of /opt/wise/lib/perl5/5.10.0/x86_64-linux-thread-multi/IO/Compress/Gzip/Constants.pm # once (49µs+6µs) by U64::BEGIN at line 791 of /opt/wise/lib/perl5/5.10.0/x86_64-linux-thread-multi/IO/Compress/Base/Common.pm # once (46µs+8µs) at line 789 of /opt/wise/lib/perl5/5.10.0/x86_64-linux-thread-multi/IO/Compress/Base/Common.pm # once (44µs+8µs) at line 84 of /opt/wise/lib/perl5/5.10.0/x86_64-linux-thread-multi/IO/Compress/Gzip/Constants.pm # once (43µs+8µs) at line 76 of /wise/base/static/lib/perl5/site_perl/5.10.0/Astro/Coord.pm # once (43µs+7µs) at line 132 of /opt/wise/lib/perl5/5.10.0/x86_64-linux-thread-multi/IO/Compress/Base/Common.pm # once (42µs+8µs) at line 78 of /opt/wise/lib/perl5/5.10.0/x86_64-linux-thread-multi/Compress/Raw/Zlib.pm # once (42µs+8µs) at line 95 of /opt/wise/lib/perl5/5.10.0/x86_64-linux-thread-multi/Compress/Raw/Zlib.pm # once (44µs+6µs) at line 57 of /opt/wise/lib/perl5/5.10.0/x86_64-linux-thread-multi/Compress/Zlib.pm # once (42µs+8µs) at line 109 of /opt/wise/lib/perl5/5.10.0/x86_64-linux-thread-multi/IO/Compress/Gzip/Constants.pm # once (42µs+8µs) at line 89 of /opt/wise/lib/perl5/5.10.0/x86_64-linux-thread-multi/IO/Compress/Gzip/Constants.pm # once (41µs+8µs) at line 466 of /opt/wise/lib/perl5/5.10.0/x86_64-linux-thread-multi/IO/Compress/Base/Common.pm # once (41µs+8µs) at line 87 of /opt/wise/lib/perl5/5.10.0/x86_64-linux-thread-multi/IO/Compress/Gzip/Constants.pm # once (43µs+6µs) at line 70 of /wise/base/deliv/dev/lib/perl/FITSIO.pm # once (40µs+8µs) at line 115 of /opt/wise/lib/perl5/5.10.0/x86_64-linux-thread-multi/IO/Compress/Gzip/Constants.pm # once (41µs+6µs) at line 95 of /wise/base/deliv/dev/lib/perl/FITSIO.pm # once (41µs+6µs) at line 473 of /opt/wise/lib/perl5/5.10.0/x86_64-linux-thread-multi/IO/Compress/Base/Common.pm # once (39µs+8µs) at line 73 of /opt/wise/lib/perl5/5.10.0/x86_64-linux-thread-multi/IO/Compress/Gzip/Constants.pm # once (40µs+7µs) at line 113 of /opt/wise/lib/perl5/5.10.0/x86_64-linux-thread-multi/IO/Compress/Gzip/Constants.pm # once (38µs+8µs) at line 97 of /opt/wise/lib/perl5/5.10.0/x86_64-linux-thread-multi/Compress/Raw/Zlib.pm # once (38µs+8µs) at line 70 of /opt/wise/lib/perl5/5.10.0/x86_64-linux-thread-multi/IO/Compress/Gzip/Constants.pm # once (38µs+7µs) at line 74 of /opt/wise/lib/perl5/5.10.0/x86_64-linux-thread-multi/IO/Compress/Gzip/Constants.pm # once (38µs+7µs) at line 80 of /opt/wise/lib/perl5/5.10.0/x86_64-linux-thread-multi/Compress/Raw/Zlib.pm # once (37µs+8µs) at line 461 of /opt/wise/lib/perl5/5.10.0/x86_64-linux-thread-multi/IO/Compress/Base/Common.pm # once (37µs+8µs) at line 76 of /opt/wise/lib/perl5/5.10.0/x86_64-linux-thread-multi/IO/Compress/Gzip/Constants.pm # once (38µs+7µs) at line 478 of /opt/wise/lib/perl5/5.10.0/x86_64-linux-thread-multi/IO/Compress/Base/Common.pm # once (36µs+9µs) at line 79 of /wise/base/static/lib/perl5/site_perl/5.10.0/Astro/Coord.pm # once (36µs+8µs) at line 469 of /opt/wise/lib/perl5/5.10.0/x86_64-linux-thread-multi/IO/Compress/Base/Common.pm # once (37µs+7µs) at line 80 of /opt/wise/lib/perl5/5.10.0/x86_64-linux-thread-multi/IO/Compress/Gzip/Constants.pm # once (37µs+7µs) by IO::Compress::Gzip::Constants::BEGIN at line 143 of /opt/wise/lib/perl5/5.10.0/x86_64-linux-thread-multi/IO/Compress/Gzip/Constants.pm # once (37µs+7µs) at line 77 of /opt/wise/lib/perl5/5.10.0/x86_64-linux-thread-multi/IO/Compress/Gzip/Constants.pm # once (36µs+7µs) at line 15 of /opt/wise/lib/perl5/5.10.0/x86_64-linux-thread-multi/IO/Uncompress/Base.pm # once (35µs+8µs) at line 79 of /opt/wise/lib/perl5/5.10.0/x86_64-linux-thread-multi/Compress/Raw/Zlib.pm # once (36µs+7µs) at line 96 of /opt/wise/lib/perl5/5.10.0/x86_64-linux-thread-multi/Compress/Raw/Zlib.pm # once (35µs+8µs) at line 470 of /opt/wise/lib/perl5/5.10.0/x86_64-linux-thread-multi/IO/Compress/Base/Common.pm # once (37µs+6µs) at line 42 of /opt/wise/lib/perl5/5.10.0/x86_64-linux-thread-multi/IO/Compress/Base/Common.pm # once (35µs+8µs) at line 67 of /opt/wise/lib/perl5/5.10.0/x86_64-linux-thread-multi/IO/Compress/Gzip/Constants.pm # once (36µs+7µs) at line 69 of /opt/wise/lib/perl5/5.10.0/x86_64-linux-thread-multi/IO/Compress/Gzip/Constants.pm # once (35µs+8µs) at line 66 of /opt/wise/lib/perl5/5.10.0/x86_64-linux-thread-multi/IO/Compress/Gzip/Constants.pm # once (34µs+8µs) at line 131 of /opt/wise/lib/perl5/5.10.0/x86_64-linux-thread-multi/IO/Compress/Base/Common.pm # once (36µs+6µs) at line 476 of /opt/wise/lib/perl5/5.10.0/x86_64-linux-thread-multi/IO/Compress/Base/Common.pm # once (34µs+8µs) at line 56 of /wise/base/static/lib/perl5/site_perl/5.10.0/Astro/Coord.pm # once (35µs+7µs) at line 88 of /opt/wise/lib/perl5/5.10.0/x86_64-linux-thread-multi/IO/Compress/Gzip/Constants.pm # once (36µs+6µs) at line 75 of /opt/wise/lib/perl5/5.10.0/x86_64-linux-thread-multi/IO/Compress/Gzip/Constants.pm # once (34µs+8µs) at line 92 of /opt/wise/lib/perl5/5.10.0/x86_64-linux-thread-multi/IO/Compress/Gzip/Constants.pm # once (35µs+7µs) at line 462 of /opt/wise/lib/perl5/5.10.0/x86_64-linux-thread-multi/IO/Compress/Base/Common.pm # once (34µs+8µs) at line 119 of /opt/wise/lib/perl5/5.10.0/x86_64-linux-thread-multi/IO/Compress/Gzip/Constants.pm # once (35µs+7µs) at line 465 of /opt/wise/lib/perl5/5.10.0/x86_64-linux-thread-multi/IO/Compress/Base/Common.pm # once (33µs+9µs) at line 94 of /wise/base/deliv/dev/lib/perl/FITSIO.pm # once (34µs+7µs) at line 102 of /opt/wise/lib/perl5/5.10.0/x86_64-linux-thread-multi/Compress/Raw/Zlib.pm # once (34µs+7µs) at line 98 of /opt/wise/lib/perl5/5.10.0/x86_64-linux-thread-multi/Compress/Raw/Zlib.pm # once (34µs+7µs) at line 790 of /opt/wise/lib/perl5/5.10.0/x86_64-linux-thread-multi/IO/Compress/Base/Common.pm # once (33µs+8µs) at line 134 of /opt/wise/lib/perl5/5.10.0/x86_64-linux-thread-multi/IO/Compress/Base/Common.pm # once (33µs+8µs) at line 471 of /opt/wise/lib/perl5/5.10.0/x86_64-linux-thread-multi/IO/Compress/Base/Common.pm # once (35µs+6µs) by Time::Local::BEGIN at line 30 of /opt/wise/lib/perl5/5.10.0/Time/Local.pm # once (34µs+7µs) at line 29 of /opt/wise/lib/perl5/5.10.0/Time/Local.pm # once (33µs+8µs) at line 81 of /opt/wise/lib/perl5/5.10.0/x86_64-linux-thread-multi/Compress/Raw/Zlib.pm # once (33µs+8µs) at line 44 of /opt/wise/lib/perl5/5.10.0/x86_64-linux-thread-multi/IO/Compress/Base/Common.pm # once (33µs+8µs) at line 82 of /opt/wise/lib/perl5/5.10.0/x86_64-linux-thread-multi/IO/Compress/Gzip/Constants.pm # once (34µs+7µs) at line 111 of /opt/wise/lib/perl5/5.10.0/x86_64-linux-thread-multi/IO/Compress/Gzip/Constants.pm # once (33µs+8µs) at line 43 of /opt/wise/lib/perl5/5.10.0/x86_64-linux-thread-multi/IO/Compress/Base/Common.pm # once (33µs+8µs) at line 114 of /opt/wise/lib/perl5/5.10.0/x86_64-linux-thread-multi/IO/Compress/Gzip/Constants.pm # once (33µs+7µs) at line 100 of /opt/wise/lib/perl5/5.10.0/x86_64-linux-thread-multi/Compress/Raw/Zlib.pm # once (32µs+8µs) at line 108 of /opt/wise/lib/perl5/5.10.0/x86_64-linux-thread-multi/Compress/Raw/Zlib.pm # once (34µs+6µs) at line 55 of /opt/wise/lib/perl5/5.10.0/x86_64-linux-thread-multi/Compress/Zlib.pm # once (33µs+7µs) at line 82 of /wise/base/static/lib/perl5/site_perl/5.10.0/Astro/Coord.pm # once (33µs+7µs) at line 78 of /opt/wise/lib/perl5/5.10.0/x86_64-linux-thread-multi/IO/Compress/Gzip/Constants.pm # once (33µs+7µs) at line 99 of /opt/wise/lib/perl5/5.10.0/x86_64-linux-thread-multi/Compress/Raw/Zlib.pm # once (33µs+7µs) at line 86 of /wise/base/static/lib/perl5/site_perl/5.10.0/Astro/Coord.pm # once (31µs+8µs) at line 107 of /opt/wise/lib/perl5/5.10.0/x86_64-linux-thread-multi/Compress/Raw/Zlib.pm # once (33µs+6µs) at line 105 of /opt/wise/lib/perl5/5.10.0/x86_64-linux-thread-multi/Compress/Raw/Zlib.pm # once (33µs+6µs) by Compress::Raw::Zlib::BEGIN at line 109 of /opt/wise/lib/perl5/5.10.0/x86_64-linux-thread-multi/Compress/Raw/Zlib.pm # once (32µs+7µs) at line 475 of /opt/wise/lib/perl5/5.10.0/x86_64-linux-thread-multi/IO/Compress/Base/Common.pm # once (32µs+7µs) at line 106 of /opt/wise/lib/perl5/5.10.0/x86_64-linux-thread-multi/Compress/Raw/Zlib.pm # once (32µs+7µs) at line 474 of /opt/wise/lib/perl5/5.10.0/x86_64-linux-thread-multi/IO/Compress/Base/Common.pm # once (33µs+6µs) at line 477 of /opt/wise/lib/perl5/5.10.0/x86_64-linux-thread-multi/IO/Compress/Base/Common.pm # once (31µs+7µs) at line 464 of /opt/wise/lib/perl5/5.10.0/x86_64-linux-thread-multi/IO/Compress/Base/Common.pm # once (30µs+8µs) at line 56 of /opt/wise/lib/perl5/5.10.0/x86_64-linux-thread-multi/Compress/Zlib.pm # once (30µs+7µs) at line 104 of /opt/wise/lib/perl5/5.10.0/x86_64-linux-thread-multi/Compress/Raw/Zlib.pm
sub import {
299200.001021.1e-6 my $class = shift;
30 return unless @_; # Ignore 'use constant;'
31 my $constants;
32 my $multiple = ref $_[0];
33 my $pkg = caller;
34 my $symtab;
35 my $str_end = $] >= 5.006 ? "\\z" : "\\Z";
36
37920.000192.1e-6 if ($] > 5.009002) {
3830.000300.00010 no strict 'refs';
# spent 30µs making 1 call to strict::unimport
39 $symtab = \%{$pkg . '::'};
40 };
41
42920.000202.2e-6 if ( $multiple ) {
43 if (ref $_[0] ne 'HASH') {
44 require Carp;
45 Carp::croak("Invalid reference type '".ref(shift)."' not 'HASH'");
46 }
47 $constants = shift;
48 } else {
49 $constants->{+shift} = undef;
50 }
51
52 foreach my $name ( keys %$constants ) {
532760.000692.5e-6 unless (defined $name) {
54 require Carp;
55 Carp::croak("Can't use undef as constant name");
56 }
57
58 # Normal constant name
59 if ($name =~ /^_?[^\W_0-9]\w*$str_end/ and !$forbidden{$name}) {
60 # Everything is okay
61
62 # Name forced into main, but we're not in main. Fatal.
63 } elsif ($forced_into_main{$name} and $pkg ne 'main') {
64 require Carp;
65 Carp::croak("Constant name '$name' is forced into main::");
66
67 # Starts with double underscore. Fatal.
68 } elsif ($name =~ /^__/) {
69 require Carp;
70 Carp::croak("Constant name '$name' begins with '__'");
71
72 # Maybe the name is tolerable
73 } elsif ($name =~ /^[A-Za-z_]\w*$str_end/) {
74 # Then we'll warn only if you've asked for warnings
75 if (warnings::enabled()) {
76 if ($keywords{$name}) {
77 warnings::warn("Constant name '$name' is a Perl keyword");
78 } elsif ($forced_into_main{$name}) {
79 warnings::warn("Constant name '$name' is " .
80 "forced into package main::");
81 }
82 }
83
84 # Looks like a boolean
85 # use constant FRED == fred;
86 } elsif ($name =~ /^[01]?$str_end/) {
87 require Carp;
88 if (@_) {
89 Carp::croak("Constant name '$name' is invalid");
90 } else {
91 Carp::croak("Constant name looks like boolean value");
92 }
93
94 } else {
95 # Must have bad characters
96 require Carp;
97 Carp::croak("Constant name '$name' has invalid characters");
98 }
99
100 {
10130.000258.4e-5 no strict 'refs';
# spent 24µs making 1 call to strict::unimport
1022760.000471.7e-6 my $full_name = "${pkg}::$name";
103 $declared{$full_name}++;
1041840.000191.0e-6 if ($multiple || @_ == 1) {
105 my $scalar = $multiple ? $constants->{$name} : $_[0];
1062760.001083.9e-6 if ($symtab && !exists $symtab->{$name}) {
107 # No typeglob yet, so we can use a reference as space-
108 # efficient proxy for a constant subroutine
109 # The check in Perl_ck_rvconst knows that inlinable
110 # constants from cv_const_sv are read only. So we have to:
111 Internals::SvREADONLY($scalar, 1);
# spent 355µs making 92 calls to Internals::SvREADONLY, avg 4µs/call
112 $symtab->{$name} = \$scalar;
113 mro::method_changed_in($pkg);
# spent 355µs making 92 calls to mro::method_changed_in, avg 4µs/call
114 } else {
115 *$full_name = sub () { $scalar };
116 }
117 } elsif (@_) {
118 my @list = @_;
119 *$full_name = sub () { @list };
120 } else {
121 *$full_name = sub () { };
122 }
123 }
124 }
125}
126
12719.0e-69.0e-61;
128
129__END__
130
131=head1 NAME
132
133constant - Perl pragma to declare constants
134
135=head1 SYNOPSIS
136
137 use constant PI => 4 * atan2(1, 1);
138 use constant DEBUG => 0;
139
140 print "Pi equals ", PI, "...\n" if DEBUG;
141
142 use constant {
143 SEC => 0,
144 MIN => 1,
145 HOUR => 2,
146 MDAY => 3,
147 MON => 4,
148 YEAR => 5,
149 WDAY => 6,
150 YDAY => 7,
151 ISDST => 8,
152 };
153
154 use constant WEEKDAYS => qw(
155 Sunday Monday Tuesday Wednesday Thursday Friday Saturday
156 );
157
158 print "Today is ", (WEEKDAYS)[ (localtime)[WDAY] ], ".\n";
159
160=head1 DESCRIPTION
161
162This pragma allows you to declare constants at compile-time.
163
164When you declare a constant such as C<PI> using the method shown
165above, each machine your script runs upon can have as many digits
166of accuracy as it can use. Also, your program will be easier to
167read, more likely to be maintained (and maintained correctly), and
168far less likely to send a space probe to the wrong planet because
169nobody noticed the one equation in which you wrote C<3.14195>.
170
171When a constant is used in an expression, perl replaces it with its
172value at compile time, and may then optimize the expression further.
173In particular, any code in an C<if (CONSTANT)> block will be optimized
174away if the constant is false.
175
176=head1 NOTES
177
178As with all C<use> directives, defining a constant happens at
179compile time. Thus, it's probably not correct to put a constant
180declaration inside of a conditional statement (like C<if ($foo)
181{ use constant ... }>).
182
183Constants defined using this module cannot be interpolated into
184strings like variables. However, concatenation works just fine:
185
186 print "Pi equals PI...\n"; # WRONG: does not expand "PI"
187 print "Pi equals ".PI."...\n"; # right
188
189Even though a reference may be declared as a constant, the reference may
190point to data which may be changed, as this code shows.
191
192 use constant ARRAY => [ 1,2,3,4 ];
193 print ARRAY->[1];
194 ARRAY->[1] = " be changed";
195 print ARRAY->[1];
196
197Dereferencing constant references incorrectly (such as using an array
198subscript on a constant hash reference, or vice versa) will be trapped at
199compile time.
200
201Constants belong to the package they are defined in. To refer to a
202constant defined in another package, specify the full package name, as
203in C<Some::Package::CONSTANT>. Constants may be exported by modules,
204and may also be called as either class or instance methods, that is,
205as C<< Some::Package->CONSTANT >> or as C<< $obj->CONSTANT >> where
206C<$obj> is an instance of C<Some::Package>. Subclasses may define
207their own constants to override those in their base class.
208
209The use of all caps for constant names is merely a convention,
210although it is recommended in order to make constants stand out
211and to help avoid collisions with other barewords, keywords, and
212subroutine names. Constant names must begin with a letter or
213underscore. Names beginning with a double underscore are reserved. Some
214poor choices for names will generate warnings, if warnings are enabled at
215compile time.
216
217=head2 List constants
218
219Constants may be lists of more (or less) than one value. A constant
220with no values evaluates to C<undef> in scalar context. Note that
221constants with more than one value do I<not> return their last value in
222scalar context as one might expect. They currently return the number
223of values, but B<this may change in the future>. Do not use constants
224with multiple values in scalar context.
225
226B<NOTE:> This implies that the expression defining the value of a
227constant is evaluated in list context. This may produce surprises:
228
229 use constant TIMESTAMP => localtime; # WRONG!
230 use constant TIMESTAMP => scalar localtime; # right
231
232The first line above defines C<TIMESTAMP> as a 9-element list, as
233returned by C<localtime()> in list context. To set it to the string
234returned by C<localtime()> in scalar context, an explicit C<scalar>
235keyword is required.
236
237List constants are lists, not arrays. To index or slice them, they
238must be placed in parentheses.
239
240 my @workdays = WEEKDAYS[1 .. 5]; # WRONG!
241 my @workdays = (WEEKDAYS)[1 .. 5]; # right
242
243=head2 Defining multiple constants at once
244
245Instead of writing multiple C<use constant> statements, you may define
246multiple constants in a single statement by giving, instead of the
247constant name, a reference to a hash where the keys are the names of
248the constants to be defined. Obviously, all constants defined using
249this method must have a single value.
250
251 use constant {
252 FOO => "A single value",
253 BAR => "This", "won't", "work!", # Error!
254 };
255
256This is a fundamental limitation of the way hashes are constructed in
257Perl. The error messages produced when this happens will often be
258quite cryptic -- in the worst case there may be none at all, and
259you'll only later find that something is broken.
260
261When defining multiple constants, you cannot use the values of other
262constants defined in the same declaration. This is because the
263calling package doesn't know about any constant within that group
264until I<after> the C<use> statement is finished.
265
266 use constant {
267 BITMASK => 0xAFBAEBA8,
268 NEGMASK => ~BITMASK, # Error!
269 };
270
271=head2 Magic constants
272
273Magical values and references can be made into constants at compile
274time, allowing for way cool stuff like this. (These error numbers
275aren't totally portable, alas.)
276
277 use constant E2BIG => ($! = 7);
278 print E2BIG, "\n"; # something like "Arg list too long"
279 print 0+E2BIG, "\n"; # "7"
280
281You can't produce a tied constant by giving a tied scalar as the
282value. References to tied variables, however, can be used as
283constants without any problems.
284
285=head1 TECHNICAL NOTES
286
287In the current implementation, scalar constants are actually
288inlinable subroutines. As of version 5.004 of Perl, the appropriate
289scalar constant is inserted directly in place of some subroutine
290calls, thereby saving the overhead of a subroutine call. See
291L<perlsub/"Constant Functions"> for details about how and when this
292happens.
293
294In the rare case in which you need to discover at run time whether a
295particular constant has been declared via this module, you may use
296this function to examine the hash C<%constant::declared>. If the given
297constant name does not include a package name, the current package is
298used.
299
300 sub declared ($) {
301 use constant 1.01; # don't omit this!
302 my $name = shift;
303 $name =~ s/^::/main::/;
304 my $pkg = caller;
305 my $full_name = $name =~ /::/ ? $name : "${pkg}::$name";
306 $constant::declared{$full_name};
307 }
308
309=head1 CAVEATS
310
311In the current version of Perl, list constants are not inlined
312and some symbols may be redefined without generating a warning.
313
314It is not possible to have a subroutine or a keyword with the same
315name as a constant in the same package. This is probably a Good Thing.
316
317A constant with a name in the list C<STDIN STDOUT STDERR ARGV ARGVOUT
318ENV INC SIG> is not allowed anywhere but in package C<main::>, for
319technical reasons.
320
321Unlike constants in some languages, these cannot be overridden
322on the command line or via environment variables.
323
324You can get into trouble if you use constants in a context which
325automatically quotes barewords (as is true for any subroutine call).
326For example, you can't say C<$hash{CONSTANT}> because C<CONSTANT> will
327be interpreted as a string. Use C<$hash{CONSTANT()}> or
328C<$hash{+CONSTANT}> to prevent the bareword quoting mechanism from
329kicking in. Similarly, since the C<< => >> operator quotes a bareword
330immediately to its left, you have to say C<< CONSTANT() => 'value' >>
331(or simply use a comma in place of the big arrow) instead of
332C<< CONSTANT => 'value' >>.
333
334=head1 BUGS
335
336Please report any bugs or feature requests via the perlbug(1) utility.
337
338=head1 AUTHORS
339
340Tom Phoenix, E<lt>F<rootbeer@redcat.com>E<gt>, with help from
341many other folks.
342
343Multiple constant declarations at once added by Casey West,
344E<lt>F<casey@geeknest.com>E<gt>.
345
346Documentation mostly rewritten by Ilmari Karonen,
347E<lt>F<perl@itz.pp.sci.fi>E<gt>.
348
349This program is maintained by the Perl 5 Porters.
350The CPAN distribution is maintained by SE<eacute>bastien Aperghis-Tramoni
351E<lt>F<sebastien@aperghis.net>E<gt>.
352
353=head1 COPYRIGHT
354
355Copyright (C) 1997, 1999 Tom Phoenix
356
357This module is free software; you can redistribute it or modify it
358under the same terms as Perl itself.
359
360=cut