Filename | /home/ss5/perl5/perlbrew/perls/perl-5.22.0/lib/site_perl/5.22.0/base.pm |
Statements | Executed 641 statements in 1.70ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
19 | 19 | 17 | 3.52ms | 4.07ms | import (recurses: max depth 1, inclusive time 1.25ms) | base::
19 | 1 | 1 | 98µs | 131µs | __ANON__[:72] | base::
19 | 1 | 1 | 49µs | 49µs | has_fields | base::
19 | 1 | 1 | 32µs | 32µs | has_attr | base::
1 | 1 | 1 | 9µs | 9µs | BEGIN@1 | Class::Load::
1 | 1 | 1 | 5µs | 16µs | BEGIN@4 | base::
1 | 1 | 1 | 4µs | 23µs | BEGIN@5 | base::
0 | 0 | 0 | 0s | 0s | __ANON__[:49] | base::
0 | 0 | 0 | 0s | 0s | __ANON__[:56] | base::
0 | 0 | 0 | 0s | 0s | __ANON__[:64] | base::
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 | 9µs | # spent 9µs within Class::Load::BEGIN@1 which was called:
# once (9µs+0s) by Class::Load::BEGIN@9 at line 1 # spent 9µs making 1 call to Class::Load::BEGIN@1 |
2 | package base; | ||||
3 | |||||
4 | 2 | 17µs | 2 | 26µs | # spent 16µs (5+11) within base::BEGIN@4 which was called:
# once (5µs+11µs) by Class::Load::BEGIN@9 at line 4 # spent 16µs making 1 call to base::BEGIN@4
# spent 11µs making 1 call to strict::import |
5 | 2 | 571µs | 2 | 42µs | # spent 23µs (4+19) within base::BEGIN@5 which was called:
# once (4µs+19µs) by Class::Load::BEGIN@9 at line 5 # spent 23µs making 1 call to base::BEGIN@5
# spent 19µs making 1 call to vars::import |
6 | 1 | 400ns | $VERSION = '2.23'; | ||
7 | 1 | 3µs | $VERSION =~ tr/_//d; | ||
8 | |||||
9 | # constant.pm is slow | ||||
10 | sub SUCCESS () { 1 } | ||||
11 | |||||
12 | sub PUBLIC () { 2**0 } | ||||
13 | sub PRIVATE () { 2**1 } | ||||
14 | sub INHERITED () { 2**2 } | ||||
15 | sub PROTECTED () { 2**3 } | ||||
16 | |||||
17 | |||||
18 | 1 | 500ns | my $Fattr = \%fields::attr; | ||
19 | |||||
20 | # spent 49µs within base::has_fields which was called 19 times, avg 3µs/call:
# 19 times (49µs+0s) by base::import at line 127, avg 3µs/call | ||||
21 | 19 | 9µs | my($base) = shift; | ||
22 | 19 | 15µs | my $fglob = ${"$base\::"}{FIELDS}; | ||
23 | 19 | 27µs | return( ($fglob && 'GLOB' eq ref($fglob) && *$fglob{HASH}) ? 1 : 0 ); | ||
24 | } | ||||
25 | |||||
26 | # spent 32µs within base::has_attr which was called 19 times, avg 2µs/call:
# 19 times (32µs+0s) by base::import at line 127, avg 2µs/call | ||||
27 | 19 | 5µs | my($proto) = shift; | ||
28 | 19 | 7µs | my($class) = ref $proto || $proto; | ||
29 | 19 | 28µs | return exists $Fattr->{$class}; | ||
30 | } | ||||
31 | |||||
32 | sub get_attr { | ||||
33 | $Fattr->{$_[0]} = [1] unless $Fattr->{$_[0]}; | ||||
34 | return $Fattr->{$_[0]}; | ||||
35 | } | ||||
36 | |||||
37 | 1 | 700ns | if ($] < 5.009) { | ||
38 | *get_fields = sub { | ||||
39 | # Shut up a possible typo warning. | ||||
40 | () = \%{$_[0].'::FIELDS'}; | ||||
41 | my $f = \%{$_[0].'::FIELDS'}; | ||||
42 | |||||
43 | # should be centralized in fields? perhaps | ||||
44 | # fields::mk_FIELDS_be_OK. Peh. As long as %{ $package . '::FIELDS' } | ||||
45 | # is used here anyway, it doesn't matter. | ||||
46 | bless $f, 'pseudohash' if (ref($f) ne 'pseudohash'); | ||||
47 | |||||
48 | return $f; | ||||
49 | } | ||||
50 | } | ||||
51 | else { | ||||
52 | *get_fields = sub { | ||||
53 | # Shut up a possible typo warning. | ||||
54 | () = \%{$_[0].'::FIELDS'}; | ||||
55 | return \%{$_[0].'::FIELDS'}; | ||||
56 | } | ||||
57 | 1 | 2µs | } | ||
58 | |||||
59 | 1 | 300ns | if ($] < 5.008) { | ||
60 | *_module_to_filename = sub { | ||||
61 | (my $fn = $_[0]) =~ s!::!/!g; | ||||
62 | $fn .= '.pm'; | ||||
63 | return $fn; | ||||
64 | } | ||||
65 | } | ||||
66 | else { | ||||
67 | # spent 131µs (98+32) within base::__ANON__[/home/ss5/perl5/perlbrew/perls/perl-5.22.0/lib/site_perl/5.22.0/base.pm:72] which was called 19 times, avg 7µs/call:
# 19 times (98µs+32µs) by base::import at line 99, avg 7µs/call | ||||
68 | 19 | 57µs | 19 | 20µs | (my $fn = $_[0]) =~ s!::!/!g; # spent 20µs making 19 calls to base::CORE:subst, avg 1µs/call |
69 | 19 | 6µs | $fn .= '.pm'; | ||
70 | 19 | 45µs | 19 | 12µs | utf8::encode($fn); # spent 12µs making 19 calls to utf8::encode, avg 658ns/call |
71 | 19 | 31µs | return $fn; | ||
72 | } | ||||
73 | 1 | 700ns | } | ||
74 | |||||
75 | |||||
76 | # spent 4.07ms (3.52+556µs) within base::import which was called 19 times, avg 214µs/call:
# once (1.45ms+586µs) by BenchmarkAnything::Storage::Backend::SQL::Query::mysql::BEGIN@7 at line 7 of BenchmarkAnything/Storage/Backend/SQL/Query/mysql.pm
# once (228µs+872µs) by SQL::SplitStatement::BEGIN@11 at line 11 of SQL/SplitStatement.pm
# once (266µs+63µs) by Log::Any::Adapter::Null::BEGIN@10 at line 10 of Log/Any/Adapter/Null.pm
# once (44µs+16µs) by JSON::MaybeXS::BEGIN@5 at line 5 of JSON/MaybeXS.pm
# once (37µs+17µs) by IO::Socket::IP::BEGIN@15 at line 15 of IO/Socket/IP.pm
# once (38µs+15µs) by Variable::Magic::BEGIN@688 at line 688 of Variable/Magic.pm
# once (36µs+17µs) by YAML::XS::BEGIN@6 at line 6 of YAML/XS.pm
# once (36µs+15µs) by Class::Load::BEGIN@9 at line 9 of Class/Load.pm
# once (34µs+15µs) by Any::URI::Escape::BEGIN@14 at line 14 of Any/URI/Escape.pm
# once (32µs+15µs) by Class::Method::Modifiers::BEGIN@14 at line 14 of Class/Method/Modifiers.pm
# once (32µs+15µs) by Moose::Meta::TypeConstraint::BEGIN@18 at line 18 of Moose/Meta/TypeConstraint.pm
# once (30µs+12µs) by IO::Socket::IP::_ForINET::BEGIN@1122 at line 1122 of IO/Socket/IP.pm
# once (25µs+8µs) by namespace::clean::_Util::BEGIN@15 at line 15 of namespace/clean/_Util.pm
# once (23µs+8µs) by Log::Any::Adapter::Util::BEGIN@11 at line 11 of Log/Any/Adapter/Util.pm
# once (21µs+9µs) by CHI::Util::BEGIN@14 at line 14 of CHI/Util.pm
# once (23µs+7µs) by YAML::XS::LibYAML::BEGIN@8 at line 8 of YAML/XS/LibYAML.pm
# once (21µs+8µs) by IO::Socket::IP::_ForINET6::BEGIN@1136 at line 1136 of IO/Socket/IP.pm
# once (789µs+-789µs) by Class::Accessor::Fast::BEGIN@2 at line 2 of Class/Accessor/Fast.pm
# once (353µs+-353µs) by BenchmarkAnything::Storage::Backend::SQL::Query::common::BEGIN@7 at line 7 of BenchmarkAnything/Storage/Backend/SQL/Query/common.pm | ||||
77 | 19 | 8µs | my $class = shift; | ||
78 | |||||
79 | 19 | 6µs | return SUCCESS unless @_; | ||
80 | |||||
81 | # List of base classes from which we will inherit %FIELDS. | ||||
82 | 19 | 3µs | my $fields_base; | ||
83 | |||||
84 | 19 | 9µs | my $inheritor = caller(0); | ||
85 | |||||
86 | 19 | 4µs | my @bases; | ||
87 | 19 | 14µs | foreach my $base (@_) { | ||
88 | 19 | 6µs | if ( $inheritor eq $base ) { | ||
89 | warn "Class '$inheritor' tried to inherit from itself\n"; | ||||
90 | } | ||||
91 | |||||
92 | 19 | 139µs | 19 | 28µs | next if grep $_->isa($base), ($inheritor, @bases); # spent 28µs making 19 calls to UNIVERSAL::isa, avg 1µs/call |
93 | |||||
94 | # Following blocks help isolate $SIG{__DIE__} changes | ||||
95 | { | ||||
96 | 38 | 7µs | my $sigdie; | ||
97 | { | ||||
98 | 38 | 37µs | local $SIG{__DIE__}; | ||
99 | 19 | 27µs | 19 | 131µs | my $fn = _module_to_filename($base); # spent 131µs making 19 calls to base::__ANON__[base.pm:72], avg 7µs/call |
100 | 38 | 234µs | eval { require $fn }; | ||
101 | # Only ignore "Can't locate" errors from our eval require. | ||||
102 | # Other fatal errors (syntax etc) must be reported. | ||||
103 | # | ||||
104 | # changing the check here is fragile - if the check | ||||
105 | # here isn't catching every error you want, you should | ||||
106 | # probably be using parent.pm, which doesn't try to | ||||
107 | # guess whether require is needed or failed, | ||||
108 | # see [perl #118561] | ||||
109 | 19 | 37µs | 19 | 4µs | die if $@ && $@ !~ /^Can't locate \Q$fn\E .*? at .* line [0-9]+(?:, <[^>]*> (?:line|chunk) [0-9]+)?\.\n\z/s # spent 4µs making 19 calls to base::CORE:match, avg 237ns/call |
110 | || $@ =~ /Compilation failed in require at .* line [0-9]+(?:, <[^>]*> (?:line|chunk) [0-9]+)?\.\n\z/; | ||||
111 | 19 | 34µs | unless (%{"$base\::"}) { | ||
112 | require Carp; | ||||
113 | local $" = " "; | ||||
114 | Carp::croak(<<ERROR); | ||||
115 | Base class package "$base" is empty. | ||||
116 | (Perhaps you need to 'use' the module which defines that package first, | ||||
117 | or make that module available in \@INC (\@INC contains: @INC). | ||||
118 | ERROR | ||||
119 | } | ||||
120 | 19 | 43µs | $sigdie = $SIG{__DIE__} || undef; | ||
121 | } | ||||
122 | # Make sure a global $SIG{__DIE__} makes it out of the localization. | ||||
123 | 19 | 5µs | $SIG{__DIE__} = $sigdie if defined $sigdie; | ||
124 | } | ||||
125 | 19 | 7µs | push @bases, $base; | ||
126 | |||||
127 | 19 | 48µs | 38 | 81µs | if ( has_fields($base) || has_attr($base) ) { # spent 49µs making 19 calls to base::has_fields, avg 3µs/call
# spent 32µs making 19 calls to base::has_attr, avg 2µs/call |
128 | # No multiple fields inheritance *suck* | ||||
129 | if ($fields_base) { | ||||
130 | require Carp; | ||||
131 | Carp::croak("Can't multiply inherit fields"); | ||||
132 | } else { | ||||
133 | $fields_base = $base; | ||||
134 | } | ||||
135 | } | ||||
136 | } | ||||
137 | # Save this until the end so it's all or nothing if the above loop croaks. | ||||
138 | 19 | 116µs | push @{"$inheritor\::ISA"}, @bases; | ||
139 | |||||
140 | 19 | 52µs | if( defined $fields_base ) { | ||
141 | inherit_fields($inheritor, $fields_base); | ||||
142 | } | ||||
143 | } | ||||
144 | |||||
145 | |||||
146 | sub inherit_fields { | ||||
147 | my($derived, $base) = @_; | ||||
148 | |||||
149 | return SUCCESS unless $base; | ||||
150 | |||||
151 | my $battr = get_attr($base); | ||||
152 | my $dattr = get_attr($derived); | ||||
153 | my $dfields = get_fields($derived); | ||||
154 | my $bfields = get_fields($base); | ||||
155 | |||||
156 | $dattr->[0] = @$battr; | ||||
157 | |||||
158 | if( keys %$dfields ) { | ||||
159 | warn <<"END"; | ||||
160 | $derived is inheriting from $base but already has its own fields! | ||||
161 | This will cause problems. Be sure you use base BEFORE declaring fields. | ||||
162 | END | ||||
163 | |||||
164 | } | ||||
165 | |||||
166 | # Iterate through the base's fields adding all the non-private | ||||
167 | # ones to the derived class. Hang on to the original attribute | ||||
168 | # (Public, Private, etc...) and add Inherited. | ||||
169 | # This is all too complicated to do efficiently with add_fields(). | ||||
170 | while (my($k,$v) = each %$bfields) { | ||||
171 | my $fno; | ||||
172 | if ($fno = $dfields->{$k} and $fno != $v) { | ||||
173 | require Carp; | ||||
174 | Carp::croak ("Inherited fields can't override existing fields"); | ||||
175 | } | ||||
176 | |||||
177 | if( $battr->[$v] & PRIVATE ) { | ||||
178 | $dattr->[$v] = PRIVATE | INHERITED; | ||||
179 | } | ||||
180 | else { | ||||
181 | $dattr->[$v] = INHERITED | $battr->[$v]; | ||||
182 | $dfields->{$k} = $v; | ||||
183 | } | ||||
184 | } | ||||
185 | |||||
186 | foreach my $idx (1..$#{$battr}) { | ||||
187 | next if defined $dattr->[$idx]; | ||||
188 | $dattr->[$idx] = $battr->[$idx] & INHERITED; | ||||
189 | } | ||||
190 | } | ||||
191 | |||||
192 | |||||
193 | 1 | 4µs | 1; | ||
194 | |||||
195 | __END__ |