| Filename | /home/doy/perl5/perlbrew/perls/perl-5.10.1/lib/5.10.1/constant.pm |
| Statements | Executed 93 statements in 3.44ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 3 | 3 | 2 | 479µs | 628µs | constant::import |
| 1 | 1 | 1 | 95µs | 95µs | constant::BEGIN@2 |
| 3 | 1 | 1 | 59µs | 59µs | constant::CORE:regcomp (opcode) |
| 1 | 1 | 1 | 48µs | 66µs | constant::BEGIN@3 |
| 3 | 1 | 1 | 43µs | 43µs | constant::CORE:match (opcode) |
| 1 | 1 | 1 | 41µs | 110µs | constant::BEGIN@38 |
| 1 | 1 | 1 | 38µs | 104µs | constant::BEGIN@101 |
| 1 | 1 | 1 | 35µs | 205µs | constant::BEGIN@6 |
| 1 | 1 | 1 | 33µs | 428µs | constant::BEGIN@4 |
| 0 | 0 | 0 | 0s | 0s | constant::__ANON__[:115] |
| 0 | 0 | 0 | 0s | 0s | constant::__ANON__[:119] |
| 0 | 0 | 0 | 0s | 0s | constant::__ANON__[:121] |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | package constant; | ||||
| 2 | 3 | 169µs | 1 | 95µs | # spent 95µs within constant::BEGIN@2 which was called:
# once (95µs+0s) by Class::MOP::Method::Meta::BEGIN@14 at line 2 # spent 95µs making 1 call to constant::BEGIN@2 |
| 3 | 3 | 89µs | 2 | 83µs | # spent 66µs (48+18) within constant::BEGIN@3 which was called:
# once (48µs+18µs) by Class::MOP::Method::Meta::BEGIN@14 at line 3 # spent 66µs making 1 call to constant::BEGIN@3
# spent 18µs making 1 call to strict::import |
| 4 | 3 | 135µs | 2 | 823µs | # spent 428µs (33+395) within constant::BEGIN@4 which was called:
# once (33µs+395µs) by Class::MOP::Method::Meta::BEGIN@14 at line 4 # spent 428µs making 1 call to constant::BEGIN@4
# spent 395µs making 1 call to warnings::register::import |
| 5 | |||||
| 6 | 3 | 526µs | 2 | 374µs | # spent 205µs (35+169) within constant::BEGIN@6 which was called:
# once (35µs+169µs) by Class::MOP::Method::Meta::BEGIN@14 at line 6 # spent 205µs making 1 call to constant::BEGIN@6
# spent 169µs making 1 call to vars::import |
| 7 | 1 | 3µs | $VERSION = '1.17'; | ||
| 8 | |||||
| 9 | #======================================================================= | ||||
| 10 | |||||
| 11 | # Some names are evil choices. | ||||
| 12 | 1 | 22µs | my %keywords = map +($_, 1), qw{ BEGIN INIT CHECK END DESTROY AUTOLOAD }; | ||
| 13 | 1 | 7µs | $keywords{UNITCHECK}++ if $] > 5.009; | ||
| 14 | |||||
| 15 | 1 | 20µs | my %forced_into_main = map +($_, 1), | ||
| 16 | qw{ STDIN STDOUT STDERR ARGV ARGVOUT ENV INC SIG }; | ||||
| 17 | |||||
| 18 | 1 | 31µs | my %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 628µs (479+149) within constant::import which was called 3 times, avg 209µs/call:
# once (187µs+83µs) by Class::MOP::Method::Meta::BEGIN@14 at line 14 of Class/MOP/Method/Meta.pm
# once (164µs+40µs) by MooseX::Role::Parameterized::Meta::Role::Parameterizable::BEGIN@11 at line 11 of MooseX/Role/Parameterized/Meta/Role/Parameterizable.pm
# once (129µs+26µs) by MooseX::Role::Parameterized::Meta::Role::Parameterizable::BEGIN@12 at line 12 of MooseX/Role/Parameterized/Meta/Role/Parameterizable.pm | ||||
| 29 | 69 | 647µs | 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 | |||||
| 37 | if ($] > 5.009002) { | ||||
| 38 | 3 | 1.02ms | 2 | 179µs | # spent 110µs (41+69) within constant::BEGIN@38 which was called:
# once (41µs+69µs) by Class::MOP::Method::Meta::BEGIN@14 at line 38 # spent 110µs making 1 call to constant::BEGIN@38
# spent 69µs making 1 call to strict::unimport |
| 39 | $symtab = \%{$pkg . '::'}; | ||||
| 40 | }; | ||||
| 41 | |||||
| 42 | 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 ) { | ||||
| 53 | unless (defined $name) { | ||||
| 54 | require Carp; | ||||
| 55 | Carp::croak("Can't use undef as constant name"); | ||||
| 56 | } | ||||
| 57 | |||||
| 58 | # Normal constant name | ||||
| 59 | 6 | 102µs | if ($name =~ /^_?[^\W_0-9]\w*$str_end/ and !$forbidden{$name}) { # spent 59µs making 3 calls to constant::CORE:regcomp, avg 20µs/call
# spent 43µs making 3 calls to constant::CORE:match, avg 14µs/call | ||
| 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 | { | ||||
| 101 | 3 | 747µs | 2 | 169µs | # spent 104µs (38+66) within constant::BEGIN@101 which was called:
# once (38µs+66µs) by Class::MOP::Method::Meta::BEGIN@14 at line 101 # spent 104µs making 1 call to constant::BEGIN@101
# spent 66µs making 1 call to strict::unimport |
| 102 | my $full_name = "${pkg}::$name"; | ||||
| 103 | $declared{$full_name}++; | ||||
| 104 | if ($multiple || @_ == 1) { | ||||
| 105 | my $scalar = $multiple ? $constants->{$name} : $_[0]; | ||||
| 106 | 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 | 3 | 17µs | Internals::SvREADONLY($scalar, 1); # spent 17µs making 3 calls to Internals::SvREADONLY, avg 6µs/call | ||
| 112 | $symtab->{$name} = \$scalar; | ||||
| 113 | 3 | 30µs | mro::method_changed_in($pkg); # spent 30µs making 3 calls to mro::method_changed_in, avg 10µ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 | |||||
| 127 | 1 | 24µs | 1; | ||
| 128 | |||||
| 129 | __END__ | ||||
# spent 43µs within constant::CORE:match which was called 3 times, avg 14µs/call:
# 3 times (43µs+0s) by constant::import at line 59, avg 14µs/call | |||||
# spent 59µs within constant::CORE:regcomp which was called 3 times, avg 20µs/call:
# 3 times (59µs+0s) by constant::import at line 59, avg 20µs/call |