Filename | /usr/lib/x86_64-linux-gnu/perl-base/base.pm |
Statements | Executed 123 statements in 917µs |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
3 | 3 | 3 | 70µs | 99µs | import | base::
3 | 1 | 1 | 12µs | 17µs | __ANON__[:75] | base::
1 | 1 | 1 | 10µs | 10µs | BEGIN@1 | YAML::XS::
3 | 1 | 1 | 5µs | 5µs | has_fields | base::
1 | 1 | 1 | 4µs | 6µs | BEGIN@4 | base::
3 | 1 | 1 | 3µs | 3µs | has_attr | base::
3 | 1 | 1 | 2µs | 2µs | CORE:subst (opcode) | base::
3 | 1 | 1 | 700ns | 700ns | CORE:match (opcode) | base::
0 | 0 | 0 | 0s | 0s | __ANON__[:131] | base::
0 | 0 | 0 | 0s | 0s | __ANON__[:132] | base::
0 | 0 | 0 | 0s | 0s | __ANON__[:52] | base::
0 | 0 | 0 | 0s | 0s | __ANON__[:59] | base::
0 | 0 | 0 | 0s | 0s | __ANON__[:67] | base::
0 | 0 | 0 | 0s | 0s | DESTROY | base::__inc::scope_guard::
0 | 0 | 0 | 0s | 0s | unhook | base::__inc::
0 | 0 | 0 | 0s | 0s | get_attr | base::
0 | 0 | 0 | 0s | 0s | inherit_fields | base::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | 2 | 30µs | 1 | 10µs | # spent 10µs within YAML::XS::BEGIN@1 which was called:
# once (10µs+0s) by YAML::XS::BEGIN@6 at line 1 # spent 10µs making 1 call to YAML::XS::BEGIN@1 |
2 | package base; | ||||
3 | |||||
4 | 2 | 777µs | 2 | 9µs | # spent 6µs (4+3) within base::BEGIN@4 which was called:
# once (4µs+3µs) by YAML::XS::BEGIN@6 at line 4 # spent 6µs making 1 call to base::BEGIN@4
# spent 3µs making 1 call to strict::import |
5 | 1 | 300ns | our $VERSION = '2.27'; | ||
6 | 1 | 1µs | $VERSION =~ tr/_//d; | ||
7 | |||||
8 | # simplest way to avoid indexing of the package: no package statement | ||||
9 | sub base::__inc::unhook { @INC = grep !(ref eq 'CODE' && $_ == $_[0]), @INC } | ||||
10 | # instance is blessed array of coderefs to be removed from @INC at scope exit | ||||
11 | sub base::__inc::scope_guard::DESTROY { base::__inc::unhook $_ for @{$_[0]} } | ||||
12 | |||||
13 | # constant.pm is slow | ||||
14 | sub SUCCESS () { 1 } | ||||
15 | |||||
16 | sub PUBLIC () { 2**0 } | ||||
17 | sub PRIVATE () { 2**1 } | ||||
18 | sub INHERITED () { 2**2 } | ||||
19 | sub PROTECTED () { 2**3 } | ||||
20 | |||||
21 | 1 | 500ns | my $Fattr = \%fields::attr; | ||
22 | |||||
23 | # spent 5µs within base::has_fields which was called 3 times, avg 2µs/call:
# 3 times (5µs+0s) by base::import at line 175, avg 2µs/call | ||||
24 | 3 | 900ns | my($base) = shift; | ||
25 | 3 | 2µs | my $fglob = ${"$base\::"}{FIELDS}; | ||
26 | 3 | 3µs | return( ($fglob && 'GLOB' eq ref($fglob) && *$fglob{HASH}) ? 1 : 0 ); | ||
27 | } | ||||
28 | |||||
29 | # spent 3µs within base::has_attr which was called 3 times, avg 1µs/call:
# 3 times (3µs+0s) by base::import at line 175, avg 1µs/call | ||||
30 | 3 | 500ns | my($proto) = shift; | ||
31 | 3 | 700ns | my($class) = ref $proto || $proto; | ||
32 | 3 | 3µs | return exists $Fattr->{$class}; | ||
33 | } | ||||
34 | |||||
35 | sub get_attr { | ||||
36 | $Fattr->{$_[0]} = [1] unless $Fattr->{$_[0]}; | ||||
37 | return $Fattr->{$_[0]}; | ||||
38 | } | ||||
39 | |||||
40 | 1 | 500ns | if ($] < 5.009) { | ||
41 | *get_fields = sub { | ||||
42 | # Shut up a possible typo warning. | ||||
43 | () = \%{$_[0].'::FIELDS'}; | ||||
44 | my $f = \%{$_[0].'::FIELDS'}; | ||||
45 | |||||
46 | # should be centralized in fields? perhaps | ||||
47 | # fields::mk_FIELDS_be_OK. Peh. As long as %{ $package . '::FIELDS' } | ||||
48 | # is used here anyway, it doesn't matter. | ||||
49 | bless $f, 'pseudohash' if (ref($f) ne 'pseudohash'); | ||||
50 | |||||
51 | return $f; | ||||
52 | } | ||||
53 | } | ||||
54 | else { | ||||
55 | *get_fields = sub { | ||||
56 | # Shut up a possible typo warning. | ||||
57 | () = \%{$_[0].'::FIELDS'}; | ||||
58 | return \%{$_[0].'::FIELDS'}; | ||||
59 | } | ||||
60 | 1 | 2µs | } | ||
61 | |||||
62 | 1 | 200ns | if ($] < 5.008) { | ||
63 | *_module_to_filename = sub { | ||||
64 | (my $fn = $_[0]) =~ s!::!/!g; | ||||
65 | $fn .= '.pm'; | ||||
66 | return $fn; | ||||
67 | } | ||||
68 | } | ||||
69 | else { | ||||
70 | # spent 17µs (12+4) within base::__ANON__[/usr/lib/x86_64-linux-gnu/perl-base/base.pm:75] which was called 3 times, avg 6µs/call:
# 3 times (12µs+4µs) by base::import at line 101, avg 6µs/call | ||||
71 | 3 | 7µs | 3 | 2µs | (my $fn = $_[0]) =~ s!::!/!g; # spent 2µs making 3 calls to base::CORE:subst, avg 833ns/call |
72 | 3 | 900ns | $fn .= '.pm'; | ||
73 | 3 | 5µs | 3 | 2µs | utf8::encode($fn); # spent 2µs making 3 calls to utf8::encode, avg 600ns/call |
74 | 3 | 4µs | return $fn; | ||
75 | } | ||||
76 | 1 | 800ns | } | ||
77 | |||||
78 | # spent 99µs (70+29) within base::import which was called 3 times, avg 33µs/call:
# once (28µs+13µs) by ExtUtils::MakeMaker::Locale::BEGIN@8 at line 8 of ExtUtils/MakeMaker/Locale.pm
# once (25µs+10µs) by YAML::XS::BEGIN@6 at line 6 of YAML/XS.pm
# once (18µs+7µs) by YAML::XS::LibYAML::BEGIN@8 at line 8 of YAML/XS/LibYAML.pm | ||||
79 | 3 | 1µs | my $class = shift; | ||
80 | |||||
81 | 3 | 600ns | return SUCCESS unless @_; | ||
82 | |||||
83 | # List of base classes from which we will inherit %FIELDS. | ||||
84 | 3 | 400ns | my $fields_base; | ||
85 | |||||
86 | 3 | 1µs | my $inheritor = caller(0); | ||
87 | |||||
88 | 3 | 400ns | my @bases; | ||
89 | 3 | 1µs | foreach my $base (@_) { | ||
90 | 3 | 700ns | if ( $inheritor eq $base ) { | ||
91 | warn "Class '$inheritor' tried to inherit from itself\n"; | ||||
92 | } | ||||
93 | |||||
94 | 3 | 19µs | 3 | 3µs | next if grep $_->isa($base), ($inheritor, @bases); # spent 3µs making 3 calls to UNIVERSAL::isa, avg 1µs/call |
95 | |||||
96 | # Following blocks help isolate $SIG{__DIE__} and @INC changes | ||||
97 | { | ||||
98 | 6 | 800ns | my $sigdie; | ||
99 | { | ||||
100 | 6 | 4µs | local $SIG{__DIE__}; | ||
101 | 3 | 4µs | 3 | 17µs | my $fn = _module_to_filename($base); # spent 17µs making 3 calls to base::__ANON__[base.pm:75], avg 6µs/call |
102 | 3 | 200ns | my $dot_hidden; | ||
103 | 3 | 700ns | eval { | ||
104 | 3 | 200ns | my $guard; | ||
105 | 3 | 700ns | if ($INC[-1] eq '.' && %{"$base\::"}) { | ||
106 | # So: the package already exists => this an optional load | ||||
107 | # And: there is a dot at the end of @INC => we want to hide it | ||||
108 | # However: we only want to hide it during our *own* require() | ||||
109 | # (i.e. without affecting nested require()s). | ||||
110 | # So we add a hook to @INC whose job is to hide the dot, but which | ||||
111 | # first checks checks the callstack depth, because within nested | ||||
112 | # require()s the callstack is deeper. | ||||
113 | # Since CORE::GLOBAL::require makes it unknowable in advance what | ||||
114 | # the exact relevant callstack depth will be, we have to record it | ||||
115 | # inside a hook. So we put another hook just for that at the front | ||||
116 | # of @INC, where it's guaranteed to run -- immediately. | ||||
117 | # The dot-hiding hook does its job by sitting directly in front of | ||||
118 | # the dot and removing itself from @INC when reached. This causes | ||||
119 | # the dot to move up one index in @INC, causing the loop inside | ||||
120 | # pp_require() to skip it. | ||||
121 | # Loaded coded may disturb this precise arrangement, but that's OK | ||||
122 | # because the hook is inert by that time. It is only active during | ||||
123 | # the top-level require(), when @INC is in our control. The only | ||||
124 | # possible gotcha is if other hooks already in @INC modify @INC in | ||||
125 | # some way during that initial require(). | ||||
126 | # Note that this jiggery hookery works just fine recursively: if | ||||
127 | # a module loaded via base.pm uses base.pm itself, there will be | ||||
128 | # one pair of hooks in @INC per base::import call frame, but the | ||||
129 | # pairs from different nestings do not interfere with each other. | ||||
130 | my $lvl; | ||||
131 | unshift @INC, sub { return if defined $lvl; 1 while defined caller ++$lvl; () }; | ||||
132 | splice @INC, -1, 0, sub { return if defined caller $lvl; ++$dot_hidden, &base::__inc::unhook; () }; | ||||
133 | $guard = bless [ @INC[0,-2] ], 'base::__inc::scope_guard'; | ||||
134 | } | ||||
135 | 3 | 1µs | require $fn | ||
136 | }; | ||||
137 | 3 | 400ns | if ($dot_hidden && (my @fn = grep -e && !( -d _ || -b _ ), $fn.'c', $fn)) { | ||
138 | require Carp; | ||||
139 | Carp::croak(<<ERROR); | ||||
140 | Base class package "$base" is not empty but "$fn[0]" exists in the current directory. | ||||
141 | To help avoid security issues, base.pm now refuses to load optional modules | ||||
142 | from the current working directory when it is the last entry in \@INC. | ||||
143 | If your software worked on previous versions of Perl, the best solution | ||||
144 | is to use FindBin to detect the path properly and to add that path to | ||||
145 | \@INC. As a last resort, you can re-enable looking in the current working | ||||
146 | directory by adding "use lib '.'" to your code. | ||||
147 | ERROR | ||||
148 | } | ||||
149 | # Only ignore "Can't locate" errors from our eval require. | ||||
150 | # Other fatal errors (syntax etc) must be reported. | ||||
151 | # | ||||
152 | # changing the check here is fragile - if the check | ||||
153 | # here isn't catching every error you want, you should | ||||
154 | # probably be using parent.pm, which doesn't try to | ||||
155 | # guess whether require is needed or failed, | ||||
156 | # see [perl #118561] | ||||
157 | 3 | 5µs | 3 | 700ns | die if $@ && $@ !~ /^Can't locate \Q$fn\E .*? at .* line [0-9]+(?:, <[^>]*> (?:line|chunk) [0-9]+)?\.\n\z/s # spent 700ns making 3 calls to base::CORE:match, avg 233ns/call |
158 | || $@ =~ /Compilation failed in require at .* line [0-9]+(?:, <[^>]*> (?:line|chunk) [0-9]+)?\.\n\z/; | ||||
159 | 3 | 2µs | unless (%{"$base\::"}) { | ||
160 | require Carp; | ||||
161 | local $" = " "; | ||||
162 | Carp::croak(<<ERROR); | ||||
163 | Base class package "$base" is empty. | ||||
164 | (Perhaps you need to 'use' the module which defines that package first, | ||||
165 | or make that module available in \@INC (\@INC contains: @INC). | ||||
166 | ERROR | ||||
167 | } | ||||
168 | 3 | 5µs | $sigdie = $SIG{__DIE__} || undef; | ||
169 | } | ||||
170 | # Make sure a global $SIG{__DIE__} makes it out of the localization. | ||||
171 | 3 | 800ns | $SIG{__DIE__} = $sigdie if defined $sigdie; | ||
172 | } | ||||
173 | 3 | 1µs | push @bases, $base; | ||
174 | |||||
175 | 3 | 5µs | 6 | 9µs | if ( has_fields($base) || has_attr($base) ) { # spent 5µs making 3 calls to base::has_fields, avg 2µs/call
# spent 3µs making 3 calls to base::has_attr, avg 1µs/call |
176 | # No multiple fields inheritance *suck* | ||||
177 | if ($fields_base) { | ||||
178 | require Carp; | ||||
179 | Carp::croak("Can't multiply inherit fields"); | ||||
180 | } else { | ||||
181 | $fields_base = $base; | ||||
182 | } | ||||
183 | } | ||||
184 | } | ||||
185 | # Save this until the end so it's all or nothing if the above loop croaks. | ||||
186 | 3 | 15µs | push @{"$inheritor\::ISA"}, @bases; | ||
187 | |||||
188 | 3 | 5µs | if( defined $fields_base ) { | ||
189 | inherit_fields($inheritor, $fields_base); | ||||
190 | } | ||||
191 | } | ||||
192 | |||||
193 | sub inherit_fields { | ||||
194 | my($derived, $base) = @_; | ||||
195 | |||||
196 | return SUCCESS unless $base; | ||||
197 | |||||
198 | my $battr = get_attr($base); | ||||
199 | my $dattr = get_attr($derived); | ||||
200 | my $dfields = get_fields($derived); | ||||
201 | my $bfields = get_fields($base); | ||||
202 | |||||
203 | $dattr->[0] = @$battr; | ||||
204 | |||||
205 | if( keys %$dfields ) { | ||||
206 | warn <<"END"; | ||||
207 | $derived is inheriting from $base but already has its own fields! | ||||
208 | This will cause problems. Be sure you use base BEFORE declaring fields. | ||||
209 | END | ||||
210 | |||||
211 | } | ||||
212 | |||||
213 | # Iterate through the base's fields adding all the non-private | ||||
214 | # ones to the derived class. Hang on to the original attribute | ||||
215 | # (Public, Private, etc...) and add Inherited. | ||||
216 | # This is all too complicated to do efficiently with add_fields(). | ||||
217 | while (my($k,$v) = each %$bfields) { | ||||
218 | my $fno; | ||||
219 | if ($fno = $dfields->{$k} and $fno != $v) { | ||||
220 | require Carp; | ||||
221 | Carp::croak ("Inherited fields can't override existing fields"); | ||||
222 | } | ||||
223 | |||||
224 | if( $battr->[$v] & PRIVATE ) { | ||||
225 | $dattr->[$v] = PRIVATE | INHERITED; | ||||
226 | } | ||||
227 | else { | ||||
228 | $dattr->[$v] = INHERITED | $battr->[$v]; | ||||
229 | $dfields->{$k} = $v; | ||||
230 | } | ||||
231 | } | ||||
232 | |||||
233 | foreach my $idx (1..$#{$battr}) { | ||||
234 | next if defined $dattr->[$idx]; | ||||
235 | $dattr->[$idx] = $battr->[$idx] & INHERITED; | ||||
236 | } | ||||
237 | } | ||||
238 | |||||
239 | 1 | 4µs | 1; | ||
240 | |||||
241 | __END__ | ||||
# spent 700ns within base::CORE:match which was called 3 times, avg 233ns/call:
# 3 times (700ns+0s) by base::import at line 157, avg 233ns/call | |||||
# spent 2µs within base::CORE:subst which was called 3 times, avg 833ns/call:
# 3 times (2µs+0s) by base::__ANON__[/usr/lib/x86_64-linux-gnu/perl-base/base.pm:75] at line 71, avg 833ns/call |