Filename | /usr/share/perl/5.18/base.pm |
Statements | Executed 388 statements in 1.92ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
14 | 14 | 13 | 2.63ms | 2.79ms | import | base::
14 | 1 | 1 | 50µs | 50µs | has_fields | base::
14 | 1 | 1 | 33µs | 33µs | has_attr | base::
1 | 1 | 1 | 13µs | 28µs | BEGIN@3 | base::
1 | 1 | 1 | 8µs | 29µ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 | 30µs | 2 | 43µs | # spent 28µs (13+15) within base::BEGIN@3 which was called:
# once (13µs+15µs) by Sub::Name::BEGIN@49 at line 3 # spent 28µs making 1 call to base::BEGIN@3
# spent 15µs making 1 call to strict::import |
4 | 2 | 883µs | 2 | 50µs | # spent 29µs (8+21) within base::BEGIN@4 which was called:
# once (8µs+21µs) by Sub::Name::BEGIN@49 at line 4 # spent 29µs making 1 call to base::BEGIN@4
# spent 21µs making 1 call to vars::import |
5 | 1 | 600ns | $VERSION = '2.18'; | ||
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 | 800ns | my $Fattr = \%fields::attr; | ||
17 | |||||
18 | # spent 50µs within base::has_fields which was called 14 times, avg 4µs/call:
# 14 times (50µs+0s) by base::import at line 100, avg 4µs/call | ||||
19 | 14 | 9µs | my($base) = shift; | ||
20 | 14 | 14µs | my $fglob = ${"$base\::"}{FIELDS}; | ||
21 | 14 | 54µs | return( ($fglob && 'GLOB' eq ref($fglob) && *$fglob{HASH}) ? 1 : 0 ); | ||
22 | } | ||||
23 | |||||
24 | # spent 33µs within base::has_attr which was called 14 times, avg 2µs/call:
# 14 times (33µs+0s) by base::import at line 100, avg 2µs/call | ||||
25 | 14 | 5µs | my($proto) = shift; | ||
26 | 14 | 5µs | my($class) = ref $proto || $proto; | ||
27 | 14 | 35µ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 | 1µs | 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 | 4µs | } | ||
56 | |||||
57 | # spent 2.79ms (2.63+154µs) within base::import which was called 14 times, avg 199µs/call:
# once (1.82ms+49µs) by Sub::Name::BEGIN@50 at line 50 of Sub/Name.pm
# once (86µs+14µs) by JSON::MaybeXS::BEGIN@5 at line 5 of /opt/flows/lib/lib/perl5/JSON/MaybeXS.pm
# once (68µs+9µs) by Class::Method::Modifiers::BEGIN@14 at line 14 of Class/Method/Modifiers.pm
# once (66µs+7µs) by Variable::Magic::BEGIN@688 at line 688 of /opt/flows/lib/lib/perl5/x86_64-linux-gnu-thread-multi/Variable/Magic.pm
# once (65µs+7µs) by Sub::Quote::BEGIN@10 at line 10 of Sub/Quote.pm
# once (62µs+7µs) by Method::Generate::BuildAll::BEGIN@4 at line 4 of Method/Generate/BuildAll.pm
# once (61µs+7µs) by Method::Generate::Accessor::BEGIN@5 at line 5 of Method/Generate/Accessor.pm
# once (60µs+8µs) by Sub::Name::BEGIN@49 at line 49 of Sub/Name.pm
# once (60µs+7µs) by Sub::Defer::BEGIN@4 at line 4 of Sub/Defer.pm
# once (59µs+7µs) by Moo::Role::BEGIN@6 at line 6 of Moo/Role.pm
# once (58µs+8µs) by Any::URI::Escape::BEGIN@14 at line 14 of /opt/flows/lib/lib/perl5/Any/URI/Escape.pm
# once (57µs+8µs) by Method::Generate::Constructor::BEGIN@5 at line 5 of Method/Generate/Constructor.pm
# once (56µs+7µs) by Moo::_Utils::BEGIN@15 at line 15 of Moo/_Utils.pm
# once (56µs+7µs) by namespace::clean::_Util::BEGIN@15 at line 15 of /opt/flows/lib/lib/perl5/namespace/clean/_Util.pm | ||||
58 | 14 | 7µs | my $class = shift; | ||
59 | |||||
60 | 14 | 7µs | return SUCCESS unless @_; | ||
61 | |||||
62 | # List of base classes from which we will inherit %FIELDS. | ||||
63 | 14 | 2µs | my $fields_base; | ||
64 | |||||
65 | 14 | 10µs | my $inheritor = caller(0); | ||
66 | |||||
67 | 14 | 2µs | my @bases; | ||
68 | 14 | 14µs | foreach my $base (@_) { | ||
69 | 14 | 4µs | if ( $inheritor eq $base ) { | ||
70 | warn "Class '$inheritor' tried to inherit from itself\n"; | ||||
71 | } | ||||
72 | |||||
73 | 14 | 163µs | 14 | 28µs | next if grep $_->isa($base), ($inheritor, @bases); # spent 28µs making 14 calls to UNIVERSAL::isa, avg 2µs/call |
74 | |||||
75 | # Following blocks help isolate $SIG{__DIE__} changes | ||||
76 | { | ||||
77 | 28 | 6µs | my $sigdie; | ||
78 | { | ||||
79 | 28 | 32µs | local $SIG{__DIE__}; | ||
80 | 14 | 277µs | eval "require $base"; # spent 98µs executing statements in string eval
# spent 22µs executing statements in 9 string evals (merged)
# spent 7µs executing statements in 3 string evals (merged)
# 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 | 14 | 3µs | die if $@ && $@ !~ /^Can't locate .*? at \(eval /; | ||
84 | 14 | 34µ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 | 14 | 45µs | $sigdie = $SIG{__DIE__} || undef; | ||
94 | } | ||||
95 | # Make sure a global $SIG{__DIE__} makes it out of the localization. | ||||
96 | 14 | 6µs | $SIG{__DIE__} = $sigdie if defined $sigdie; | ||
97 | } | ||||
98 | 14 | 9µs | push @bases, $base; | ||
99 | |||||
100 | 14 | 51µs | 28 | 84µs | if ( has_fields($base) || has_attr($base) ) { # spent 50µs making 14 calls to base::has_fields, avg 4µs/call
# spent 33µs making 14 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 | 14 | 130µs | push @{"$inheritor\::ISA"}, @bases; | ||
112 | |||||
113 | 14 | 62µ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 | 4µs | 1; | ||
165 | |||||
166 | __END__ |