Filename | /usr/lib/perl5/5.14/base.pm |
Statements | Executed 170 statements in 2.63ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
6 | 6 | 5 | 3.99ms | 4.18ms | import | base::
1 | 1 | 1 | 222µs | 256µs | BEGIN@3 | base::
6 | 1 | 1 | 77µs | 77µs | has_version | base::
6 | 1 | 1 | 44µs | 44µs | has_fields | base::
6 | 1 | 1 | 37µs | 37µs | has_attr | base::
1 | 1 | 1 | 15µs | 76µs | BEGIN@4 | base::
0 | 0 | 0 | 0s | 0s | __ANON__[:54] | base::
0 | 0 | 0 | 0s | 0s | __ANON__[:61] | 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 | 71µs | 2 | 291µs | # spent 256µs (222+35) within base::BEGIN@3 which was called:
# once (222µs+35µs) by installer::BEGIN@30 at line 3 # spent 256µs making 1 call to base::BEGIN@3
# spent 35µs making 1 call to strict::import |
4 | 2 | 1.82ms | 2 | 138µs | # spent 76µs (15+62) within base::BEGIN@4 which was called:
# once (15µs+62µs) by installer::BEGIN@30 at line 4 # spent 76µs making 1 call to base::BEGIN@4
# spent 62µs making 1 call to vars::import |
5 | 1 | 2µs | $VERSION = '2.16'; | ||
6 | 1 | 25µs | $VERSION = eval $VERSION; # spent 7µ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 | |||||
17 | 1 | 2µs | my $Fattr = \%fields::attr; | ||
18 | |||||
19 | # spent 44µs within base::has_fields which was called 6 times, avg 7µs/call:
# 6 times (44µs+0s) by base::import at line 113, avg 7µs/call | ||||
20 | 6 | 8µs | my($base) = shift; | ||
21 | 6 | 12µs | my $fglob = ${"$base\::"}{FIELDS}; | ||
22 | 6 | 34µs | return( ($fglob && 'GLOB' eq ref($fglob) && *$fglob{HASH}) ? 1 : 0 ); | ||
23 | } | ||||
24 | |||||
25 | # spent 77µs within base::has_version which was called 6 times, avg 13µs/call:
# 6 times (77µs+0s) by base::import at line 83, avg 13µs/call | ||||
26 | 6 | 8µs | my($base) = shift; | ||
27 | 6 | 27µs | my $vglob = ${$base.'::'}{VERSION}; | ||
28 | 6 | 52µs | return( ($vglob && *$vglob{SCALAR}) ? 1 : 0 ); | ||
29 | } | ||||
30 | |||||
31 | # spent 37µs within base::has_attr which was called 6 times, avg 6µs/call:
# 6 times (37µs+0s) by base::import at line 113, avg 6µs/call | ||||
32 | 6 | 7µs | my($proto) = shift; | ||
33 | 6 | 6µs | my($class) = ref $proto || $proto; | ||
34 | 6 | 31µs | return exists $Fattr->{$class}; | ||
35 | } | ||||
36 | |||||
37 | sub get_attr { | ||||
38 | $Fattr->{$_[0]} = [1] unless $Fattr->{$_[0]}; | ||||
39 | return $Fattr->{$_[0]}; | ||||
40 | } | ||||
41 | |||||
42 | 1 | 5µs | if ($] < 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 | } | ||||
56 | else { | ||||
57 | *get_fields = sub { | ||||
58 | # Shut up a possible typo warning. | ||||
59 | () = \%{$_[0].'::FIELDS'}; | ||||
60 | return \%{$_[0].'::FIELDS'}; | ||||
61 | } | ||||
62 | 1 | 7µs | } | ||
63 | |||||
64 | # spent 4.18ms (3.99+186µs) within base::import which was called 6 times, avg 696µs/call:
# once (3.66ms+30µs) by installer::BEGIN@30 at line 30 of /cygdrive/c/lo/libo-master/instsetoo_native/util/C:/lo/libo-master/solenv/bin/modules/installer.pm
# once (91µs+53µs) by File::Temp::BEGIN@162 at line 162 of File/Temp.pm
# once (85µs+39µs) by installer::logger::BEGIN@33 at line 33 of /cygdrive/c/lo/libo-master/instsetoo_native/util/C:/lo/libo-master/solenv/bin/modules/installer/logger.pm
# once (73µs+35µs) by installer::setupscript::BEGIN@30 at line 30 of /cygdrive/c/lo/libo-master/instsetoo_native/util/C:/lo/libo-master/solenv/bin/modules/installer/setupscript.pm
# once (62µs+27µs) by installer::strip::BEGIN@33 at line 33 of /cygdrive/c/lo/libo-master/instsetoo_native/util/C:/lo/libo-master/solenv/bin/modules/installer/strip.pm
# once (20µs+2µs) by File::Temp::BEGIN@173 at line 173 of File/Temp.pm | ||||
65 | 6 | 7µs | my $class = shift; | ||
66 | |||||
67 | 6 | 3µs | return SUCCESS unless @_; | ||
68 | |||||
69 | # List of base classes from which we will inherit %FIELDS. | ||||
70 | 6 | 2µs | my $fields_base; | ||
71 | |||||
72 | 6 | 8µs | my $inheritor = caller(0); | ||
73 | 6 | 2µs | my @isa_classes; | ||
74 | |||||
75 | 6 | 3µs | my @bases; | ||
76 | 6 | 16µs | foreach my $base (@_) { | ||
77 | 7 | 5µs | if ( $inheritor eq $base ) { | ||
78 | warn "Class '$inheritor' tried to inherit from itself\n"; | ||||
79 | } | ||||
80 | |||||
81 | 7 | 136µs | 8 | 28µs | next if grep $_->isa($base), ($inheritor, @bases); # spent 28µs making 8 calls to UNIVERSAL::isa, avg 4µs/call |
82 | |||||
83 | 6 | 27µs | 6 | 77µs | if (has_version($base)) { # spent 77µs making 6 calls to base::has_version, avg 13µs/call |
84 | ${$base.'::VERSION'} = '-1, set by base.pm' | ||||
85 | 5 | 14µs | unless defined ${$base.'::VERSION'}; | ||
86 | } | ||||
87 | else { | ||||
88 | 1 | 500ns | my $sigdie; | ||
89 | { | ||||
90 | 2 | 9µs | local $SIG{__DIE__}; | ||
91 | 1 | 31µs | eval "require $base"; # spent 3.42ms 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 | 1 | 1µs | die if $@ && $@ !~ /^Can't locate .*? at \(eval /; | ||
95 | 1 | 6µs | unless (%{"$base\::"}) { | ||
96 | require Carp; | ||||
97 | local $" = " "; | ||||
98 | Carp::croak(<<ERROR); | ||||
99 | Base 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). | ||||
102 | ERROR | ||||
103 | } | ||||
104 | 1 | 7µs | $sigdie = $SIG{__DIE__} || undef; | ||
105 | } | ||||
106 | # Make sure a global $SIG{__DIE__} makes it out of the localization. | ||||
107 | 1 | 1µs | $SIG{__DIE__} = $sigdie if defined $sigdie; | ||
108 | ${$base.'::VERSION'} = "-1, set by base.pm" | ||||
109 | 1 | 4µs | unless defined ${$base.'::VERSION'}; | ||
110 | } | ||||
111 | 6 | 11µs | push @bases, $base; | ||
112 | |||||
113 | 6 | 54µs | 12 | 81µs | if ( has_fields($base) || has_attr($base) ) { # spent 44µs making 6 calls to base::has_fields, avg 7µs/call
# spent 37µs making 6 calls to base::has_attr, avg 6µ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 | 6 | 28µs | push @{"$inheritor\::ISA"}, @isa_classes; | ||
125 | |||||
126 | 6 | 74µs | push @{"$inheritor\::ISA"}, @bases; | ||
127 | |||||
128 | 6 | 43µs | if( defined $fields_base ) { | ||
129 | inherit_fields($inheritor, $fields_base); | ||||
130 | } | ||||
131 | } | ||||
132 | |||||
133 | |||||
134 | sub 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! | ||||
149 | This will cause problems. Be sure you use base BEFORE declaring fields. | ||||
150 | END | ||||
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 | |||||
181 | 1 | 23µs | 1; | ||
182 | |||||
183 | __END__ |