← Index
NYTProf Performance Profile   « line view »
For index.cgi
  Run on Sat May 9 17:18:47 2020
Reported on Sat May 9 17:19:07 2020

Filename/usr/share/perl/5.18/base.pm
StatementsExecuted 91 statements in 1.31ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
333237µs267µsbase::::importbase::import
11115µs30µsbase::::BEGIN@3base::BEGIN@3
31113µs13µsbase::::has_fieldsbase::has_fields
3119µs9µsbase::::has_attrbase::has_attr
1119µs40µsbase::::BEGIN@4base::BEGIN@4
0000s0sbase::::__ANON__[:47]base::__ANON__[:47]
0000s0sbase::::__ANON__[:54]base::__ANON__[:54]
0000s0sbase::::get_attrbase::get_attr
0000s0sbase::::inherit_fieldsbase::inherit_fields
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package base;
2
3234µs246µs
# spent 30µs (15+16) within base::BEGIN@3 which was called: # once (15µs+16µs) by Variable::Magic::BEGIN@688 at line 3
use strict 'vars';
# spent 30µs making 1 call to base::BEGIN@3 # spent 16µs making 1 call to strict::import
42982µs272µs
# spent 40µs (9+31) within base::BEGIN@4 which was called: # once (9µs+31µs) by Variable::Magic::BEGIN@688 at line 4
use vars qw($VERSION);
# spent 40µs making 1 call to base::BEGIN@4 # spent 31µs making 1 call to vars::import
511µs$VERSION = '2.18';
6118µs$VERSION = eval $VERSION;
# spent 3µs executing statements in string eval
7
8# constant.pm is slow
9sub SUCCESS () { 1 }
10
11sub PUBLIC () { 2**0 }
12sub PRIVATE () { 2**1 }
13sub INHERITED () { 2**2 }
14sub PROTECTED () { 2**3 }
15
1611µsmy $Fattr = \%fields::attr;
17
18
# spent 13µs within base::has_fields which was called 3 times, avg 4µs/call: # 3 times (13µs+0s) by base::import at line 100, avg 4µs/call
sub has_fields {
1933µs my($base) = shift;
2033µs my $fglob = ${"$base\::"}{FIELDS};
21315µs return( ($fglob && 'GLOB' eq ref($fglob) && *$fglob{HASH}) ? 1 : 0 );
22}
23
24
# spent 9µs within base::has_attr which was called 3 times, avg 3µs/call: # 3 times (9µs+0s) by base::import at line 100, avg 3µs/call
sub has_attr {
2532µs my($proto) = shift;
2632µs my($class) = ref $proto || $proto;
27311µs return exists $Fattr->{$class};
28}
29
30sub get_attr {
31 $Fattr->{$_[0]} = [1] unless $Fattr->{$_[0]};
32 return $Fattr->{$_[0]};
33}
34
3511µsif ($] < 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}
49else {
50 *get_fields = sub {
51 # Shut up a possible typo warning.
52 () = \%{$_[0].'::FIELDS'};
53 return \%{$_[0].'::FIELDS'};
54 }
5514µs}
56
57
# spent 267µs (237+30) within base::import which was called 3 times, avg 89µs/call: # once (84µs+11µs) by Class::Method::Modifiers::BEGIN@14 at line 14 of Class/Method/Modifiers.pm # once (77µs+10µs) by Variable::Magic::BEGIN@688 at line 688 of Variable/Magic.pm # once (76µs+9µs) by namespace::clean::_Util::BEGIN@15 at line 15 of namespace/clean/_Util.pm
sub import {
5832µs my $class = shift;
59
6032µs return SUCCESS unless @_;
61
62 # List of base classes from which we will inherit %FIELDS.
633600ns my $fields_base;
64
6533µs my $inheritor = caller(0);
66
6731µs my @bases;
6834µs foreach my $base (@_) {
6932µs if ( $inheritor eq $base ) {
70 warn "Class '$inheritor' tried to inherit from itself\n";
71 }
72
73351µs37µs next if grep $_->isa($base), ($inheritor, @bases);
# spent 7µs making 3 calls to UNIVERSAL::isa, avg 2µs/call
74
75 # Following blocks help isolate $SIG{__DIE__} changes
76 {
7762µs my $sigdie;
78 {
7968µs local $SIG{__DIE__};
80371µs eval "require $base";
# spent 8µs executing statements in 3 string evals (merged)
81 # Only ignore "Can't locate" errors from our eval require.
82 # Other fatal errors (syntax etc) must be reported.
833900ns die if $@ && $@ !~ /^Can't locate .*? at \(eval /;
8438µs unless (%{"$base\::"}) {
85 require Carp;
86 local $" = " ";
87 Carp::croak(<<ERROR);
88Base class package "$base" is empty.
89 (Perhaps you need to 'use' the module which defines that package first,
90 or make that module available in \@INC (\@INC contains: @INC).
91ERROR
92 }
93312µs $sigdie = $SIG{__DIE__} || undef;
94 }
95 # Make sure a global $SIG{__DIE__} makes it out of the localization.
9632µs $SIG{__DIE__} = $sigdie if defined $sigdie;
97 }
9832µs push @bases, $base;
99
100314µs623µs if ( has_fields($base) || has_attr($base) ) {
# spent 13µs making 3 calls to base::has_fields, avg 4µs/call # spent 9µs making 3 calls to base::has_attr, avg 3µs/call
101 # No multiple fields inheritance *suck*
102 if ($fields_base) {
103 require Carp;
104 Carp::croak("Can't multiply inherit fields");
105 } else {
106 $fields_base = $base;
107 }
108 }
109 }
110 # Save this until the end so it's all or nothing if the above loop croaks.
111332µs push @{"$inheritor\::ISA"}, @bases;
112
113314µs if( defined $fields_base ) {
114 inherit_fields($inheritor, $fields_base);
115 }
116}
117
118sub inherit_fields {
119 my($derived, $base) = @_;
120
121 return SUCCESS unless $base;
122
123 my $battr = get_attr($base);
124 my $dattr = get_attr($derived);
125 my $dfields = get_fields($derived);
126 my $bfields = get_fields($base);
127
128 $dattr->[0] = @$battr;
129
130 if( keys %$dfields ) {
131 warn <<"END";
132$derived is inheriting from $base but already has its own fields!
133This will cause problems. Be sure you use base BEFORE declaring fields.
134END
135
136 }
137
138 # Iterate through the base's fields adding all the non-private
139 # ones to the derived class. Hang on to the original attribute
140 # (Public, Private, etc...) and add Inherited.
141 # This is all too complicated to do efficiently with add_fields().
142 while (my($k,$v) = each %$bfields) {
143 my $fno;
144 if ($fno = $dfields->{$k} and $fno != $v) {
145 require Carp;
146 Carp::croak ("Inherited fields can't override existing fields");
147 }
148
149 if( $battr->[$v] & PRIVATE ) {
150 $dattr->[$v] = PRIVATE | INHERITED;
151 }
152 else {
153 $dattr->[$v] = INHERITED | $battr->[$v];
154 $dfields->{$k} = $v;
155 }
156 }
157
158 foreach my $idx (1..$#{$battr}) {
159 next if defined $dattr->[$idx];
160 $dattr->[$idx] = $battr->[$idx] & INHERITED;
161 }
162}
163
16415µs1;
165
166__END__