Filename | /usr/share/perl/5.18/base.pm |
Statements | Executed 660 statements in 2.10ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
24 | 24 | 22 | 1.26ms | 1.44ms | import | base::
24 | 1 | 1 | 87µs | 87µs | has_fields | base::
24 | 1 | 1 | 57µs | 57µs | has_attr | base::
1 | 1 | 1 | 9µs | 17µs | BEGIN@3 | base::
1 | 1 | 1 | 6µs | 24µ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 | 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 | 20µs | 2 | 25µs | # spent 17µs (9+8) within base::BEGIN@3 which was called:
# once (9µs+8µs) by Devel::InnerPackage::BEGIN@4 at line 3 # spent 17µs making 1 call to base::BEGIN@3
# spent 8µs making 1 call to strict::import |
4 | 2 | 616µs | 2 | 42µs | # spent 24µs (6+18) within base::BEGIN@4 which was called:
# once (6µs+18µs) by Devel::InnerPackage::BEGIN@4 at line 4 # spent 24µs making 1 call to base::BEGIN@4
# spent 18µs making 1 call to vars::import |
5 | 1 | 400ns | $VERSION = '2.18'; | ||
6 | 1 | 10µ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 | 600ns | my $Fattr = \%fields::attr; | ||
17 | |||||
18 | # spent 87µs within base::has_fields which was called 24 times, avg 4µs/call:
# 24 times (87µs+0s) by base::import at line 100, avg 4µs/call | ||||
19 | 24 | 16µs | my($base) = shift; | ||
20 | 24 | 29µs | my $fglob = ${"$base\::"}{FIELDS}; | ||
21 | 24 | 79µs | return( ($fglob && 'GLOB' eq ref($fglob) && *$fglob{HASH}) ? 1 : 0 ); | ||
22 | } | ||||
23 | |||||
24 | # spent 57µs within base::has_attr which was called 24 times, avg 2µs/call:
# 24 times (57µs+0s) by base::import at line 100, avg 2µs/call | ||||
25 | 24 | 10µs | my($proto) = shift; | ||
26 | 24 | 11µs | my($class) = ref $proto || $proto; | ||
27 | 24 | 57µ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 | 600ns | 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 | # spent 1.44ms (1.26+181µs) within base::import which was called 24 times, avg 60µs/call:
# once (84µs+16µs) by DBD::SQLite::Constants::BEGIN@8 at line 8 of DBD/SQLite/Constants.pm
# once (80µs+15µs) by File::Temp::BEGIN@165 at line 165 of File/Temp.pm
# once (74µs+12µs) by HTTP::Headers::Util::BEGIN@8 at line 8 of HTTP/Headers/Util.pm
# once (68µs+10µs) by HTTP::Body::OctetStream::BEGIN@7 at line 7 of HTTP/Body/OctetStream.pm
# once (61µs+6µs) by Cookie::Baker::BEGIN@6 at line 6 of Cookie/Baker.pm
# once (57µs+9µs) by Moose::Meta::TypeConstraint::BEGIN@18 at line 18 of Moose/Meta/TypeConstraint.pm
# once (56µs+8µs) by HTTP::Parser::XS::BEGIN@6 at line 6 of HTTP/Parser/XS.pm
# once (55µs+8µs) by YAML::XS::BEGIN@6 at line 6 of YAML/XS.pm
# once (54µs+10µs) by POSIX::strftime::Compiler::BEGIN@9 at line 9 of POSIX/strftime/Compiler.pm
# once (55µs+8µs) by HTTP::Status::BEGIN@8 at line 8 of HTTP/Status.pm
# once (51µs+6µs) by HTTP::Body::XFormsMultipart::BEGIN@7 at line 7 of HTTP/Body/XFormsMultipart.pm
# once (52µs+6µs) by Scope::Upper::BEGIN@725 at line 725 of Scope/Upper.pm
# once (51µs+7µs) by Sub::Name::BEGIN@49 at line 49 of Sub/Name.pm
# once (51µs+7µs) by HTTP::Body::UrlEncoded::BEGIN@7 at line 7 of HTTP/Body/UrlEncoded.pm
# once (48µs+7µs) by Devel::InnerPackage::BEGIN@4 at line 4 of Devel/InnerPackage.pm
# once (48µs+6µs) by HTTP::Body::MultiPart::BEGIN@7 at line 7 of HTTP/Body/MultiPart.pm
# once (48µs+6µs) by Class::Load::BEGIN@9 at line 9 of Class/Load.pm
# once (48µs+6µs) by HTTP::Body::XForms::BEGIN@7 at line 7 of HTTP/Body/XForms.pm
# once (45µs+5µs) by Stream::Buffered::Auto::BEGIN@4 at line 4 of Stream/Buffered/Auto.pm
# once (44µs+5µs) by Stream::Buffered::PerlIO::BEGIN@4 at line 4 of Stream/Buffered/PerlIO.pm
# once (42µs+5µs) by Stream::Buffered::File::BEGIN@4 at line 4 of Stream/Buffered/File.pm
# once (41µs+4µs) by YAML::XS::LibYAML::BEGIN@8 at line 8 of YAML/XS/LibYAML.pm
# once (38µs+5µs) by Sub::Name::BEGIN@50 at line 50 of Sub/Name.pm
# once (10µs+800ns) by File::Temp::BEGIN@177 at line 177 of File/Temp.pm | ||||
58 | 24 | 12µs | my $class = shift; | ||
59 | |||||
60 | 24 | 9µs | return SUCCESS unless @_; | ||
61 | |||||
62 | # List of base classes from which we will inherit %FIELDS. | ||||
63 | 24 | 4µs | my $fields_base; | ||
64 | |||||
65 | 24 | 19µs | my $inheritor = caller(0); | ||
66 | |||||
67 | 24 | 4µs | my @bases; | ||
68 | 24 | 22µs | foreach my $base (@_) { | ||
69 | 25 | 11µs | if ( $inheritor eq $base ) { | ||
70 | warn "Class '$inheritor' tried to inherit from itself\n"; | ||||
71 | } | ||||
72 | |||||
73 | 25 | 236µs | 26 | 37µs | next if grep $_->isa($base), ($inheritor, @bases); # spent 37µs making 26 calls to UNIVERSAL::isa, avg 1µs/call |
74 | |||||
75 | # Following blocks help isolate $SIG{__DIE__} changes | ||||
76 | { | ||||
77 | 48 | 11µs | my $sigdie; | ||
78 | { | ||||
79 | 48 | 51µs | local $SIG{__DIE__}; | ||
80 | 24 | 378µs | eval "require $base"; # spent 24µs executing statements in 12 string evals (merged)
# spent 7µs executing statements in 4 string evals (merged)
# spent 5µs executing statements in 3 string evals (merged)
# spent 2µs executing statements in string eval
# spent 2µs executing statements in string eval
# spent 2µs executing statements in string eval
# spent 2µs executing statements in string eval
# spent 2µs executing statements in string eval | ||
81 | # Only ignore "Can't locate" errors from our eval require. | ||||
82 | # Other fatal errors (syntax etc) must be reported. | ||||
83 | 24 | 5µs | die if $@ && $@ !~ /^Can't locate .*? at \(eval /; | ||
84 | 24 | 51µs | unless (%{"$base\::"}) { | ||
85 | require Carp; | ||||
86 | local $" = " "; | ||||
87 | Carp::croak(<<ERROR); | ||||
88 | Base 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). | ||||
91 | ERROR | ||||
92 | } | ||||
93 | 24 | 69µs | $sigdie = $SIG{__DIE__} || undef; | ||
94 | } | ||||
95 | # Make sure a global $SIG{__DIE__} makes it out of the localization. | ||||
96 | 24 | 9µs | $SIG{__DIE__} = $sigdie if defined $sigdie; | ||
97 | } | ||||
98 | 24 | 14µs | push @bases, $base; | ||
99 | |||||
100 | 24 | 77µs | 48 | 143µs | if ( has_fields($base) || has_attr($base) ) { # spent 87µs making 24 calls to base::has_fields, avg 4µs/call
# spent 57µs making 24 calls to base::has_attr, avg 2µ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. | ||||
111 | 24 | 171µs | push @{"$inheritor\::ISA"}, @bases; | ||
112 | |||||
113 | 24 | 94µs | if( defined $fields_base ) { | ||
114 | inherit_fields($inheritor, $fields_base); | ||||
115 | } | ||||
116 | } | ||||
117 | |||||
118 | sub 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! | ||||
133 | This will cause problems. Be sure you use base BEFORE declaring fields. | ||||
134 | END | ||||
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 | |||||
164 | 1 | 3µs | 1; | ||
165 | |||||
166 | __END__ |