Filename | /usr/share/perl/5.14/base.pm |
Statements | Executed 102 statements in 2.00ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
3 | 3 | 2 | 295µs | 444µs | import | base::
3 | 1 | 1 | 63µs | 63µs | has_version | base::
3 | 1 | 1 | 40µs | 40µs | has_fields | base::
3 | 1 | 1 | 28µs | 28µs | has_attr | base::
1 | 1 | 1 | 23µs | 55µs | BEGIN@3 | base::
1 | 1 | 1 | 15µs | 65µs | BEGIN@4 | base::
0 | 0 | 0 | 0s | 0s | __ANON__[:53] | base::
0 | 0 | 0 | 0s | 0s | __ANON__[:60] | 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 | 46µs | 2 | 87µs | # spent 55µs (23+32) within base::BEGIN@3 which was called:
# once (23µs+32µs) by File::Temp::BEGIN@162 at line 3 # spent 55µs making 1 call to base::BEGIN@3
# spent 32µs making 1 call to strict::import |
4 | 2 | 1.46ms | 2 | 116µs | # spent 65µs (15+51) within base::BEGIN@4 which was called:
# once (15µs+51µs) by File::Temp::BEGIN@162 at line 4 # spent 65µs making 1 call to base::BEGIN@4
# spent 51µs making 1 call to vars::import |
5 | 1 | 2µs | $VERSION = '2.16'; | ||
6 | 1 | 23µs | $VERSION = eval $VERSION; # spent 4µ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 | 2µs | my $Fattr = \%fields::attr; | ||
17 | |||||
18 | # spent 40µs within base::has_fields which was called 3 times, avg 13µs/call:
# 3 times (40µs+0s) by base::import at line 112, avg 13µs/call | ||||
19 | 9 | 37µs | my($base) = shift; | ||
20 | 3 | 6µs | my $fglob = ${"$base\::"}{FIELDS}; | ||
21 | return( ($fglob && 'GLOB' eq ref($fglob) && *$fglob{HASH}) ? 1 : 0 ); | ||||
22 | } | ||||
23 | |||||
24 | # spent 63µs within base::has_version which was called 3 times, avg 21µs/call:
# 3 times (63µs+0s) by base::import at line 82, avg 21µs/call | ||||
25 | 9 | 60µs | my($base) = shift; | ||
26 | 3 | 7µs | my $vglob = ${$base.'::'}{VERSION}; | ||
27 | return( ($vglob && *$vglob{SCALAR}) ? 1 : 0 ); | ||||
28 | } | ||||
29 | |||||
30 | # spent 28µs within base::has_attr which was called 3 times, avg 9µs/call:
# 3 times (28µs+0s) by base::import at line 112, avg 9µs/call | ||||
31 | 9 | 30µs | my($proto) = shift; | ||
32 | my($class) = ref $proto || $proto; | ||||
33 | return exists $Fattr->{$class}; | ||||
34 | } | ||||
35 | |||||
36 | sub get_attr { | ||||
37 | $Fattr->{$_[0]} = [1] unless $Fattr->{$_[0]}; | ||||
38 | return $Fattr->{$_[0]}; | ||||
39 | } | ||||
40 | |||||
41 | 2 | 9µs | if ($] < 5.009) { | ||
42 | *get_fields = sub { | ||||
43 | # Shut up a possible typo warning. | ||||
44 | () = \%{$_[0].'::FIELDS'}; | ||||
45 | my $f = \%{$_[0].'::FIELDS'}; | ||||
46 | |||||
47 | # should be centralized in fields? perhaps | ||||
48 | # fields::mk_FIELDS_be_OK. Peh. As long as %{ $package . '::FIELDS' } | ||||
49 | # is used here anyway, it doesn't matter. | ||||
50 | bless $f, 'pseudohash' if (ref($f) ne 'pseudohash'); | ||||
51 | |||||
52 | return $f; | ||||
53 | } | ||||
54 | } | ||||
55 | else { | ||||
56 | *get_fields = sub { | ||||
57 | # Shut up a possible typo warning. | ||||
58 | () = \%{$_[0].'::FIELDS'}; | ||||
59 | return \%{$_[0].'::FIELDS'}; | ||||
60 | } | ||||
61 | } | ||||
62 | |||||
63 | # spent 444µs (295+149) within base::import which was called 3 times, avg 148µs/call:
# once (137µs+77µs) by File::Temp::BEGIN@162 at line 162 of File/Temp.pm
# once (119µs+69µs) by Sort::Maker::BEGIN@4 at line 4 of /usr/local/src/github.com/foswiki/core/lib/CPAN/lib/Sort/Maker.pm
# once (39µs+3µs) by File::Temp::BEGIN@173 at line 173 of File/Temp.pm | ||||
64 | 30 | 114µs | my $class = shift; | ||
65 | |||||
66 | return SUCCESS unless @_; | ||||
67 | |||||
68 | # List of base classes from which we will inherit %FIELDS. | ||||
69 | my $fields_base; | ||||
70 | |||||
71 | my $inheritor = caller(0); | ||||
72 | my @isa_classes; | ||||
73 | |||||
74 | my @bases; | ||||
75 | foreach my $base (@_) { | ||||
76 | 17 | 161µs | if ( $inheritor eq $base ) { | ||
77 | warn "Class '$inheritor' tried to inherit from itself\n"; | ||||
78 | } | ||||
79 | |||||
80 | 5 | 18µs | next if grep $_->isa($base), ($inheritor, @bases); # spent 18µs making 5 calls to UNIVERSAL::isa, avg 4µs/call | ||
81 | |||||
82 | 3 | 11µs | 3 | 63µs | if (has_version($base)) { # spent 63µs making 3 calls to base::has_version, avg 21µs/call |
83 | ${$base.'::VERSION'} = '-1, set by base.pm' | ||||
84 | 3 | 8µs | unless defined ${$base.'::VERSION'}; | ||
85 | } | ||||
86 | else { | ||||
87 | my $sigdie; | ||||
88 | { | ||||
89 | local $SIG{__DIE__}; | ||||
90 | eval "require $base"; | ||||
91 | # Only ignore "Can't locate" errors from our eval require. | ||||
92 | # Other fatal errors (syntax etc) must be reported. | ||||
93 | die if $@ && $@ !~ /^Can't locate .*? at \(eval /; | ||||
94 | unless (%{"$base\::"}) { | ||||
95 | require Carp; | ||||
96 | local $" = " "; | ||||
97 | Carp::croak(<<ERROR); | ||||
98 | Base class package "$base" is empty. | ||||
99 | (Perhaps you need to 'use' the module which defines that package first, | ||||
100 | or make that module available in \@INC (\@INC contains: @INC). | ||||
101 | ERROR | ||||
102 | } | ||||
103 | $sigdie = $SIG{__DIE__} || undef; | ||||
104 | } | ||||
105 | # Make sure a global $SIG{__DIE__} makes it out of the localization. | ||||
106 | $SIG{__DIE__} = $sigdie if defined $sigdie; | ||||
107 | ${$base.'::VERSION'} = "-1, set by base.pm" | ||||
108 | unless defined ${$base.'::VERSION'}; | ||||
109 | } | ||||
110 | push @bases, $base; | ||||
111 | |||||
112 | 6 | 68µs | if ( has_fields($base) || has_attr($base) ) { # spent 40µs making 3 calls to base::has_fields, avg 13µs/call
# spent 28µs making 3 calls to base::has_attr, avg 9µs/call | ||
113 | # No multiple fields inheritance *suck* | ||||
114 | if ($fields_base) { | ||||
115 | require Carp; | ||||
116 | Carp::croak("Can't multiply inherit fields"); | ||||
117 | } else { | ||||
118 | $fields_base = $base; | ||||
119 | } | ||||
120 | } | ||||
121 | } | ||||
122 | # Save this until the end so it's all or nothing if the above loop croaks. | ||||
123 | 3 | 7µs | push @{"$inheritor\::ISA"}, @isa_classes; | ||
124 | |||||
125 | 3 | 6µs | push @{"$inheritor\::ISA"}, @bases; | ||
126 | |||||
127 | if( defined $fields_base ) { | ||||
128 | inherit_fields($inheritor, $fields_base); | ||||
129 | } | ||||
130 | } | ||||
131 | |||||
132 | sub inherit_fields { | ||||
133 | my($derived, $base) = @_; | ||||
134 | |||||
135 | return SUCCESS unless $base; | ||||
136 | |||||
137 | my $battr = get_attr($base); | ||||
138 | my $dattr = get_attr($derived); | ||||
139 | my $dfields = get_fields($derived); | ||||
140 | my $bfields = get_fields($base); | ||||
141 | |||||
142 | $dattr->[0] = @$battr; | ||||
143 | |||||
144 | if( keys %$dfields ) { | ||||
145 | warn <<"END"; | ||||
146 | $derived is inheriting from $base but already has its own fields! | ||||
147 | This will cause problems. Be sure you use base BEFORE declaring fields. | ||||
148 | END | ||||
149 | |||||
150 | } | ||||
151 | |||||
152 | # Iterate through the base's fields adding all the non-private | ||||
153 | # ones to the derived class. Hang on to the original attribute | ||||
154 | # (Public, Private, etc...) and add Inherited. | ||||
155 | # This is all too complicated to do efficiently with add_fields(). | ||||
156 | while (my($k,$v) = each %$bfields) { | ||||
157 | my $fno; | ||||
158 | if ($fno = $dfields->{$k} and $fno != $v) { | ||||
159 | require Carp; | ||||
160 | Carp::croak ("Inherited fields can't override existing fields"); | ||||
161 | } | ||||
162 | |||||
163 | if( $battr->[$v] & PRIVATE ) { | ||||
164 | $dattr->[$v] = PRIVATE | INHERITED; | ||||
165 | } | ||||
166 | else { | ||||
167 | $dattr->[$v] = INHERITED | $battr->[$v]; | ||||
168 | $dfields->{$k} = $v; | ||||
169 | } | ||||
170 | } | ||||
171 | |||||
172 | foreach my $idx (1..$#{$battr}) { | ||||
173 | next if defined $dattr->[$idx]; | ||||
174 | $dattr->[$idx] = $battr->[$idx] & INHERITED; | ||||
175 | } | ||||
176 | } | ||||
177 | |||||
178 | 1 | 8µs | 1; | ||
179 | |||||
180 | __END__ |