Filename | /usr/share/perl5/vendor_perl/Carp.pm |
Statements | Executed 922 statements in 6.40ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
40 | 2 | 1 | 867µs | 1.23ms | caller_info | Carp::
2 | 1 | 1 | 349µs | 1.58ms | ret_backtrace | Carp::
48 | 3 | 1 | 145µs | 145µs | _cgc | Carp::
4 | 1 | 1 | 109µs | 138µs | format_arg | Carp::
38 | 1 | 1 | 104µs | 108µs | get_subname | Carp::
2 | 1 | 1 | 40µs | 56µs | long_error_loc | Carp::
1 | 1 | 1 | 32µs | 32µs | BEGIN@3 | Carp::
2 | 1 | 1 | 30µs | 1.72ms | confess | Carp::
2 | 1 | 1 | 24µs | 1.69ms | longmess | Carp::
6 | 2 | 1 | 24µs | 24µs | str_len_trim | Carp::
1 | 1 | 1 | 24µs | 45µs | BEGIN@399 | Carp::
2 | 1 | 1 | 19µs | 1.66ms | longmess_heavy | Carp::
1 | 1 | 1 | 18µs | 49µs | BEGIN@398 | Carp::
1 | 1 | 1 | 18µs | 36µs | BEGIN@406 | Carp::
1 | 1 | 1 | 16µs | 37µs | BEGIN@67 | Carp::
1 | 1 | 1 | 15µs | 41µs | BEGIN@4 | Carp::
1 | 1 | 1 | 15µs | 23µs | BEGIN@5 | Carp::
1 | 1 | 1 | 14µs | 34µs | BEGIN@18 | Carp::
1 | 1 | 1 | 14µs | 34µs | BEGIN@413 | Carp::
1 | 1 | 1 | 14µs | 14µs | BEGIN@7 | Carp::
1 | 1 | 1 | 13µs | 37µs | BEGIN@8 | Carp::
1 | 1 | 1 | 13µs | 13µs | BEGIN@105 | Carp::
1 | 1 | 1 | 11µs | 11µs | BEGIN@17 | Carp::
0 | 0 | 0 | 0s | 0s | __ANON__[:13] | Carp::
0 | 0 | 0 | 0s | 0s | __ANON__[:23] | Carp::
0 | 0 | 0 | 0s | 0s | carp | Carp::
0 | 0 | 0 | 0s | 0s | cluck | Carp::
0 | 0 | 0 | 0s | 0s | croak | Carp::
0 | 0 | 0 | 0s | 0s | export_fail | Carp::
0 | 0 | 0 | 0s | 0s | get_status | Carp::
0 | 0 | 0 | 0s | 0s | ret_summary | Carp::
0 | 0 | 0 | 0s | 0s | short_error_loc | Carp::
0 | 0 | 0 | 0s | 0s | shortmess | Carp::
0 | 0 | 0 | 0s | 0s | shortmess_heavy | Carp::
0 | 0 | 0 | 0s | 0s | trusts | Carp::
0 | 0 | 0 | 0s | 0s | trusts_directly | Carp::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package Carp; | ||||
2 | |||||
3 | 3 | 96µs | 1 | 32µs | # spent 32µs within Carp::BEGIN@3 which was called:
# once (32µs+0s) by CGI::Carp::BEGIN@334 at line 3 # spent 32µs making 1 call to Carp::BEGIN@3 |
4 | 2 | 47µs | 2 | 66µs | # spent 41µs (15+26) within Carp::BEGIN@4 which was called:
# once (15µs+26µs) by CGI::Carp::BEGIN@334 at line 4 # spent 41µs making 1 call to Carp::BEGIN@4
# spent 26µs making 1 call to strict::import |
5 | 2 | 54µs | 2 | 32µs | # spent 23µs (15+8) within Carp::BEGIN@5 which was called:
# once (15µs+8µs) by CGI::Carp::BEGIN@334 at line 5 # spent 23µs making 1 call to Carp::BEGIN@5
# spent 8µs making 1 call to warnings::import |
6 | |||||
7 | # spent 14µs within Carp::BEGIN@7 which was called:
# once (14µs+0s) by CGI::Carp::BEGIN@334 at line 15 | ||||
8 | 2 | 159µs | 2 | 61µs | # spent 37µs (13+24) within Carp::BEGIN@8 which was called:
# once (13µs+24µs) by CGI::Carp::BEGIN@334 at line 8 # spent 37µs making 1 call to Carp::BEGIN@8
# spent 24µs making 1 call to strict::unimport |
9 | 1 | 20µs | if(exists($::{"utf8::"}) && exists(*{$::{"utf8::"}}{HASH}->{"is_utf8"}) && | ||
10 | defined(*{*{$::{"utf8::"}}{HASH}->{"is_utf8"}}{CODE})) { | ||||
11 | *is_utf8 = \&{"utf8::is_utf8"}; | ||||
12 | } else { | ||||
13 | *is_utf8 = sub { 0 }; | ||||
14 | } | ||||
15 | 1 | 54µs | 1 | 14µs | } # spent 14µs making 1 call to Carp::BEGIN@7 |
16 | |||||
17 | # spent 11µs within Carp::BEGIN@17 which was called:
# once (11µs+0s) by CGI::Carp::BEGIN@334 at line 25 | ||||
18 | 2 | 141µs | 2 | 53µs | # spent 34µs (14+20) within Carp::BEGIN@18 which was called:
# once (14µs+20µs) by CGI::Carp::BEGIN@334 at line 18 # spent 34µs making 1 call to Carp::BEGIN@18
# spent 20µs making 1 call to strict::unimport |
19 | 1 | 19µs | if(exists($::{"utf8::"}) && exists(*{$::{"utf8::"}}{HASH}->{"downgrade"}) && | ||
20 | defined(*{*{$::{"utf8::"}}{HASH}->{"downgrade"}}{CODE})) { | ||||
21 | *downgrade = \&{"utf8::downgrade"}; | ||||
22 | } else { | ||||
23 | *downgrade = sub {}; | ||||
24 | } | ||||
25 | 1 | 371µs | 1 | 11µs | } # spent 11µs making 1 call to Carp::BEGIN@17 |
26 | |||||
27 | 1 | 1µs | our $VERSION = '1.26'; | ||
28 | |||||
29 | 1 | 400ns | our $MaxEvalLen = 0; | ||
30 | 1 | 200ns | our $Verbose = 0; | ||
31 | 1 | 200ns | our $CarpLevel = 0; | ||
32 | 1 | 200ns | our $MaxArgLen = 64; # How much of each argument to print. 0 = all. | ||
33 | 1 | 200ns | our $MaxArgNums = 8; # How many arguments to print. 0 = all. | ||
34 | |||||
35 | 1 | 900ns | require Exporter; | ||
36 | 1 | 13µs | our @ISA = ('Exporter'); | ||
37 | 1 | 2µs | our @EXPORT = qw(confess croak carp); | ||
38 | 1 | 1µs | our @EXPORT_OK = qw(cluck verbose longmess shortmess); | ||
39 | 1 | 1µs | our @EXPORT_FAIL = qw(verbose); # hook to enable verbose mode | ||
40 | |||||
41 | # The members of %Internal are packages that are internal to perl. | ||||
42 | # Carp will not report errors from within these packages if it | ||||
43 | # can. The members of %CarpInternal are internal to Perl's warning | ||||
44 | # system. Carp will not report errors from within these packages | ||||
45 | # either, and will not report calls *to* these packages for carp and | ||||
46 | # croak. They replace $CarpLevel, which is deprecated. The | ||||
47 | # $Max(EvalLen|(Arg(Len|Nums)) variables are used to specify how the eval | ||||
48 | # text and function arguments should be formatted when printed. | ||||
49 | |||||
50 | 1 | 300ns | our %CarpInternal; | ||
51 | 1 | 100ns | our %Internal; | ||
52 | |||||
53 | # disable these by default, so they can live w/o require Carp | ||||
54 | 1 | 3µs | $CarpInternal{Carp}++; | ||
55 | 1 | 600ns | $CarpInternal{warnings}++; | ||
56 | 1 | 700ns | $Internal{Exporter}++; | ||
57 | 1 | 400ns | $Internal{'Exporter::Heavy'}++; | ||
58 | |||||
59 | # if the caller specifies verbose usage ("perl -MCarp=verbose script.pl") | ||||
60 | # then the following method will be called by the Exporter which knows | ||||
61 | # to do this thanks to @EXPORT_FAIL, above. $_[1] will contain the word | ||||
62 | # 'verbose'. | ||||
63 | |||||
64 | sub export_fail { shift; $Verbose = shift if $_[0] eq 'verbose'; @_ } | ||||
65 | |||||
66 | sub _cgc { | ||||
67 | 2 | 582µs | 2 | 59µs | # spent 37µs (16+22) within Carp::BEGIN@67 which was called:
# once (16µs+22µs) by CGI::Carp::BEGIN@334 at line 67 # spent 37µs making 1 call to Carp::BEGIN@67
# spent 22µs making 1 call to strict::unimport |
68 | 48 | 107µs | return \&{"CORE::GLOBAL::caller"} if defined &{"CORE::GLOBAL::caller"}; | ||
69 | 48 | 115µs | return; | ||
70 | } | ||||
71 | |||||
72 | # spent 1.69ms (24µs+1.67) within Carp::longmess which was called 2 times, avg 846µs/call:
# 2 times (24µs+1.67ms) by Carp::confess at line 101, avg 846µs/call | ||||
73 | # Icky backwards compatibility wrapper. :-( | ||||
74 | # | ||||
75 | # The story is that the original implementation hard-coded the | ||||
76 | # number of call levels to go back, so calls to longmess were off | ||||
77 | # by one. Other code began calling longmess and expecting this | ||||
78 | # behaviour, so the replacement has to emulate that behaviour. | ||||
79 | 2 | 3µs | 2 | 10µs | my $cgc = _cgc(); # spent 10µs making 2 calls to Carp::_cgc, avg 5µs/call |
80 | 2 | 4µs | my $call_pack = $cgc ? $cgc->() : caller(); | ||
81 | 2 | 16µs | 2 | 1.66ms | if ( $Internal{$call_pack} or $CarpInternal{$call_pack} ) { # spent 1.66ms making 2 calls to Carp::longmess_heavy, avg 828µs/call |
82 | return longmess_heavy(@_); | ||||
83 | } | ||||
84 | else { | ||||
85 | local $CarpLevel = $CarpLevel + 1; | ||||
86 | return longmess_heavy(@_); | ||||
87 | } | ||||
88 | } | ||||
89 | |||||
90 | 1 | 200ns | our @CARP_NOT; | ||
91 | |||||
92 | sub shortmess { | ||||
93 | my $cgc = _cgc(); | ||||
94 | |||||
95 | # Icky backwards compatibility wrapper. :-( | ||||
96 | local @CARP_NOT = $cgc ? $cgc->() : caller(); | ||||
97 | shortmess_heavy(@_); | ||||
98 | } | ||||
99 | |||||
100 | sub croak { die shortmess @_ } | ||||
101 | 2 | 56µs | 2 | 1.69ms | # spent 1.72ms (30µs+1.69) within Carp::confess which was called 2 times, avg 861µs/call:
# 2 times (30µs+1.69ms) by JSON::BEGIN@2 or JSON::_load_xs at line 2 of (eval 12)[JSON.pm:252], avg 861µs/call # spent 1.69ms making 2 calls to Carp::longmess, avg 846µs/call |
102 | sub carp { warn shortmess @_ } | ||||
103 | sub cluck { warn longmess @_ } | ||||
104 | |||||
105 | # spent 13µs within Carp::BEGIN@105 which was called:
# once (13µs+0s) by CGI::Carp::BEGIN@334 at line 112 | ||||
106 | 1 | 14µs | if("$]" >= 5.015002 || ("$]" >= 5.014002 && "$]" < 5.015) || | ||
107 | ("$]" >= 5.012005 && "$]" < 5.013)) { | ||||
108 | *CALLER_OVERRIDE_CHECK_OK = sub () { 1 }; | ||||
109 | } else { | ||||
110 | *CALLER_OVERRIDE_CHECK_OK = sub () { 0 }; | ||||
111 | } | ||||
112 | 1 | 2.63ms | 1 | 13µs | } # spent 13µs making 1 call to Carp::BEGIN@105 |
113 | |||||
114 | sub caller_info { | ||||
115 | 40 | 22µs | my $i = shift(@_) + 1; | ||
116 | 40 | 6µs | my %call_info; | ||
117 | 40 | 39µs | 40 | 119µs | my $cgc = _cgc(); # spent 119µs making 40 calls to Carp::_cgc, avg 3µs/call |
118 | { | ||||
119 | # Some things override caller() but forget to implement the | ||||
120 | # @DB::args part of it, which we need. We check for this by | ||||
121 | # pre-populating @DB::args with a sentinel which no-one else | ||||
122 | # has the address of, so that we can detect whether @DB::args | ||||
123 | # has been properly populated. However, on earlier versions | ||||
124 | # of perl this check tickles a bug in CORE::caller() which | ||||
125 | # leaks memory. So we only check on fixed perls. | ||||
126 | 80 | 83µs | @DB::args = \$i if CALLER_OVERRIDE_CHECK_OK; | ||
127 | package DB; | ||||
128 | |||||
129 | 40 | 259µs | |||
- - | |||||
133 | 40 | 20µs | unless ( defined $call_info{pack} ) { | ||
134 | return (); | ||||
135 | } | ||||
136 | |||||
137 | 38 | 57µs | 38 | 108µs | my $sub_name = Carp::get_subname( \%call_info ); # spent 108µs making 38 calls to Carp::get_subname, avg 3µs/call |
138 | 38 | 14µs | if ( $call_info{has_args} ) { | ||
139 | 15 | 3µs | my @args; | ||
140 | 15 | 12µs | if (CALLER_OVERRIDE_CHECK_OK && @DB::args == 1 | ||
141 | && ref $DB::args[0] eq ref \$i | ||||
142 | && $DB::args[0] == \$i ) { | ||||
143 | @DB::args = (); # Don't let anyone see the address of $i | ||||
144 | local $@; | ||||
145 | my $where = eval { | ||||
146 | my $func = $cgc or return ''; | ||||
147 | my $gv = | ||||
148 | *{ | ||||
149 | ( $::{"B::"} || return '') # B stash | ||||
150 | ->{svref_2object} || return '' # entry in stash | ||||
151 | }{CODE} # coderef in entry | ||||
152 | ->($func)->GV; | ||||
153 | my $package = $gv->STASH->NAME; | ||||
154 | my $subname = $gv->NAME; | ||||
155 | return unless defined $package && defined $subname; | ||||
156 | |||||
157 | # returning CORE::GLOBAL::caller isn't useful for tracing the cause: | ||||
158 | return if $package eq 'CORE::GLOBAL' && $subname eq 'caller'; | ||||
159 | " in &${package}::$subname"; | ||||
160 | } || ''; | ||||
161 | @args | ||||
162 | = "** Incomplete caller override detected$where; \@DB::args were not set **"; | ||||
163 | } | ||||
164 | else { | ||||
165 | 19 | 24µs | 4 | 138µs | @args = map { Carp::format_arg($_) } @DB::args; # spent 138µs making 4 calls to Carp::format_arg, avg 35µs/call |
166 | } | ||||
167 | 15 | 7µs | if ( $MaxArgNums and @args > $MaxArgNums ) | ||
168 | { # More than we want to show? | ||||
169 | $#args = $MaxArgNums; | ||||
170 | push @args, '...'; | ||||
171 | } | ||||
172 | |||||
173 | # Push the args onto the subroutine | ||||
174 | 15 | 18µs | $sub_name .= '(' . join( ', ', @args ) . ')'; | ||
175 | } | ||||
176 | 38 | 24µs | $call_info{sub_name} = $sub_name; | ||
177 | 38 | 223µs | return wantarray() ? %call_info : \%call_info; | ||
178 | } | ||||
179 | |||||
180 | # Transform an argument to a function into a string. | ||||
181 | # spent 138µs (109+30) within Carp::format_arg which was called 4 times, avg 35µs/call:
# 4 times (109µs+30µs) by Carp::caller_info at line 165, avg 35µs/call | ||||
182 | 4 | 5µs | my $arg = shift; | ||
183 | 4 | 900ns | if ( ref($arg) ) { | ||
184 | $arg = defined($overload::VERSION) ? overload::StrVal($arg) : "$arg"; | ||||
185 | } | ||||
186 | 4 | 2µs | if ( defined($arg) ) { | ||
187 | 4 | 18µs | $arg =~ s/'/\\'/g; | ||
188 | 4 | 7µs | 4 | 20µs | $arg = str_len_trim( $arg, $MaxArgLen ); # spent 20µs making 4 calls to Carp::str_len_trim, avg 5µs/call |
189 | |||||
190 | # Quote it? | ||||
191 | # Downgrade, and use [0-9] rather than \d, to avoid loading | ||||
192 | # Unicode tables, which would be liable to fail if we're | ||||
193 | # processing a syntax error. | ||||
194 | 4 | 17µs | 4 | 6µs | downgrade($arg, 1); # spent 6µs making 4 calls to utf8::downgrade, avg 1µs/call |
195 | 4 | 14µs | $arg = "'$arg'" unless $arg =~ /^-?[0-9.]+\z/; | ||
196 | } | ||||
197 | else { | ||||
198 | $arg = 'undef'; | ||||
199 | } | ||||
200 | |||||
201 | # The following handling of "control chars" is direct from | ||||
202 | # the original code - it is broken on Unicode though. | ||||
203 | # Suggestions? | ||||
204 | is_utf8($arg) | ||||
205 | 4 | 42µs | 4 | 4µs | or $arg =~ s/([[:cntrl:]]|[[:^ascii:]])/sprintf("\\x{%x}",ord($1))/eg; # spent 4µs making 4 calls to utf8::is_utf8, avg 900ns/call |
206 | 4 | 16µs | return $arg; | ||
207 | } | ||||
208 | |||||
209 | # Takes an inheritance cache and a package and returns | ||||
210 | # an anon hash of known inheritances and anon array of | ||||
211 | # inheritances which consequences have not been figured | ||||
212 | # for. | ||||
213 | sub get_status { | ||||
214 | my $cache = shift; | ||||
215 | my $pkg = shift; | ||||
216 | $cache->{$pkg} ||= [ { $pkg => $pkg }, [ trusts_directly($pkg) ] ]; | ||||
217 | return @{ $cache->{$pkg} }; | ||||
218 | } | ||||
219 | |||||
220 | # Takes the info from caller() and figures out the name of | ||||
221 | # the sub/require/eval | ||||
222 | # spent 108µs (104+4) within Carp::get_subname which was called 38 times, avg 3µs/call:
# 38 times (104µs+4µs) by Carp::caller_info at line 137, avg 3µs/call | ||||
223 | 38 | 11µs | my $info = shift; | ||
224 | 38 | 14µs | if ( defined( $info->{evaltext} ) ) { | ||
225 | 12 | 4µs | my $eval = $info->{evaltext}; | ||
226 | 12 | 31µs | if ( $info->{is_require} ) { | ||
227 | return "require $eval"; | ||||
228 | } | ||||
229 | else { | ||||
230 | 2 | 2µs | $eval =~ s/([\\\'])/\\$1/g; | ||
231 | 2 | 9µs | 2 | 4µs | return "eval '" . str_len_trim( $eval, $MaxEvalLen ) . "'"; # spent 4µs making 2 calls to Carp::str_len_trim, avg 2µs/call |
232 | } | ||||
233 | } | ||||
234 | |||||
235 | 26 | 74µs | return ( $info->{sub} eq '(eval)' ) ? 'eval {...}' : $info->{sub}; | ||
236 | } | ||||
237 | |||||
238 | # Figures out what call (from the point of view of the caller) | ||||
239 | # the long error backtrace should start at. | ||||
240 | # spent 56µs (40+16) within Carp::long_error_loc which was called 2 times, avg 28µs/call:
# 2 times (40µs+16µs) by Carp::longmess_heavy at line 270, avg 28µs/call | ||||
241 | 2 | 500ns | my $i; | ||
242 | 2 | 1µs | my $lvl = $CarpLevel; | ||
243 | { | ||||
244 | 8 | 2µs | ++$i; | ||
245 | 6 | 6µs | 6 | 16µs | my $cgc = _cgc(); # spent 16µs making 6 calls to Carp::_cgc, avg 3µs/call |
246 | 6 | 9µs | my $pkg = $cgc ? $cgc->($i) : caller($i); | ||
247 | 6 | 1µs | unless ( defined($pkg) ) { | ||
248 | |||||
249 | # This *shouldn't* happen. | ||||
250 | if (%Internal) { | ||||
251 | local %Internal; | ||||
252 | $i = long_error_loc(); | ||||
253 | last; | ||||
254 | } | ||||
255 | else { | ||||
256 | |||||
257 | # OK, now I am irritated. | ||||
258 | return 2; | ||||
259 | } | ||||
260 | } | ||||
261 | 6 | 5µs | redo if $CarpInternal{$pkg}; | ||
262 | 2 | 1µs | redo unless 0 > --$lvl; | ||
263 | 2 | 2µs | redo if $Internal{$pkg}; | ||
264 | } | ||||
265 | 2 | 7µs | return $i - 1; | ||
266 | } | ||||
267 | |||||
268 | # spent 1.66ms (19µs+1.64) within Carp::longmess_heavy which was called 2 times, avg 828µs/call:
# 2 times (19µs+1.64ms) by Carp::longmess at line 81, avg 828µs/call | ||||
269 | 2 | 800ns | return @_ if ref( $_[0] ); # don't break references as exceptions | ||
270 | 2 | 3µs | 2 | 56µs | my $i = long_error_loc(); # spent 56µs making 2 calls to Carp::long_error_loc, avg 28µs/call |
271 | 2 | 10µs | 2 | 1.58ms | return ret_backtrace( $i, @_ ); # spent 1.58ms making 2 calls to Carp::ret_backtrace, avg 791µs/call |
272 | } | ||||
273 | |||||
274 | # Returns a full stack backtrace starting from where it is | ||||
275 | # told. | ||||
276 | # spent 1.58ms (349µs+1.23) within Carp::ret_backtrace which was called 2 times, avg 791µs/call:
# 2 times (349µs+1.23ms) by Carp::longmess_heavy at line 271, avg 791µs/call | ||||
277 | 2 | 4µs | my ( $i, @error ) = @_; | ||
278 | 2 | 300ns | my $mess; | ||
279 | 2 | 12µs | my $err = join '', @error; | ||
280 | 2 | 300ns | $i++; | ||
281 | |||||
282 | 2 | 800ns | my $tid_msg = ''; | ||
283 | 2 | 1µs | if ( defined &threads::tid ) { | ||
284 | my $tid = threads->tid; | ||||
285 | $tid_msg = " thread $tid" if $tid; | ||||
286 | } | ||||
287 | |||||
288 | 2 | 12µs | 2 | 205µs | my %i = caller_info($i); # spent 205µs making 2 calls to Carp::caller_info, avg 102µs/call |
289 | 2 | 7µs | $mess = "$err at $i{file} line $i{line}$tid_msg"; | ||
290 | 2 | 2µs | if( defined $. ) { | ||
291 | local $@ = ''; | ||||
292 | local $SIG{__DIE__}; | ||||
293 | eval { | ||||
294 | CORE::die; | ||||
295 | }; | ||||
296 | if($@ =~ /^Died at .*(, <.*?> line \d+).$/ ) { | ||||
297 | $mess .= $1; | ||||
298 | } | ||||
299 | } | ||||
300 | 2 | 700ns | $mess .= "\.\n"; | ||
301 | |||||
302 | 2 | 237µs | 38 | 1.03ms | while ( my %i = caller_info( ++$i ) ) { # spent 1.03ms making 38 calls to Carp::caller_info, avg 27µs/call |
303 | $mess .= "\t$i{sub_name} called at $i{file} line $i{line}$tid_msg\n"; | ||||
304 | } | ||||
305 | |||||
306 | 2 | 17µs | return $mess; | ||
307 | } | ||||
308 | |||||
309 | sub ret_summary { | ||||
310 | my ( $i, @error ) = @_; | ||||
311 | my $err = join '', @error; | ||||
312 | $i++; | ||||
313 | |||||
314 | my $tid_msg = ''; | ||||
315 | if ( defined &threads::tid ) { | ||||
316 | my $tid = threads->tid; | ||||
317 | $tid_msg = " thread $tid" if $tid; | ||||
318 | } | ||||
319 | |||||
320 | my %i = caller_info($i); | ||||
321 | return "$err at $i{file} line $i{line}$tid_msg\.\n"; | ||||
322 | } | ||||
323 | |||||
324 | sub short_error_loc { | ||||
325 | # You have to create your (hash)ref out here, rather than defaulting it | ||||
326 | # inside trusts *on a lexical*, as you want it to persist across calls. | ||||
327 | # (You can default it on $_[2], but that gets messy) | ||||
328 | my $cache = {}; | ||||
329 | my $i = 1; | ||||
330 | my $lvl = $CarpLevel; | ||||
331 | { | ||||
332 | my $cgc = _cgc(); | ||||
333 | my $called = $cgc ? $cgc->($i) : caller($i); | ||||
334 | $i++; | ||||
335 | my $caller = $cgc ? $cgc->($i) : caller($i); | ||||
336 | |||||
337 | return 0 unless defined($caller); # What happened? | ||||
338 | redo if $Internal{$caller}; | ||||
339 | redo if $CarpInternal{$caller}; | ||||
340 | redo if $CarpInternal{$called}; | ||||
341 | redo if trusts( $called, $caller, $cache ); | ||||
342 | redo if trusts( $caller, $called, $cache ); | ||||
343 | redo unless 0 > --$lvl; | ||||
344 | } | ||||
345 | return $i - 1; | ||||
346 | } | ||||
347 | |||||
348 | sub shortmess_heavy { | ||||
349 | return longmess_heavy(@_) if $Verbose; | ||||
350 | return @_ if ref( $_[0] ); # don't break references as exceptions | ||||
351 | my $i = short_error_loc(); | ||||
352 | if ($i) { | ||||
353 | ret_summary( $i, @_ ); | ||||
354 | } | ||||
355 | else { | ||||
356 | longmess_heavy(@_); | ||||
357 | } | ||||
358 | } | ||||
359 | |||||
360 | # If a string is too long, trims it with ... | ||||
361 | sub str_len_trim { | ||||
362 | 6 | 4µs | my $str = shift; | ||
363 | 6 | 2µs | my $max = shift || 0; | ||
364 | 6 | 9µs | if ( 2 < $max and $max < length($str) ) { | ||
365 | substr( $str, $max - 3 ) = '...'; | ||||
366 | } | ||||
367 | 6 | 20µs | return $str; | ||
368 | } | ||||
369 | |||||
370 | # Takes two packages and an optional cache. Says whether the | ||||
371 | # first inherits from the second. | ||||
372 | # | ||||
373 | # Recursive versions of this have to work to avoid certain | ||||
374 | # possible endless loops, and when following long chains of | ||||
375 | # inheritance are less efficient. | ||||
376 | sub trusts { | ||||
377 | my $child = shift; | ||||
378 | my $parent = shift; | ||||
379 | my $cache = shift; | ||||
380 | my ( $known, $partial ) = get_status( $cache, $child ); | ||||
381 | |||||
382 | # Figure out consequences until we have an answer | ||||
383 | while ( @$partial and not exists $known->{$parent} ) { | ||||
384 | my $anc = shift @$partial; | ||||
385 | next if exists $known->{$anc}; | ||||
386 | $known->{$anc}++; | ||||
387 | my ( $anc_knows, $anc_partial ) = get_status( $cache, $anc ); | ||||
388 | my @found = keys %$anc_knows; | ||||
389 | @$known{@found} = (); | ||||
390 | push @$partial, @$anc_partial; | ||||
391 | } | ||||
392 | return exists $known->{$parent}; | ||||
393 | } | ||||
394 | |||||
395 | # Takes a package and gives a list of those trusted directly | ||||
396 | sub trusts_directly { | ||||
397 | my $class = shift; | ||||
398 | 2 | 64µs | 2 | 79µs | # spent 49µs (18+30) within Carp::BEGIN@398 which was called:
# once (18µs+30µs) by CGI::Carp::BEGIN@334 at line 398 # spent 49µs making 1 call to Carp::BEGIN@398
# spent 30µs making 1 call to strict::unimport |
399 | 2 | 131µs | 2 | 67µs | # spent 45µs (24+22) within Carp::BEGIN@399 which was called:
# once (24µs+22µs) by CGI::Carp::BEGIN@334 at line 399 # spent 45µs making 1 call to Carp::BEGIN@399
# spent 22µs making 1 call to warnings::unimport |
400 | return @{"$class\::CARP_NOT"} | ||||
401 | ? @{"$class\::CARP_NOT"} | ||||
402 | : @{"$class\::ISA"}; | ||||
403 | } | ||||
404 | |||||
405 | 1 | 2µs | if(!defined($warnings::VERSION) || | ||
406 | 3 | 73µs | 2 | 54µs | # spent 36µs (18+18) within Carp::BEGIN@406 which was called:
# once (18µs+18µs) by CGI::Carp::BEGIN@334 at line 406 # spent 36µs making 1 call to Carp::BEGIN@406
# spent 18µs making 1 call to warnings::unimport |
407 | # Very old versions of warnings.pm import from Carp. This can go | ||||
408 | # wrong due to the circular dependency. If Carp is invoked before | ||||
409 | # warnings, then Carp starts by loading warnings, then warnings | ||||
410 | # tries to import from Carp, and gets nothing because Carp is in | ||||
411 | # the process of loading and hasn't defined its import method yet. | ||||
412 | # So we work around that by manually exporting to warnings here. | ||||
413 | 2 | 132µs | 2 | 54µs | # spent 34µs (14+20) within Carp::BEGIN@413 which was called:
# once (14µs+20µs) by CGI::Carp::BEGIN@334 at line 413 # spent 34µs making 1 call to Carp::BEGIN@413
# spent 20µs making 1 call to strict::unimport |
414 | *{"warnings::$_"} = \&$_ foreach @EXPORT; | ||||
415 | } | ||||
416 | |||||
417 | 1 | 32µs | 1; | ||
418 | |||||
419 | __END__ |