Filename | /usr/local/perls/perl-5.26.1/lib/5.26.1/constant.pm |
Statements | Executed 3870 statements in 5.34ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
129 | 129 | 7 | 3.80ms | 4.96ms | import | constant::
129 | 1 | 1 | 328µs | 328µs | CORE:subst (opcode) | constant::
129 | 1 | 1 | 286µs | 286µs | CORE:match (opcode) | constant::
129 | 1 | 1 | 261µs | 261µs | CORE:regcomp (opcode) | constant::
0 | 0 | 0 | 0s | 0s | BEGIN | constant::
0 | 0 | 0 | 0s | 0s | __ANON__[:174] | constant::
0 | 0 | 0 | 0s | 0s | __ANON__[:190] | constant::
0 | 0 | 0 | 0s | 0s | __ANON__[:192] | constant::
0 | 0 | 0 | 0s | 0s | __ANON__[:41] | constant::
0 | 0 | 0 | 0s | 0s | __ANON__[:42] | constant::
0 | 0 | 0 | 0s | 0s | __ANON__[:43] | constant::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package constant; | ||||
2 | use 5.008; | ||||
3 | use strict; | ||||
4 | use warnings::register; | ||||
5 | |||||
6 | our $VERSION = '1.33'; | ||||
7 | our %declared; | ||||
8 | |||||
9 | #======================================================================= | ||||
10 | |||||
11 | # Some names are evil choices. | ||||
12 | my %keywords = map +($_, 1), qw{ BEGIN INIT CHECK END DESTROY AUTOLOAD }; | ||||
13 | $keywords{UNITCHECK}++ if $] > 5.009; | ||||
14 | |||||
15 | my %forced_into_main = map +($_, 1), | ||||
16 | qw{ STDIN STDOUT STDERR ARGV ARGVOUT ENV INC SIG }; | ||||
17 | |||||
18 | my %forbidden = (%keywords, %forced_into_main); | ||||
19 | |||||
20 | my $normal_constant_name = qr/^_?[^\W_0-9]\w*\z/; | ||||
21 | my $tolerable = qr/^[A-Za-z_]\w*\z/; | ||||
22 | my $boolean = qr/^[01]?\z/; | ||||
23 | |||||
24 | BEGIN { | ||||
25 | # We'd like to do use constant _CAN_PCS => $] > 5.009002 | ||||
26 | # but that's a bit tricky before we load the constant module :-) | ||||
27 | # By doing this, we save several run time checks for *every* call | ||||
28 | # to import. | ||||
29 | my $const = $] > 5.009002; | ||||
30 | my $downgrade = $] < 5.015004; # && $] >= 5.008 | ||||
31 | my $constarray = exists &_make_const; | ||||
32 | if ($const) { | ||||
33 | Internals::SvREADONLY($const, 1); | ||||
34 | Internals::SvREADONLY($downgrade, 1); | ||||
35 | $constant::{_CAN_PCS} = \$const; | ||||
36 | $constant::{_DOWNGRADE} = \$downgrade; | ||||
37 | $constant::{_CAN_PCS_FOR_ARRAY} = \$constarray; | ||||
38 | } | ||||
39 | else { | ||||
40 | no strict 'refs'; | ||||
41 | *{"_CAN_PCS"} = sub () {$const}; | ||||
42 | *{"_DOWNGRADE"} = sub () { $downgrade }; | ||||
43 | *{"_CAN_PCS_FOR_ARRAY"} = sub () { $constarray }; | ||||
44 | } | ||||
45 | } | ||||
46 | |||||
47 | #======================================================================= | ||||
48 | # import() - import symbols into user's namespace | ||||
49 | # | ||||
50 | # What we actually do is define a function in the caller's namespace | ||||
51 | # which returns the value. The function we create will normally | ||||
52 | # be inlined as a constant, thereby avoiding further sub calling | ||||
53 | # overhead. | ||||
54 | #======================================================================= | ||||
55 | # spent 4.96ms (3.80+1.16) within constant::import which was called 129 times, avg 38µs/call:
# once (81µs+24µs) by IO::Compress::Base::Common::BEGIN@45 at line 45 of IO/Compress/Base/Common.pm
# once (67µs+25µs) by Archive::Tar::Constant::BEGIN@17 at line 17 of Archive/Tar/Constant.pm
# once (64µs+16µs) by IO::Compress::Base::Common::BEGIN@48 at line 48 of IO/Compress/Base/Common.pm
# once (42µs+16µs) by IO::Compress::Gzip::Constants::BEGIN@65 at line 65 of IO/Compress/Gzip/Constants.pm
# once (40µs+16µs) by Archive::Tar::Constant::BEGIN@74 at line 78 of Archive/Tar/Constant.pm
# once (41µs+15µs) by Compress::Zlib::BEGIN@48 at line 48 of Compress/Zlib.pm
# once (47µs+8µs) by Archive::Tar::Constant::BEGIN@62 at line 62 of Archive/Tar/Constant.pm
# once (45µs+9µs) by Archive::Tar::Constant::BEGIN@18 at line 18 of Archive/Tar/Constant.pm
# once (38µs+15µs) by Compress::Raw::Bzip2::BEGIN@55 at line 55 of Compress/Raw/Bzip2.pm
# once (42µs+9µs) by Archive::Tar::Constant::BEGIN@33 at line 33 of Archive/Tar/Constant.pm
# once (39µs+11µs) by Compress::Raw::Zlib::BEGIN@105 at line 105 of Compress/Raw/Zlib.pm
# once (38µs+12µs) by IO::Uncompress::Base::BEGIN@14 at line 14 of IO/Uncompress/Base.pm
# once (42µs+8µs) by Archive::Tar::Constant::BEGIN@49 at line 49 of Archive/Tar/Constant.pm
# once (36µs+13µs) by IO::Compress::Base::Common::BEGIN@480 at line 480 of IO/Compress/Base/Common.pm
# once (39µs+9µs) by Archive::Tar::Constant::BEGIN@52 at line 52 of Archive/Tar/Constant.pm
# once (39µs+8µs) by Archive::Tar::Constant::BEGIN@63 at line 63 of Archive/Tar/Constant.pm
# once (40µs+7µs) by Archive::Tar::Constant::BEGIN@58 at line 58 of Archive/Tar/Constant.pm
# once (37µs+8µs) by IO::Compress::Gzip::Constants::BEGIN@69 at line 69 of IO/Compress/Gzip/Constants.pm
# once (34µs+11µs) by IO::Compress::Gzip::Constants::BEGIN@143 at line 145 of IO/Compress/Gzip/Constants.pm
# once (35µs+9µs) by U64::BEGIN@835 at line 835 of IO/Compress/Base/Common.pm
# once (32µs+10µs) by IO::Compress::Base::Common::BEGIN@49 at line 49 of IO/Compress/Base/Common.pm
# once (31µs+11µs) by IO::Compress::Base::Common::BEGIN@46 at line 46 of IO/Compress/Base/Common.pm
# once (33µs+9µs) by Archive::Tar::Constant::BEGIN@36 at line 36 of Archive/Tar/Constant.pm
# once (31µs+9µs) by Compress::Raw::Zlib::BEGIN@118 at line 118 of Compress/Raw/Zlib.pm
# once (30µs+10µs) by Compress::Raw::Bzip2::BEGIN@56 at line 56 of Compress/Raw/Bzip2.pm
# once (30µs+10µs) by IO::Compress::Base::Common::BEGIN@148 at line 148 of IO/Compress/Base/Common.pm
# once (31µs+9µs) by Archive::Tar::Constant::BEGIN@80 at line 80 of Archive/Tar/Constant.pm
# once (32µs+8µs) by Archive::Tar::Constant::BEGIN@19 at line 19 of Archive/Tar/Constant.pm
# once (30µs+9µs) by IO::Compress::Gzip::Constants::BEGIN@115 at line 115 of IO/Compress/Gzip/Constants.pm
# once (32µs+7µs) by U64::BEGIN@837 at line 837 of IO/Compress/Base/Common.pm
# once (31µs+8µs) by Archive::Tar::Constant::BEGIN@38 at line 38 of Archive/Tar/Constant.pm
# once (30µs+9µs) by Archive::Tar::Constant::BEGIN@26 at line 26 of Archive/Tar/Constant.pm
# once (30µs+9µs) by Archive::Tar::Constant::BEGIN@53 at line 53 of Archive/Tar/Constant.pm
# once (30µs+9µs) by Compress::Zlib::BEGIN@50 at line 50 of Compress/Zlib.pm
# once (28µs+10µs) by Compress::Raw::Zlib::BEGIN@106 at line 106 of Compress/Raw/Zlib.pm
# once (29µs+9µs) by IO::Compress::Base::Common::BEGIN@490 at line 490 of IO/Compress/Base/Common.pm
# once (30µs+8µs) by Archive::Tar::Constant::BEGIN@29 at line 29 of Archive/Tar/Constant.pm
# once (29µs+9µs) by Archive::Tar::Constant::BEGIN@41 at line 41 of Archive/Tar/Constant.pm
# once (30µs+8µs) by Archive::Tar::Constant::BEGIN@31 at line 31 of Archive/Tar/Constant.pm
# once (30µs+8µs) by Archive::Tar::Constant::BEGIN@56 at line 56 of Archive/Tar/Constant.pm
# once (29µs+8µs) by Compress::Raw::Zlib::BEGIN@122 at line 122 of Compress/Raw/Zlib.pm
# once (29µs+8µs) by Compress::Raw::Zlib::BEGIN@119 at line 119 of Compress/Raw/Zlib.pm
# once (28µs+9µs) by Compress::Raw::Bzip2::BEGIN@57 at line 57 of Compress/Raw/Bzip2.pm
# once (25µs+12µs) by IO::Uncompress::Base::BEGIN@15 at line 15 of IO/Uncompress/Base.pm
# once (27µs+10µs) by IO::Compress::Base::Common::BEGIN@481 at line 481 of IO/Compress/Base/Common.pm
# once (28µs+9µs) by IO::Compress::Base::Common::BEGIN@149 at line 149 of IO/Compress/Base/Common.pm
# once (28µs+9µs) by IO::Compress::Base::Common::BEGIN@150 at line 150 of IO/Compress/Base/Common.pm
# once (29µs+8µs) by U64::BEGIN@836 at line 836 of IO/Compress/Base/Common.pm
# once (29µs+8µs) by IO::Compress::Base::Common::BEGIN@493 at line 493 of IO/Compress/Base/Common.pm
# once (27µs+10µs) by Archive::Tar::Constant::BEGIN@84 at line 84 of Archive/Tar/Constant.pm
# once (29µs+8µs) by Archive::Tar::Constant::BEGIN@83 at line 83 of Archive/Tar/Constant.pm
# once (29µs+8µs) by Archive::Tar::Constant::BEGIN@22 at line 22 of Archive/Tar/Constant.pm
# once (29µs+8µs) by Archive::Tar::Constant::BEGIN@21 at line 21 of Archive/Tar/Constant.pm
# once (29µs+8µs) by Archive::Tar::Constant::BEGIN@48 at line 48 of Archive/Tar/Constant.pm
# once (28µs+8µs) by Compress::Raw::Bzip2::BEGIN@58 at line 58 of Compress/Raw/Bzip2.pm
# once (27µs+9µs) by IO::Compress::Gzip::Constants::BEGIN@109 at line 109 of IO/Compress/Gzip/Constants.pm
# once (29µs+7µs) by Archive::Tar::Constant::BEGIN@54 at line 54 of Archive/Tar/Constant.pm
# once (29µs+7µs) by Archive::Tar::Constant::BEGIN@47 at line 47 of Archive/Tar/Constant.pm
# once (28µs+8µs) by Archive::Tar::Constant::BEGIN@64 at line 64 of Archive/Tar/Constant.pm
# once (27µs+9µs) by Archive::Tar::Constant::BEGIN@25 at line 25 of Archive/Tar/Constant.pm
# once (27µs+9µs) by Archive::Tar::Constant::BEGIN@50 at line 50 of Archive/Tar/Constant.pm
# once (28µs+8µs) by Archive::Tar::Constant::BEGIN@23 at line 23 of Archive/Tar/Constant.pm
# once (27µs+8µs) by Compress::Raw::Zlib::BEGIN@149 at line 149 of Compress/Raw/Zlib.pm
# once (26µs+9µs) by Compress::Raw::Zlib::BEGIN@121 at line 121 of Compress/Raw/Zlib.pm
# once (26µs+9µs) by Compress::Raw::Zlib::BEGIN@139 at line 139 of Compress/Raw/Zlib.pm
# once (28µs+7µs) by Compress::Raw::Zlib::BEGIN@136 at line 136 of Compress/Raw/Zlib.pm
# once (27µs+8µs) by Compress::Raw::Zlib::BEGIN@148 at line 148 of Compress/Raw/Zlib.pm
# once (27µs+8µs) by IO::Compress::Gzip::Constants::BEGIN@70 at line 70 of IO/Compress/Gzip/Constants.pm
# once (26µs+9µs) by IO::Compress::Gzip::Constants::BEGIN@88 at line 88 of IO/Compress/Gzip/Constants.pm
# once (26µs+9µs) by IO::Compress::Base::Common::BEGIN@483 at line 483 of IO/Compress/Base/Common.pm
# once (27µs+8µs) by IO::Compress::Base::Common::BEGIN@499 at line 499 of IO/Compress/Base/Common.pm
# once (27µs+8µs) by IO::Compress::Base::Common::BEGIN@500 at line 500 of IO/Compress/Base/Common.pm
# once (27µs+8µs) by IO::Compress::Base::Common::BEGIN@494 at line 494 of IO/Compress/Base/Common.pm
# once (25µs+10µs) by IO::Compress::Base::Common::BEGIN@47 at line 47 of IO/Compress/Base/Common.pm
# once (27µs+8µs) by Archive::Tar::Constant::BEGIN@24 at line 24 of Archive/Tar/Constant.pm
# once (27µs+8µs) by Archive::Tar::Constant::BEGIN@37 at line 37 of Archive/Tar/Constant.pm
# once (26µs+9µs) by Archive::Tar::Constant::BEGIN@61 at line 61 of Archive/Tar/Constant.pm
# once (27µs+8µs) by Archive::Tar::Constant::BEGIN@85 at line 85 of Archive/Tar/Constant.pm
# once (27µs+8µs) by Archive::Tar::Constant::BEGIN@20 at line 20 of Archive/Tar/Constant.pm
# once (27µs+8µs) by Archive::Tar::Constant::BEGIN@86 at line 86 of Archive/Tar/Constant.pm
# once (25µs+10µs) by Compress::Zlib::BEGIN@49 at line 49 of Compress/Zlib.pm
# once (27µs+8µs) by Compress::Zlib::BEGIN@51 at line 51 of Compress/Zlib.pm
# once (26µs+8µs) by Compress::Raw::Zlib::BEGIN@120 at line 120 of Compress/Raw/Zlib.pm
# once (27µs+7µs) by IO::Compress::Gzip::Constants::BEGIN@92 at line 93 of IO/Compress/Gzip/Constants.pm
# once (26µs+8µs) by IO::Compress::Gzip::Constants::BEGIN@119 at line 119 of IO/Compress/Gzip/Constants.pm
# once (25µs+9µs) by IO::Compress::Gzip::Constants::BEGIN@67 at line 67 of IO/Compress/Gzip/Constants.pm
# once (25µs+9µs) by IO::Compress::Gzip::Constants::BEGIN@66 at line 66 of IO/Compress/Gzip/Constants.pm
# once (27µs+7µs) by IO::Compress::Gzip::Constants::BEGIN@78 at line 78 of IO/Compress/Gzip/Constants.pm
# once (25µs+9µs) by IO::Compress::Gzip::Constants::BEGIN@90 at line 91 of IO/Compress/Gzip/Constants.pm
# once (26µs+8µs) by IO::Compress::Gzip::Constants::BEGIN@80 at line 80 of IO/Compress/Gzip/Constants.pm
# once (26µs+8µs) by IO::Compress::Base::Common::BEGIN@482 at line 482 of IO/Compress/Base/Common.pm
# once (26µs+8µs) by IO::Compress::Base::Common::BEGIN@50 at line 50 of IO/Compress/Base/Common.pm
# once (26µs+8µs) by IO::Compress::Base::Common::BEGIN@484 at line 484 of IO/Compress/Base/Common.pm
# once (26µs+8µs) by Archive::Tar::Constant::BEGIN@27 at line 27 of Archive/Tar/Constant.pm
# once (27µs+7µs) by Archive::Tar::Constant::BEGIN@42 at line 42 of Archive/Tar/Constant.pm
# once (26µs+7µs) by Compress::Raw::Zlib::BEGIN@150 at line 150 of Compress/Raw/Zlib.pm
# once (25µs+8µs) by IO::Compress::Gzip::Constants::BEGIN@75 at line 75 of IO/Compress/Gzip/Constants.pm
# once (25µs+8µs) by IO::Compress::Gzip::Constants::BEGIN@74 at line 74 of IO/Compress/Gzip/Constants.pm
# once (25µs+8µs) by IO::Compress::Gzip::Constants::BEGIN@77 at line 77 of IO/Compress/Gzip/Constants.pm
# once (24µs+9µs) by IO::Compress::Base::Common::BEGIN@485 at line 485 of IO/Compress/Base/Common.pm
# once (25µs+8µs) by IO::Compress::Base::Common::BEGIN@492 at line 492 of IO/Compress/Base/Common.pm
# once (25µs+8µs) by IO::Compress::Base::Common::BEGIN@489 at line 489 of IO/Compress/Base/Common.pm
# once (25µs+8µs) by Archive::Tar::Constant::BEGIN@65 at line 65 of Archive/Tar/Constant.pm
# once (25µs+8µs) by Archive::Tar::Constant::BEGIN@57 at line 57 of Archive/Tar/Constant.pm
# once (25µs+8µs) by Archive::Tar::Constant::BEGIN@30 at line 30 of Archive/Tar/Constant.pm
# once (26µs+7µs) by Archive::Tar::Constant::BEGIN@34 at line 34 of Archive/Tar/Constant.pm
# once (26µs+7µs) by Archive::Tar::Constant::BEGIN@40 at line 40 of Archive/Tar/Constant.pm
# once (24µs+9µs) by Archive::Tar::Constant::BEGIN@81 at line 81 of Archive/Tar/Constant.pm
# once (24µs+9µs) by Archive::Tar::Constant::BEGIN@59 at line 59 of Archive/Tar/Constant.pm
# once (25µs+7µs) by Compress::Raw::Zlib::BEGIN@145 at line 145 of Compress/Raw/Zlib.pm
# once (24µs+8µs) by Compress::Raw::Zlib::BEGIN@146 at line 146 of Compress/Raw/Zlib.pm
# once (24µs+8µs) by Compress::Raw::Zlib::BEGIN@138 at line 138 of Compress/Raw/Zlib.pm
# once (24µs+8µs) by IO::Compress::Gzip::Constants::BEGIN@76 at line 76 of IO/Compress/Gzip/Constants.pm
# once (25µs+7µs) by IO::Compress::Gzip::Constants::BEGIN@114 at line 114 of IO/Compress/Gzip/Constants.pm
# once (25µs+7µs) by IO::Compress::Gzip::Constants::BEGIN@87 at line 87 of IO/Compress/Gzip/Constants.pm
# once (24µs+8µs) by IO::Compress::Base::Common::BEGIN@152 at line 152 of IO/Compress/Base/Common.pm
# once (24µs+8µs) by U64::BEGIN@838 at line 838 of IO/Compress/Base/Common.pm
# once (24µs+8µs) by IO::Compress::Base::Common::BEGIN@51 at line 51 of IO/Compress/Base/Common.pm
# once (23µs+8µs) by Compress::Raw::Zlib::BEGIN@137 at line 137 of Compress/Raw/Zlib.pm
# once (23µs+8µs) by Compress::Raw::Zlib::BEGIN@147 at line 147 of Compress/Raw/Zlib.pm
# once (23µs+8µs) by IO::Compress::Gzip::Constants::BEGIN@86 at line 86 of IO/Compress/Gzip/Constants.pm
# once (22µs+9µs) by IO::Compress::Gzip::Constants::BEGIN@89 at line 89 of IO/Compress/Gzip/Constants.pm
# once (24µs+7µs) by IO::Compress::Gzip::Constants::BEGIN@82 at line 82 of IO/Compress/Gzip/Constants.pm
# once (24µs+7µs) by IO::Compress::Gzip::Constants::BEGIN@113 at line 113 of IO/Compress/Gzip/Constants.pm
# once (23µs+8µs) by IO::Compress::Base::Common::BEGIN@495 at line 495 of IO/Compress/Base/Common.pm
# once (23µs+8µs) by Archive::Tar::Constant::BEGIN@68 at line 71 of Archive/Tar/Constant.pm
# once (22µs+8µs) by IO::Compress::Gzip::Constants::BEGIN@84 at line 84 of IO/Compress/Gzip/Constants.pm
# once (22µs+8µs) by IO::Compress::Gzip::Constants::BEGIN@73 at line 73 of IO/Compress/Gzip/Constants.pm
# once (22µs+8µs) by IO::Compress::Gzip::Constants::BEGIN@111 at line 111 of IO/Compress/Gzip/Constants.pm | ||||
56 | 129 | 66µs | my $class = shift; | ||
57 | 129 | 47µs | return unless @_; # Ignore 'use constant;' | ||
58 | 129 | 21µs | my $constants; | ||
59 | 129 | 56µs | my $multiple = ref $_[0]; | ||
60 | 129 | 62µs | my $caller = caller; | ||
61 | 129 | 26µs | my $flush_mro; | ||
62 | my $symtab; | ||||
63 | |||||
64 | 129 | 56µs | if (_CAN_PCS) { | ||
65 | no strict 'refs'; | ||||
66 | 129 | 159µs | $symtab = \%{$caller . '::'}; | ||
67 | }; | ||||
68 | |||||
69 | 129 | 33µs | if ( $multiple ) { | ||
70 | if (ref $_[0] ne 'HASH') { | ||||
71 | require Carp; | ||||
72 | Carp::croak("Invalid reference type '".ref(shift)."' not 'HASH'"); | ||||
73 | } | ||||
74 | $constants = shift; | ||||
75 | } else { | ||||
76 | 129 | 27µs | unless (defined $_[0]) { | ||
77 | require Carp; | ||||
78 | Carp::croak("Can't use undef as constant name"); | ||||
79 | } | ||||
80 | 129 | 219µs | $constants->{+shift} = undef; | ||
81 | } | ||||
82 | |||||
83 | 129 | 198µs | foreach my $name ( keys %$constants ) { | ||
84 | 129 | 14µs | my $pkg; | ||
85 | 129 | 29µs | my $symtab = $symtab; | ||
86 | 129 | 31µs | my $orig_name = $name; | ||
87 | 129 | 682µs | 129 | 328µs | if ($name =~ s/(.*)(?:::|')(?=.)//s) { # spent 328µs making 129 calls to constant::CORE:subst, avg 3µs/call |
88 | $pkg = $1; | ||||
89 | if (_CAN_PCS && $pkg ne $caller) { | ||||
90 | no strict 'refs'; | ||||
91 | $symtab = \%{$pkg . '::'}; | ||||
92 | } | ||||
93 | } | ||||
94 | else { | ||||
95 | 129 | 34µs | $pkg = $caller; | ||
96 | } | ||||
97 | |||||
98 | # Normal constant name | ||||
99 | 129 | 1.01ms | 258 | 547µs | if ($name =~ $normal_constant_name and !$forbidden{$name}) { # spent 286µs making 129 calls to constant::CORE:match, avg 2µs/call
# spent 261µs making 129 calls to constant::CORE:regcomp, avg 2µs/call |
100 | # Everything is okay | ||||
101 | |||||
102 | # Name forced into main, but we're not in main. Fatal. | ||||
103 | } elsif ($forced_into_main{$name} and $pkg ne 'main') { | ||||
104 | require Carp; | ||||
105 | Carp::croak("Constant name '$name' is forced into main::"); | ||||
106 | |||||
107 | # Starts with double underscore. Fatal. | ||||
108 | } elsif ($name =~ /^__/) { | ||||
109 | require Carp; | ||||
110 | Carp::croak("Constant name '$name' begins with '__'"); | ||||
111 | |||||
112 | # Maybe the name is tolerable | ||||
113 | } elsif ($name =~ $tolerable) { | ||||
114 | # Then we'll warn only if you've asked for warnings | ||||
115 | if (warnings::enabled()) { | ||||
116 | if ($keywords{$name}) { | ||||
117 | warnings::warn("Constant name '$name' is a Perl keyword"); | ||||
118 | } elsif ($forced_into_main{$name}) { | ||||
119 | warnings::warn("Constant name '$name' is " . | ||||
120 | "forced into package main::"); | ||||
121 | } | ||||
122 | } | ||||
123 | |||||
124 | # Looks like a boolean | ||||
125 | # use constant FRED == fred; | ||||
126 | } elsif ($name =~ $boolean) { | ||||
127 | require Carp; | ||||
128 | if (@_) { | ||||
129 | Carp::croak("Constant name '$name' is invalid"); | ||||
130 | } else { | ||||
131 | Carp::croak("Constant name looks like boolean value"); | ||||
132 | } | ||||
133 | |||||
134 | } else { | ||||
135 | # Must have bad characters | ||||
136 | require Carp; | ||||
137 | Carp::croak("Constant name '$name' has invalid characters"); | ||||
138 | } | ||||
139 | |||||
140 | { | ||||
141 | 129 | 100µs | no strict 'refs'; | ||
142 | 129 | 86µs | my $full_name = "${pkg}::$name"; | ||
143 | 129 | 258µs | $declared{$full_name}++; | ||
144 | 129 | 85µs | if ($multiple || @_ == 1) { | ||
145 | 129 | 46µs | my $scalar = $multiple ? $constants->{$orig_name} : $_[0]; | ||
146 | |||||
147 | if (_DOWNGRADE) { # for 5.8 to 5.14 | ||||
148 | # Work around perl bug #31991: Sub names (actually glob | ||||
149 | # names in general) ignore the UTF8 flag. So we have to | ||||
150 | # turn it off to get the "right" symbol table entry. | ||||
151 | utf8::is_utf8 $name and utf8::encode $name; | ||||
152 | } | ||||
153 | |||||
154 | # The constant serves to optimise this entire block out on | ||||
155 | # 5.8 and earlier. | ||||
156 | 129 | 43µs | if (_CAN_PCS) { | ||
157 | # Use a reference as a proxy for a constant subroutine. | ||||
158 | # If this is not a glob yet, it saves space. If it is | ||||
159 | # a glob, we must still create it this way to get the | ||||
160 | # right internal flags set, as constants are distinct | ||||
161 | # from subroutines created with sub(){...}. | ||||
162 | # The check in Perl_ck_rvconst knows that inlinable | ||||
163 | # constants from cv_const_sv are read only. So we have to: | ||||
164 | 129 | 435µs | 129 | 137µs | Internals::SvREADONLY($scalar, 1); # spent 137µs making 129 calls to Internals::SvREADONLY, avg 1µs/call |
165 | 129 | 84µs | if (!exists $symtab->{$name}) { | ||
166 | 129 | 76µs | $symtab->{$name} = \$scalar; | ||
167 | 129 | 78µs | ++$flush_mro->{$pkg}; | ||
168 | } | ||||
169 | else { | ||||
170 | local $constant::{_dummy} = \$scalar; | ||||
171 | *$full_name = \&{"_dummy"}; | ||||
172 | } | ||||
173 | } else { | ||||
174 | *$full_name = sub () { $scalar }; | ||||
175 | } | ||||
176 | } elsif (@_) { | ||||
177 | my @list = @_; | ||||
178 | if (_CAN_PCS_FOR_ARRAY) { | ||||
179 | _make_const($list[$_]) for 0..$#list; | ||||
180 | _make_const(@list); | ||||
181 | if (!exists $symtab->{$name}) { | ||||
182 | $symtab->{$name} = \@list; | ||||
183 | $flush_mro->{$pkg}++; | ||||
184 | } | ||||
185 | else { | ||||
186 | local $constant::{_dummy} = \@list; | ||||
187 | *$full_name = \&{"_dummy"}; | ||||
188 | } | ||||
189 | } | ||||
190 | else { *$full_name = sub () { @list }; } | ||||
191 | } else { | ||||
192 | *$full_name = sub () { }; | ||||
193 | } | ||||
194 | } | ||||
195 | } | ||||
196 | # Flush the cache exactly once if we make any direct symbol table changes. | ||||
197 | 129 | 678µs | if (_CAN_PCS && $flush_mro) { | ||
198 | 129 | 606µs | 129 | 144µs | mro::method_changed_in($_) for keys %$flush_mro; # spent 144µs making 129 calls to mro::method_changed_in, avg 1µs/call |
199 | } | ||||
200 | } | ||||
201 | |||||
202 | 1; | ||||
203 | |||||
204 | __END__ | ||||
# spent 286µs within constant::CORE:match which was called 129 times, avg 2µs/call:
# 129 times (286µs+0s) by constant::import at line 99, avg 2µs/call | |||||
# spent 261µs within constant::CORE:regcomp which was called 129 times, avg 2µs/call:
# 129 times (261µs+0s) by constant::import at line 99, avg 2µs/call | |||||
# spent 328µs within constant::CORE:subst which was called 129 times, avg 3µs/call:
# 129 times (328µs+0s) by constant::import at line 87, avg 3µs/call |