| Filename | /home/doy/perl5/perlbrew/perls/perl-5.10.1/lib/5.10.1/base.pm |
| Statements | Executed 1690 statements in 23.2ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 57 | 57 | 56 | 32.7ms | 525ms | base::import (recurses: max depth 3, inclusive time 82.4ms) |
| 68 | 1 | 1 | 2.34ms | 2.34ms | base::has_version |
| 1 | 1 | 1 | 1.68ms | 3.46ms | base::BEGIN@4 |
| 68 | 1 | 1 | 1.45ms | 1.45ms | base::has_fields |
| 68 | 1 | 1 | 1.18ms | 1.18ms | base::has_attr |
| 1 | 1 | 1 | 58µs | 131µs | base::BEGIN@3 |
| 0 | 0 | 0 | 0s | 0s | base::__ANON__[:54] |
| 0 | 0 | 0 | 0s | 0s | base::__ANON__[:61] |
| 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 | 3 | 100µs | 2 | 203µs | # spent 131µs (58+72) within base::BEGIN@3 which was called:
# once (58µs+72µs) by Markdent::Types::BEGIN@9 at line 3 # spent 131µs making 1 call to base::BEGIN@3
# spent 72µs making 1 call to strict::import |
| 4 | 3 | 3.41ms | 2 | 3.59ms | # spent 3.46ms (1.68+1.77) within base::BEGIN@4 which was called:
# once (1.68ms+1.77ms) by Markdent::Types::BEGIN@9 at line 4 # spent 3.46ms making 1 call to base::BEGIN@4
# spent 133µs making 1 call to vars::import |
| 5 | 1 | 4µs | $VERSION = '2.14'; | ||
| 6 | 1 | 69µs | $VERSION = eval $VERSION; # spent 12µ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 | 5µs | my $Fattr = \%fields::attr; | ||
| 18 | |||||
| 19 | # spent 1.45ms within base::has_fields which was called 68 times, avg 21µs/call:
# 68 times (1.45ms+0s) by base::import at line 113, avg 21µs/call | ||||
| 20 | 68 | 275µs | my($base) = shift; | ||
| 21 | 68 | 471µs | my $fglob = ${"$base\::"}{FIELDS}; | ||
| 22 | 68 | 996µs | return( ($fglob && 'GLOB' eq ref($fglob) && *$fglob{HASH}) ? 1 : 0 ); | ||
| 23 | } | ||||
| 24 | |||||
| 25 | # spent 2.34ms within base::has_version which was called 68 times, avg 34µs/call:
# 68 times (2.34ms+0s) by base::import at line 83, avg 34µs/call | ||||
| 26 | 68 | 293µs | my($base) = shift; | ||
| 27 | 68 | 934µs | my $vglob = ${$base.'::'}{VERSION}; | ||
| 28 | 68 | 1.34ms | return( ($vglob && *$vglob{SCALAR}) ? 1 : 0 ); | ||
| 29 | } | ||||
| 30 | |||||
| 31 | # spent 1.18ms within base::has_attr which was called 68 times, avg 17µs/call:
# 68 times (1.18ms+0s) by base::import at line 113, avg 17µs/call | ||||
| 32 | 68 | 260µs | my($proto) = shift; | ||
| 33 | 68 | 217µs | my($class) = ref $proto || $proto; | ||
| 34 | 68 | 906µ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 | 18µ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 | 13µs | } | ||
| 63 | |||||
| 64 | # spent 525ms (32.7+492) within base::import which was called 57 times, avg 9.21ms/call:
# once (2.02ms+463ms) by Markdent::Types::BEGIN@9 at line 9 of Markdent/Types.pm
# once (2.28ms+34.2ms) by Moose::Meta::Attribute::BEGIN@23 at line 23 of Moose/Meta/Attribute.pm
# once (1.80ms+11.3ms) by Moose::Meta::Method::Overridden::BEGIN@10 at line 10 of Moose/Meta/Method/Overridden.pm
# once (420µs+253µs) by Moose::Meta::Method::Accessor::BEGIN@13 at line 13 of Moose/Meta/Method/Accessor.pm
# once (350µs+245µs) by Moose::Meta::Role::BEGIN@25 at line 25 of Moose/Meta/Role.pm
# once (365µs+166µs) by Moose::Meta::Method::Constructor::BEGIN@14 at line 14 of Moose/Meta/Method/Constructor.pm
# once (286µs+172µs) by Moose::Meta::Method::Delegation::BEGIN@14 at line 14 of Moose/Meta/Method/Delegation.pm
# once (257µs+161µs) by Moose::Meta::Method::Destructor::BEGIN@15 at line 15 of Moose/Meta/Method/Destructor.pm
# once (331µs+82µs) by Moose::Meta::TypeCoercion::Union::BEGIN@14 at line 14 of Moose/Meta/TypeCoercion/Union.pm
# once (252µs+160µs) by Moose::Meta::Method::Meta::BEGIN@11 at line 11 of Moose/Meta/Method/Meta.pm
# once (221µs+85µs) by Moose::Meta::Role::Method::Conflicting::BEGIN@9 at line 9 of Moose/Meta/Role/Method/Conflicting.pm
# once (209µs+80µs) by Moose::Meta::Role::Composite::BEGIN@13 at line 13 of Moose/Meta/Role/Composite.pm
# once (200µs+88µs) by Moose::Meta::Role::Application::ToClass::BEGIN@14 at line 14 of Moose/Meta/Role/Application/ToClass.pm
# once (194µs+93µs) by Moose::Meta::Class::Immutable::Trait::BEGIN@13 at line 13 of Moose/Meta/Class/Immutable/Trait.pm
# once (190µs+96µs) by Moose::Meta::TypeConstraint::Enum::BEGIN@13 at line 13 of Moose/Meta/TypeConstraint/Enum.pm
# once (201µs+78µs) by Markdent::Regexes::BEGIN@11 at line 11 of Markdent/Regexes.pm
# once (180µs+98µs) by Moose::Meta::Role::Application::RoleSummation::BEGIN@15 at line 15 of Moose/Meta/Role/Application/RoleSummation.pm
# once (175µs+100µs) by Moose::Meta::Instance::BEGIN@13 at line 13 of Moose/Meta/Instance.pm
# once (186µs+86µs) by Moose::Meta::Role::Attribute::BEGIN@13 at line 13 of Moose/Meta/Role/Attribute.pm
# once (186µs+86µs) by Moose::Meta::Class::BEGIN@29 at line 29 of Moose/Meta/Class.pm
# once (182µs+84µs) by Moose::Meta::TypeConstraint::DuckType::BEGIN@17 at line 17 of Moose/Meta/TypeConstraint/DuckType.pm
# once (179µs+85µs) by Moose::Meta::Role::Method::BEGIN@11 at line 11 of Moose/Meta/Role/Method.pm
# once (175µs+82µs) by Moose::Meta::TypeConstraint::Parameterizable::BEGIN@11 at line 11 of Moose/Meta/TypeConstraint/Parameterizable.pm
# once (173µs+81µs) by Moose::Meta::Method::Augmented::BEGIN@10 at line 10 of Moose/Meta/Method/Augmented.pm
# once (168µs+86µs) by Moose::Meta::Role::Application::ToRole::BEGIN@13 at line 13 of Moose/Meta/Role/Application/ToRole.pm
# once (167µs+85µs) by Moose::Meta::TypeConstraint::Class::BEGIN@14 at line 14 of Moose/Meta/TypeConstraint/Class.pm
# once (169µs+82µs) by Moose::Error::Default::BEGIN@13 at line 13 of Moose/Error/Default.pm
# once (168µs+83µs) by Moose::Meta::TypeConstraint::Role::BEGIN@14 at line 14 of Moose/Meta/TypeConstraint/Role.pm
# once (166µs+85µs) by Moose::Meta::Role::Application::ToInstance::BEGIN@13 at line 13 of Moose/Meta/Role/Application/ToInstance.pm
# once (171µs+78µs) by Variable::Magic::BEGIN@565 at line 565 of Variable/Magic.pm
# once (167µs+78µs) by Devel::Caller::BEGIN@7 at line 7 of Devel/Caller.pm
# once (162µs+84µs) by Moose::Meta::TypeConstraint::Registry::BEGIN@14 at line 14 of Moose/Meta/TypeConstraint/Registry.pm
# once (161µs+82µs) by Moose::Meta::TypeConstraint::Union::BEGIN@16 at line 16 of Moose/Meta/TypeConstraint/Union.pm
# once (160µs+83µs) by Moose::Meta::TypeConstraint::Parameterized::BEGIN@15 at line 15 of Moose/Meta/TypeConstraint/Parameterized.pm
# once (157µs+85µs) by Moose::Meta::Role::Method::Required::BEGIN@11 at line 11 of Moose/Meta/Role/Method/Required.pm
# once (165µs+76µs) by List::AllUtils::BEGIN@16 at line 16 of List/AllUtils.pm
# once (161µs+77µs) by MooseX::Types::Util::BEGIN@14 at line 14 of MooseX/Types/Util.pm
# once (149µs+82µs) by Moose::Meta::TypeConstraint::BEGIN@16 at line 16 of Moose/Meta/TypeConstraint.pm
# once (1.20ms+-1.20ms) by Class::MOP::Mixin::AttributeCore::BEGIN@12 at line 12 of Class/MOP/Mixin/AttributeCore.pm
# once (168µs+-168µs) by Class::MOP::Method::Inlined::BEGIN@13 at line 13 of Class/MOP/Method/Inlined.pm
# once (2.43ms+-2.43ms) by Class::MOP::Method::BEGIN@14 at line 14 of Class/MOP/Method.pm
# once (206µs+-206µs) by Moose::Meta::Method::BEGIN@12 at line 12 of Moose/Meta/Method.pm
# once (170µs+-170µs) by Class::MOP::Method::Wrapped::BEGIN@14 at line 14 of Class/MOP/Method/Wrapped.pm
# once (197µs+-197µs) by Class::MOP::Mixin::HasMethods::BEGIN@16 at line 16 of Class/MOP/Mixin/HasMethods.pm
# once (2.07ms+-2.07ms) by Class::MOP::Method::Accessor::BEGIN@15 at line 15 of Class/MOP/Method/Accessor.pm
# once (194µs+-194µs) by Class::MOP::Method::Generated::BEGIN@14 at line 14 of Class/MOP/Method/Generated.pm
# once (193µs+-193µs) by Moose::Meta::Mixin::AttributeCore::BEGIN@9 at line 9 of Moose/Meta/Mixin/AttributeCore.pm
# once (163µs+-163µs) by Class::MOP::Instance::BEGIN@13 at line 13 of Class/MOP/Instance.pm
# once (203µs+-203µs) by Class::MOP::Package::BEGIN@15 at line 15 of Class/MOP/Package.pm
# once (128µs+-128µs) by Sub::Name::BEGIN@50 at line 50 of Sub/Name.pm
# once (192µs+-192µs) by Sub::Name::BEGIN@49 at line 49 of Sub/Name.pm
# once (3.43ms+-3.43ms) by Class::MOP::Method::Meta::BEGIN@16 at line 16 of Class/MOP/Method/Meta.pm
# once (2.38ms+-2.38ms) by Class::MOP::Class::BEGIN@24 at line 24 of Class/MOP/Class.pm
# once (176µs+-176µs) by Class::MOP::Mixin::HasAttributes::BEGIN@13 at line 13 of Class/MOP/Mixin/HasAttributes.pm
# once (2.48ms+-2.48ms) by Class::MOP::Method::Constructor::BEGIN@15 at line 15 of Class/MOP/Method/Constructor.pm
# once (3.19ms+-3.19ms) by Class::MOP::Module::BEGIN@14 at line 14 of Class/MOP/Module.pm
# once (257µs+-257µs) by Class::MOP::Attribute::BEGIN@17 at line 17 of Class/MOP/Attribute.pm | ||||
| 65 | 57 | 249µs | my $class = shift; | ||
| 66 | |||||
| 67 | 57 | 129µs | return SUCCESS unless @_; | ||
| 68 | |||||
| 69 | # List of base classes from which we will inherit %FIELDS. | ||||
| 70 | 57 | 106µs | my $fields_base; | ||
| 71 | |||||
| 72 | 57 | 232µs | my $inheritor = caller(0); | ||
| 73 | 57 | 125µs | my @isa_classes; | ||
| 74 | |||||
| 75 | 57 | 100µs | my @bases; | ||
| 76 | 57 | 358µs | foreach my $base (@_) { | ||
| 77 | 68 | 174µs | if ( $inheritor eq $base ) { | ||
| 78 | warn "Class '$inheritor' tried to inherit from itself\n"; | ||||
| 79 | } | ||||
| 80 | |||||
| 81 | 68 | 3.49ms | 81 | 900µs | next if grep $_->isa($base), ($inheritor, @bases); # spent 900µs making 81 calls to UNIVERSAL::isa, avg 11µs/call |
| 82 | |||||
| 83 | 68 | 901µs | 68 | 2.34ms | if (has_version($base)) { # spent 2.34ms making 68 calls to base::has_version, avg 34µs/call |
| 84 | ${$base.'::VERSION'} = '-1, set by base.pm' | ||||
| 85 | 57 | 458µs | unless defined ${$base.'::VERSION'}; | ||
| 86 | } | ||||
| 87 | else { | ||||
| 88 | 11 | 22µs | my $sigdie; | ||
| 89 | { | ||||
| 90 | 22 | 251µs | local $SIG{__DIE__}; | ||
| 91 | 11 | 824µs | eval "require $base"; # spent 521µs executing statements in string eval
# spent 428µs executing statements in string eval
# spent 384µs executing statements in string eval
# spent 353µs executing statements in string eval
# spent 341µs executing statements in string eval
# spent 317µs executing statements in string eval
# spent 311µs executing statements in string eval
# spent 310µs executing statements in string eval
# spent 305µs executing statements in string eval
# spent 304µs executing statements in string eval
# spent 11µs 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 | 11 | 27µs | die if $@ && $@ !~ /^Can't locate .*? at \(eval /; | ||
| 95 | 11 | 162µ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 | 11 | 200µs | $sigdie = $SIG{__DIE__} || undef; | ||
| 105 | } | ||||
| 106 | # Make sure a global $SIG{__DIE__} makes it out of the localization. | ||||
| 107 | 11 | 26µs | $SIG{__DIE__} = $sigdie if defined $sigdie; | ||
| 108 | ${$base.'::VERSION'} = "-1, set by base.pm" | ||||
| 109 | 11 | 135µs | unless defined ${$base.'::VERSION'}; | ||
| 110 | } | ||||
| 111 | 68 | 318µs | push @bases, $base; | ||
| 112 | |||||
| 113 | 68 | 1.70ms | 136 | 2.63ms | if ( has_fields($base) || has_attr($base) ) { # spent 1.45ms making 68 calls to base::has_fields, avg 21µs/call
# spent 1.18ms making 68 calls to base::has_attr, avg 17µ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 | 57 | 784µs | push @{"$inheritor\::ISA"}, @isa_classes; | ||
| 125 | |||||
| 126 | 57 | 1.79ms | push @{"$inheritor\::ISA"}, @bases; | ||
| 127 | |||||
| 128 | 57 | 1.28ms | 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 | 18µs | 1; | ||
| 182 | |||||
| 183 | __END__ |