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