Filename | /usr/share/perl/5.20/base.pm |
Statements | Executed 1202 statements in 23.6ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
36 | 36 | 28 | 43.0ms | 47.6ms | import (recurses: max depth 2, inclusive time 2.82ms) | base::
36 | 1 | 1 | 235µs | 355µs | __ANON__[:70] | base::
36 | 1 | 1 | 126µs | 126µs | has_fields | base::
36 | 1 | 1 | 91µs | 91µs | has_attr | base::
36 | 1 | 1 | 77µs | 77µs | CORE:subst (opcode) | base::
4 | 1 | 1 | 69µs | 69µs | CORE:regcomp (opcode) | base::
40 | 1 | 1 | 38µs | 38µs | CORE:match (opcode) | base::
1 | 1 | 1 | 17µs | 30µs | BEGIN@3 | base::
1 | 1 | 1 | 7µs | 30µs | BEGIN@4 | base::
0 | 0 | 0 | 0s | 0s | __ANON__[:47] | base::
0 | 0 | 0 | 0s | 0s | __ANON__[:54] | base::
0 | 0 | 0 | 0s | 0s | __ANON__[:62] | 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 | package base; | ||||
2 | |||||
3 | 2 | 30µs | 2 | 43µs | # spent 30µs (17+13) within base::BEGIN@3 which was called:
# once (17µs+13µs) by C4::Boolean::BEGIN@28 at line 3 # spent 30µs making 1 call to base::BEGIN@3
# spent 13µs making 1 call to strict::import |
4 | 2 | 975µs | 2 | 54µs | # spent 30µs (7+23) within base::BEGIN@4 which was called:
# once (7µs+23µs) by C4::Boolean::BEGIN@28 at line 4 # spent 30µs making 1 call to base::BEGIN@4
# spent 23µs making 1 call to vars::import |
5 | 1 | 500ns | $VERSION = '2.22'; | ||
6 | 1 | 13µs | $VERSION = eval $VERSION; # spent 2µs executing statements in string eval | ||
7 | |||||
8 | # constant.pm is slow | ||||
9 | sub SUCCESS () { 1 } | ||||
10 | |||||
11 | sub PUBLIC () { 2**0 } | ||||
12 | sub PRIVATE () { 2**1 } | ||||
13 | sub INHERITED () { 2**2 } | ||||
14 | sub PROTECTED () { 2**3 } | ||||
15 | |||||
16 | 1 | 700ns | my $Fattr = \%fields::attr; | ||
17 | |||||
18 | # spent 126µs within base::has_fields which was called 36 times, avg 4µs/call:
# 36 times (126µs+0s) by base::import at line 124, avg 4µs/call | ||||
19 | 36 | 18µs | my($base) = shift; | ||
20 | 36 | 40µs | my $fglob = ${"$base\::"}{FIELDS}; | ||
21 | 36 | 88µs | return( ($fglob && 'GLOB' eq ref($fglob) && *$fglob{HASH}) ? 1 : 0 ); | ||
22 | } | ||||
23 | |||||
24 | # spent 91µs within base::has_attr which was called 36 times, avg 3µs/call:
# 36 times (91µs+0s) by base::import at line 124, avg 3µs/call | ||||
25 | 36 | 13µs | my($proto) = shift; | ||
26 | 36 | 21µs | my($class) = ref $proto || $proto; | ||
27 | 36 | 75µs | return exists $Fattr->{$class}; | ||
28 | } | ||||
29 | |||||
30 | sub get_attr { | ||||
31 | $Fattr->{$_[0]} = [1] unless $Fattr->{$_[0]}; | ||||
32 | return $Fattr->{$_[0]}; | ||||
33 | } | ||||
34 | |||||
35 | 1 | 800ns | if ($] < 5.009) { | ||
36 | *get_fields = sub { | ||||
37 | # Shut up a possible typo warning. | ||||
38 | () = \%{$_[0].'::FIELDS'}; | ||||
39 | my $f = \%{$_[0].'::FIELDS'}; | ||||
40 | |||||
41 | # should be centralized in fields? perhaps | ||||
42 | # fields::mk_FIELDS_be_OK. Peh. As long as %{ $package . '::FIELDS' } | ||||
43 | # is used here anyway, it doesn't matter. | ||||
44 | bless $f, 'pseudohash' if (ref($f) ne 'pseudohash'); | ||||
45 | |||||
46 | return $f; | ||||
47 | } | ||||
48 | } | ||||
49 | else { | ||||
50 | *get_fields = sub { | ||||
51 | # Shut up a possible typo warning. | ||||
52 | () = \%{$_[0].'::FIELDS'}; | ||||
53 | return \%{$_[0].'::FIELDS'}; | ||||
54 | } | ||||
55 | 1 | 3µs | } | ||
56 | |||||
57 | 1 | 300ns | if ($] < 5.008) { | ||
58 | *_module_to_filename = sub { | ||||
59 | (my $fn = $_[0]) =~ s!::!/!g; | ||||
60 | $fn .= '.pm'; | ||||
61 | return $fn; | ||||
62 | } | ||||
63 | } | ||||
64 | else { | ||||
65 | # spent 355µs (235+120) within base::__ANON__[/usr/share/perl/5.20/base.pm:70] which was called 36 times, avg 10µs/call:
# 36 times (235µs+120µs) by base::import at line 96, avg 10µs/call | ||||
66 | 36 | 170µs | 36 | 77µs | (my $fn = $_[0]) =~ s!::!/!g; # spent 77µs making 36 calls to base::CORE:subst, avg 2µs/call |
67 | 36 | 16µs | $fn .= '.pm'; | ||
68 | 36 | 107µs | 36 | 43µs | utf8::encode($fn); # spent 43µs making 36 calls to utf8::encode, avg 1µs/call |
69 | 36 | 78µs | return $fn; | ||
70 | } | ||||
71 | 1 | 1µs | } | ||
72 | |||||
73 | # spent 47.6ms (43.0+4.62) within base::import which was called 36 times, avg 1.32ms/call:
# once (12.9ms+3.37ms) by Template::BEGIN@25 at line 25 of Template.pm
# once (13.0ms+52µs) by XML::SAX::Expat::BEGIN@9 at line 9 of XML/SAX/Expat.pm
# once (4.89ms+336µs) by Set::Infinite::BEGIN@16 at line 16 of Set/Infinite.pm
# once (1.99ms+2.83ms) by DateTime::Locale::en_US::BEGIN@25 at line 25 of DateTime/Locale/en_US.pm
# once (1.74ms+91µs) by MARC::Charset::Code::BEGIN@5 at line 5 of MARC/Charset/Code.pm
# once (1.72ms+20µs) by Authen::CAS::Client::Response::ProxySuccess::BEGIN@108 at line 108 of Authen/CAS/Client/Response.pm
# once (1.02ms+60µs) by Authen::CAS::Client::Response::AuthFailure::BEGIN@68 at line 68 of Authen/CAS/Client/Response.pm
# once (1.03ms+44µs) by Authen::CAS::Client::Response::AuthSuccess::BEGIN@94 at line 94 of Authen/CAS/Client/Response.pm
# once (1.01ms+21µs) by Authen::CAS::Client::Response::ProxyFailure::BEGIN@76 at line 76 of Authen/CAS/Client/Response.pm
# once (74µs+35µs) by CGI::Util::BEGIN@2 at line 2 of CGI/Util.pm
# once (51µs+27µs) by Template::Provider::BEGIN@43 at line 43 of Template/Provider.pm
# once (51µs+25µs) by C4::Boolean::BEGIN@28 at line 28 of C4/Boolean.pm
# once (52µs+24µs) by Authen::CAS::Client::Response::Error::BEGIN@39 at line 39 of Authen/CAS/Client/Response.pm
# once (49µs+22µs) by MIME::Types::BEGIN@218 at line 218 of MIME/Types.pm
# once (47µs+23µs) by C4::Linker::BEGIN@50 at line 50 of C4/Linker.pm
# once (44µs+23µs) by C4::Templates::BEGIN@32 at line 32 of C4/Templates.pm
# once (42µs+25µs) by DateTime::Format::Builder::Parser::Quick::BEGIN@9 at line 9 of DateTime/Format/Builder/Parser/Quick.pm
# once (46µs+19µs) by DateTime::Infinite::BEGIN@9 at line 9 of DateTime/Infinite.pm
# once (45µs+19µs) by Koha::AuthUtils::BEGIN@24 at line 24 of Koha/AuthUtils.pm
# once (43µs+21µs) by Class::Load::BEGIN@9 at line 9 of Class/Load.pm
# once (43µs+20µs) by Koha::DateUtils::BEGIN@26 at line 26 of Koha/DateUtils.pm
# once (42µs+20µs) by JSON::BEGIN@6 at line 6 of JSON.pm
# once (40µs+21µs) by Template::Service::BEGIN@25 at line 25 of Template/Service.pm
# once (40µs+18µs) by MARC::Charset::BEGIN@8 at line 8 of MARC/Charset.pm
# once (40µs+17µs) by Variable::Magic::BEGIN@646 at line 646 of Variable/Magic.pm
# once (39µs+17µs) by MARC::File::XML::BEGIN@6 at line 6 of MARC/File/XML.pm
# once (40µs+16µs) by Template::Document::BEGIN@26 at line 26 of Template/Document.pm
# once (38µs+18µs) by Template::Config::BEGIN@23 at line 23 of Template/Config.pm
# once (37µs+17µs) by MARC::File::Encode::BEGIN@21 at line 21 of MARC/File/Encode.pm
# once (35µs+15µs) by MARC::Charset::Constants::BEGIN@20 at line 20 of MARC/Charset/Constants.pm
# once (31µs+14µs) by DateTime::Infinite::Future::BEGIN@41 at line 41 of DateTime/Infinite.pm
# once (31µs+13µs) by Authen::CAS::Client::Response::Success::BEGIN@84 at line 84 of Authen/CAS/Client/Response.pm
# once (28µs+12µs) by DateTime::Infinite::Past::BEGIN@66 at line 66 of DateTime/Infinite.pm
# once (21µs+7µs) by Authen::CAS::Client::Response::Failure::BEGIN@53 at line 53 of Authen/CAS/Client/Response.pm
# once (2.66ms+-2.66ms) by DateTime::Locale::en::BEGIN@25 at line 25 of DateTime/Locale/en.pm
# once (36µs+-36µs) by DateTime::Locale::root::BEGIN@25 at line 25 of DateTime/Locale/root.pm | ||||
74 | 36 | 17µs | my $class = shift; | ||
75 | |||||
76 | 36 | 13µs | return SUCCESS unless @_; | ||
77 | |||||
78 | # List of base classes from which we will inherit %FIELDS. | ||||
79 | 36 | 6µs | my $fields_base; | ||
80 | |||||
81 | 36 | 28µs | my $inheritor = caller(0); | ||
82 | |||||
83 | 36 | 9µs | my @bases; | ||
84 | 36 | 32µs | foreach my $base (@_) { | ||
85 | 37 | 13µs | if ( $inheritor eq $base ) { | ||
86 | warn "Class '$inheritor' tried to inherit from itself\n"; | ||||
87 | } | ||||
88 | |||||
89 | 37 | 399µs | 38 | 82µs | next if grep $_->isa($base), ($inheritor, @bases); # spent 82µs making 38 calls to UNIVERSAL::isa, avg 2µs/call |
90 | |||||
91 | # Following blocks help isolate $SIG{__DIE__} changes | ||||
92 | { | ||||
93 | 72 | 20µs | my $sigdie; | ||
94 | { | ||||
95 | 72 | 74µs | local $SIG{__DIE__}; | ||
96 | 36 | 70µs | 36 | 355µs | my $fn = _module_to_filename($base); # spent 355µs making 36 calls to base::__ANON__[base.pm:70], avg 10µs/call |
97 | 72 | 20.3ms | eval { require $fn }; | ||
98 | # Only ignore "Can't locate" errors from our eval require. | ||||
99 | # Other fatal errors (syntax etc) must be reported. | ||||
100 | # | ||||
101 | # changing the check here is fragile - if the check | ||||
102 | # here isn't catching every error you want, you should | ||||
103 | # probably be using parent.pm, which doesn't try to | ||||
104 | # guess whether require is needed or failed, | ||||
105 | # see [perl #118561] | ||||
106 | 36 | 208µs | 44 | 107µs | die if $@ && $@ !~ /^Can't locate \Q$fn\E .*? at .* line [0-9]+(?:, <[^>]*> (?:line|chunk) [0-9]+)?\.\n\z/s # spent 69µs making 4 calls to base::CORE:regcomp, avg 17µs/call
# spent 38µs making 40 calls to base::CORE:match, avg 948ns/call |
107 | || $@ =~ /Compilation failed in require at .* line [0-9]+(?:, <[^>]*> (?:line|chunk) [0-9]+)?\.\n\z/; | ||||
108 | 36 | 88µs | unless (%{"$base\::"}) { | ||
109 | require Carp; | ||||
110 | local $" = " "; | ||||
111 | Carp::croak(<<ERROR); | ||||
112 | Base class package "$base" is empty. | ||||
113 | (Perhaps you need to 'use' the module which defines that package first, | ||||
114 | or make that module available in \@INC (\@INC contains: @INC). | ||||
115 | ERROR | ||||
116 | } | ||||
117 | 36 | 105µs | $sigdie = $SIG{__DIE__} || undef; | ||
118 | } | ||||
119 | # Make sure a global $SIG{__DIE__} makes it out of the localization. | ||||
120 | 36 | 14µs | $SIG{__DIE__} = $sigdie if defined $sigdie; | ||
121 | } | ||||
122 | 36 | 20µs | push @bases, $base; | ||
123 | |||||
124 | 36 | 124µs | 72 | 218µs | if ( has_fields($base) || has_attr($base) ) { # spent 126µs making 36 calls to base::has_fields, avg 4µs/call
# spent 91µs making 36 calls to base::has_attr, avg 3µs/call |
125 | # No multiple fields inheritance *suck* | ||||
126 | if ($fields_base) { | ||||
127 | require Carp; | ||||
128 | Carp::croak("Can't multiply inherit fields"); | ||||
129 | } else { | ||||
130 | $fields_base = $base; | ||||
131 | } | ||||
132 | } | ||||
133 | } | ||||
134 | # Save this until the end so it's all or nothing if the above loop croaks. | ||||
135 | 36 | 300µs | push @{"$inheritor\::ISA"}, @bases; | ||
136 | |||||
137 | 36 | 156µs | if( defined $fields_base ) { | ||
138 | inherit_fields($inheritor, $fields_base); | ||||
139 | } | ||||
140 | } | ||||
141 | |||||
142 | sub inherit_fields { | ||||
143 | my($derived, $base) = @_; | ||||
144 | |||||
145 | return SUCCESS unless $base; | ||||
146 | |||||
147 | my $battr = get_attr($base); | ||||
148 | my $dattr = get_attr($derived); | ||||
149 | my $dfields = get_fields($derived); | ||||
150 | my $bfields = get_fields($base); | ||||
151 | |||||
152 | $dattr->[0] = @$battr; | ||||
153 | |||||
154 | if( keys %$dfields ) { | ||||
155 | warn <<"END"; | ||||
156 | $derived is inheriting from $base but already has its own fields! | ||||
157 | This will cause problems. Be sure you use base BEFORE declaring fields. | ||||
158 | END | ||||
159 | |||||
160 | } | ||||
161 | |||||
162 | # Iterate through the base's fields adding all the non-private | ||||
163 | # ones to the derived class. Hang on to the original attribute | ||||
164 | # (Public, Private, etc...) and add Inherited. | ||||
165 | # This is all too complicated to do efficiently with add_fields(). | ||||
166 | while (my($k,$v) = each %$bfields) { | ||||
167 | my $fno; | ||||
168 | if ($fno = $dfields->{$k} and $fno != $v) { | ||||
169 | require Carp; | ||||
170 | Carp::croak ("Inherited fields can't override existing fields"); | ||||
171 | } | ||||
172 | |||||
173 | if( $battr->[$v] & PRIVATE ) { | ||||
174 | $dattr->[$v] = PRIVATE | INHERITED; | ||||
175 | } | ||||
176 | else { | ||||
177 | $dattr->[$v] = INHERITED | $battr->[$v]; | ||||
178 | $dfields->{$k} = $v; | ||||
179 | } | ||||
180 | } | ||||
181 | |||||
182 | foreach my $idx (1..$#{$battr}) { | ||||
183 | next if defined $dattr->[$idx]; | ||||
184 | $dattr->[$idx] = $battr->[$idx] & INHERITED; | ||||
185 | } | ||||
186 | } | ||||
187 | |||||
188 | 1 | 4µs | 1; | ||
189 | |||||
190 | __END__ | ||||
# spent 38µs within base::CORE:match which was called 40 times, avg 948ns/call:
# 40 times (38µs+0s) by base::import at line 106, avg 948ns/call | |||||
# spent 69µs within base::CORE:regcomp which was called 4 times, avg 17µs/call:
# 4 times (69µs+0s) by base::import at line 106, avg 17µs/call | |||||
# spent 77µs within base::CORE:subst which was called 36 times, avg 2µs/call:
# 36 times (77µs+0s) by base::__ANON__[/usr/share/perl/5.20/base.pm:70] at line 66, avg 2µs/call |