← Index
NYTProf Performance Profile   « block view • line view • sub view »
For -e
  Run on Sun Aug 5 15:24:32 2012
Reported on Sun Aug 5 15:24:54 2012

Filename/usr/lib/perl5/5.12.4/base.pm
StatementsExecuted 269 statements in 8.89ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
99726.1ms30.4msbase::::importbase::import (recurses: max depth 2, inclusive time 14.0ms)
911379µs379µsbase::::has_versionbase::has_version
911277µs277µsbase::::has_fieldsbase::has_fields
911239µs239µsbase::::has_attrbase::has_attr
11170µs162µsbase::::BEGIN@3base::BEGIN@3
11155µs200µsbase::::BEGIN@4base::BEGIN@4
0000s0sbase::::__ANON__[:54]base::__ANON__[:54]
0000s0sbase::::__ANON__[:61]base::__ANON__[:61]
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
33146µs2255µs
# spent 162µs (70+92) within base::BEGIN@3 which was called: # once (70µs+92µs) by DateTime::TimeZone::Floating::BEGIN@9 at line 3
use strict 'vars';
# spent 162µs making 1 call to base::BEGIN@3 # spent 92µs making 1 call to strict::import
434.46ms2344µs
# spent 200µs (55+144) within base::BEGIN@4 which was called: # once (55µs+144µs) by DateTime::TimeZone::Floating::BEGIN@9 at line 4
use vars qw($VERSION);
# spent 200µs making 1 call to base::BEGIN@4 # spent 144µs making 1 call to vars::import
516µs$VERSION = '2.15';
6166µs$VERSION = eval $VERSION;
# spent 14µ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
16
1717µsmy $Fattr = \%fields::attr;
18
19
# spent 277µs within base::has_fields which was called 9 times, avg 31µs/call: # 9 times (277µs+0s) by base::import at line 113, avg 31µs/call
sub has_fields {
2027332µs my($base) = shift;
21 my $fglob = ${"$base\::"}{FIELDS};
22 return( ($fglob && 'GLOB' eq ref($fglob) && *$fglob{HASH}) ? 1 : 0 );
23}
24
25
# spent 379µs within base::has_version which was called 9 times, avg 42µs/call: # 9 times (379µs+0s) by base::import at line 83, avg 42µs/call
sub has_version {
2627439µs my($base) = shift;
27 my $vglob = ${$base.'::'}{VERSION};
28 return( ($vglob && *$vglob{SCALAR}) ? 1 : 0 );
29}
30
31
# spent 239µs within base::has_attr which was called 9 times, avg 27µs/call: # 9 times (239µs+0s) by base::import at line 113, avg 27µs/call
sub has_attr {
3227267µs my($proto) = shift;
33 my($class) = ref $proto || $proto;
34 return exists $Fattr->{$class};
35}
36
37sub get_attr {
38 $Fattr->{$_[0]} = [1] unless $Fattr->{$_[0]};
39 return $Fattr->{$_[0]};
40}
41
42225µsif ($] < 5.009) {
43 *get_fields = sub {
44 # Shut up a possible typo warning.
45 () = \%{$_[0].'::FIELDS'};
46 my $f = \%{$_[0].'::FIELDS'};
47
48 # should be centralized in fields? perhaps
49 # fields::mk_FIELDS_be_OK. Peh. As long as %{ $package . '::FIELDS' }
50 # is used here anyway, it doesn't matter.
51 bless $f, 'pseudohash' if (ref($f) ne 'pseudohash');
52
53 return $f;
54 }
55}
56else {
57 *get_fields = sub {
58 # Shut up a possible typo warning.
59 () = \%{$_[0].'::FIELDS'};
60 return \%{$_[0].'::FIELDS'};
61 }
62}
63
64
# spent 30.4ms (26.1+4.27) within base::import which was called 9 times, avg 3.38ms/call: # once (9.77ms+13.2ms) by DateTime::Locale::en_US::BEGIN@25 at line 25 of DateTime/Locale/en_US.pm # once (3.03ms+3.36ms) by DateTime::TimeZone::Floating::BEGIN@9 at line 9 of DateTime/TimeZone/Floating.pm # once (267µs+114µs) by DateTime::Infinite::Future::BEGIN@44 at line 44 of DateTime/Infinite.pm # once (232µs+131µs) by DateTime::Infinite::Past::BEGIN@68 at line 68 of DateTime/Infinite.pm # once (234µs+116µs) by DateTime::Infinite::BEGIN@12 at line 12 of DateTime/Infinite.pm # once (447µs+-447µs) by DateTime::Locale::root::BEGIN@25 at line 25 of DateTime/Locale/root.pm # once (238µs+-238µs) by DateTime::TimeZone::UTC::BEGIN@9 at line 9 of DateTime/TimeZone/UTC.pm # once (11.6ms+-11.6ms) by DateTime::Locale::en::BEGIN@25 at line 25 of DateTime/Locale/en.pm # once (302µs+-302µs) by DateTime::TimeZone::OffsetOnly::BEGIN@9 at line 9 of DateTime/TimeZone/OffsetOnly.pm
sub import {
65901.09ms my $class = shift;
66
67 return SUCCESS unless @_;
68
69 # List of base classes from which we will inherit %FIELDS.
70 my $fields_base;
71
72 my $inheritor = caller(0);
73 my @isa_classes;
74
75 my @bases;
76 foreach my $base (@_) {
77451.18ms if ( $inheritor eq $base ) {
78 warn "Class '$inheritor' tried to inherit from itself\n";
79 }
80
819140µs next if grep $_->isa($base), ($inheritor, @bases);
# spent 140µs making 9 calls to UNIVERSAL::isa, avg 16µs/call
82
8321213µs9379µs if (has_version($base)) {
# spent 379µs making 9 calls to base::has_version, avg 42µs/call
84 ${$base.'::VERSION'} = '-1, set by base.pm'
85 unless defined ${$base.'::VERSION'};
86 }
87 else {
88 my $sigdie;
89 {
9020621µs local $SIG{__DIE__};
91 eval "require $base";
# spent 435µs executing statements in string eval # spent 411µs executing statements in string eval # spent 411µs executing statements in string eval # spent 14µs executing statements in string eval
92 # Only ignore "Can't locate" errors from our eval require.
93 # Other fatal errors (syntax etc) must be reported.
94 die if $@ && $@ !~ /^Can't locate .*? at \(eval /;
95 unless (%{"$base\::"}) {
96 require Carp;
97 local $" = " ";
98 Carp::croak(<<ERROR);
99Base class package "$base" is empty.
100 (Perhaps you need to 'use' the module which defines that package first,
101 or make that module available in \@INC (\@INC contains: @INC).
102ERROR
103 }
104 $sigdie = $SIG{__DIE__} || undef;
105 }
106 # Make sure a global $SIG{__DIE__} makes it out of the localization.
107 $SIG{__DIE__} = $sigdie if defined $sigdie;
108 ${$base.'::VERSION'} = "-1, set by base.pm"
109 unless defined ${$base.'::VERSION'};
110 }
111 push @bases, $base;
112
11318516µs if ( has_fields($base) || has_attr($base) ) {
# spent 277µs making 9 calls to base::has_fields, avg 31µs/call # spent 239µs making 9 calls to base::has_attr, avg 27µs/call
114 # No multiple fields inheritance *suck*
115 if ($fields_base) {
116 require Carp;
117 Carp::croak("Can't multiply inherit fields");
118 } else {
119 $fields_base = $base;
120 }
121 }
122 }
123 # Save this until the end so it's all or nothing if the above loop croaks.
124 push @{"$inheritor\::ISA"}, @isa_classes;
125
126 push @{"$inheritor\::ISA"}, @bases;
127
128 if( defined $fields_base ) {
129 inherit_fields($inheritor, $fields_base);
130 }
131}
132
133
134sub inherit_fields {
135 my($derived, $base) = @_;
136
137 return SUCCESS unless $base;
138
139 my $battr = get_attr($base);
140 my $dattr = get_attr($derived);
141 my $dfields = get_fields($derived);
142 my $bfields = get_fields($base);
143
144 $dattr->[0] = @$battr;
145
146 if( keys %$dfields ) {
147 warn <<"END";
148$derived is inheriting from $base but already has its own fields!
149This will cause problems. Be sure you use base BEFORE declaring fields.
150END
151
152 }
153
154 # Iterate through the base's fields adding all the non-private
155 # ones to the derived class. Hang on to the original attribute
156 # (Public, Private, etc...) and add Inherited.
157 # This is all too complicated to do efficiently with add_fields().
158 while (my($k,$v) = each %$bfields) {
159 my $fno;
160 if ($fno = $dfields->{$k} and $fno != $v) {
161 require Carp;
162 Carp::croak ("Inherited fields can't override existing fields");
163 }
164
165 if( $battr->[$v] & PRIVATE ) {
166 $dattr->[$v] = PRIVATE | INHERITED;
167 }
168 else {
169 $dattr->[$v] = INHERITED | $battr->[$v];
170 $dfields->{$k} = $v;
171 }
172 }
173
174 foreach my $idx (1..$#{$battr}) {
175 next if defined $dattr->[$idx];
176 $dattr->[$idx] = $battr->[$idx] & INHERITED;
177 }
178}
179
180
181125µs1;
182
183__END__