Filename | /usr/share/perl/5.14/base.pm |
Statements | Executed 2259 statements in 6.05ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
64 | 64 | 61 | 15.0ms | 27.7ms | import (recurses: max depth 2, inclusive time 9.26ms) | base::
76 | 1 | 1 | 508µs | 508µs | has_version | base::
76 | 1 | 1 | 233µs | 233µs | has_fields | base::
76 | 1 | 1 | 174µs | 174µs | has_attr | base::
1 | 1 | 1 | 23µs | 47µs | BEGIN@3 | base::
1 | 1 | 1 | 13µs | 54µ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 | 56µs | 2 | 72µs | # spent 47µs (23+24) within base::BEGIN@3 which was called:
# once (23µs+24µs) by Try::Tiny::BEGIN@14 at line 3 # spent 47µs making 1 call to base::BEGIN@3
# spent 24µs making 1 call to strict::import |
4 | 2 | 1.79ms | 2 | 96µs | # spent 54µs (13+42) within base::BEGIN@4 which was called:
# once (13µs+42µs) by Try::Tiny::BEGIN@14 at line 4 # spent 54µs making 1 call to base::BEGIN@4
# spent 42µs making 1 call to vars::import |
5 | 1 | 1µs | $VERSION = '2.16'; | ||
6 | 1 | 30µs | $VERSION = eval $VERSION; # spent 5µ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 233µs within base::has_fields which was called 76 times, avg 3µs/call:
# 76 times (233µs+0s) by base::import at line 112, avg 3µs/call | ||||
19 | 304 | 310µs | my($base) = shift; | ||
20 | my $fglob = ${"$base\::"}{FIELDS}; | ||||
21 | return( ($fglob && 'GLOB' eq ref($fglob) && *$fglob{HASH}) ? 1 : 0 ); | ||||
22 | } | ||||
23 | |||||
24 | # spent 508µs within base::has_version which was called 76 times, avg 7µs/call:
# 76 times (508µs+0s) by base::import at line 82, avg 7µs/call | ||||
25 | 304 | 584µs | my($base) = shift; | ||
26 | my $vglob = ${$base.'::'}{VERSION}; | ||||
27 | return( ($vglob && *$vglob{SCALAR}) ? 1 : 0 ); | ||||
28 | } | ||||
29 | |||||
30 | # spent 174µs within base::has_attr which was called 76 times, avg 2µs/call:
# 76 times (174µs+0s) by base::import at line 112, avg 2µs/call | ||||
31 | 228 | 223µ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 | 1 | 2µ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 | 1 | 7µs | } | ||
62 | |||||
63 | # spent 27.7ms (15.0+12.7) within base::import which was called 64 times, avg 433µs/call:
# once (3.50ms+4.60ms) by DateTime::Locale::en_US::BEGIN@25 at line 25 of DateTime/Locale/en_US.pm
# once (553µs+5.36ms) by Moose::Meta::Attribute::BEGIN@27 at line 27 of Moose/Meta/Attribute.pm
# once (558µs+3.89ms) by Class::MOP::Class::BEGIN@26 at line 26 of Class/MOP/Class.pm
# once (426µs+1.76ms) by Moose::Meta::Method::Overridden::BEGIN@12 at line 12 of Moose/Meta/Method/Overridden.pm
# once (455µs+1.45ms) by Class::MOP::Method::Accessor::BEGIN@17 at line 17 of Class/MOP/Method/Accessor.pm
# once (770µs+790µs) by Class::MOP::Method::Meta::BEGIN@18 at line 18 of Class/MOP/Method/Meta.pm
# once (557µs+183µs) by Class::MOP::Method::Constructor::BEGIN@17 at line 17 of Class/MOP/Method/Constructor.pm
# once (234µs+68µs) by Class::MOP::Mixin::AttributeCore::BEGIN@14 at line 14 of Class/MOP/Mixin/AttributeCore.pm
# once (80µs+29µs) by Try::Tiny::BEGIN@14 at line 14 of Try/Tiny.pm
# once (71µs+29µs) by DateTime::Infinite::Future::BEGIN@47 at line 47 of DateTime/Infinite.pm
# once (68µs+27µs) by DateTime::Infinite::BEGIN@12 at line 12 of DateTime/Infinite.pm
# once (66µs+28µs) by Class::Load::BEGIN@7 at line 7 of Class/Load.pm
# once (56µs+35µs) by Moose::Meta::Role::BEGIN@27 at line 27 of Moose/Meta/Role.pm
# once (62µs+27µs) by Sub::Name::BEGIN@49 at line 49 of Sub/Name.pm
# once (62µs+26µs) by DateTime::Infinite::Past::BEGIN@75 at line 75 of DateTime/Infinite.pm
# once (51µs+24µs) by Sub::Name::BEGIN@50 at line 50 of Sub/Name.pm
# once (44µs+27µs) by Moose::Meta::Role::Attribute::BEGIN@16 at line 16 of Moose/Meta/Role/Attribute.pm
# once (47µs+23µs) by Moose::Meta::Method::Constructor::BEGIN@18 at line 18 of Moose/Meta/Method/Constructor.pm
# once (44µs+24µs) by Moose::Meta::Method::Accessor::BEGIN@15 at line 15 of Moose/Meta/Method/Accessor.pm
# once (45µs+23µs) by Moose::Meta::Method::Destructor::BEGIN@17 at line 17 of Moose/Meta/Method/Destructor.pm
# once (43µs+23µs) by Class::MOP::Attribute::BEGIN@19 at line 19 of Class/MOP/Attribute.pm
# once (41µs+23µs) by Moose::Meta::Method::Meta::BEGIN@13 at line 13 of Moose/Meta/Method/Meta.pm
# once (41µs+23µs) by Moose::Meta::Method::Delegation::BEGIN@16 at line 16 of Moose/Meta/Method/Delegation.pm
# once (31µs+20µs) by Moose::Meta::Role::Composite::BEGIN@16 at line 16 of Moose/Meta/Role/Composite.pm
# once (34µs+16µs) by Moose::Meta::Class::Immutable::Trait::BEGIN@15 at line 15 of Moose/Meta/Class/Immutable/Trait.pm
# once (31µs+15µs) by JSON::BEGIN@6 at line 6 of JSON.pm
# once (32µs+12µs) by Moose::Meta::Class::BEGIN@31 at line 31 of Moose/Meta/Class.pm
# once (28µs+16µs) by Moose::Meta::TypeCoercion::Union::BEGIN@16 at line 16 of Moose/Meta/TypeCoercion/Union.pm
# once (32µs+11µs) by Encode::Alias::BEGIN@8 at line 8 of Encode/Alias.pm
# once (31µs+12µs) by Class::MOP::Method::Overload::BEGIN@15 at line 15 of Class/MOP/Method/Overload.pm
# once (27µs+16µs) by Moose::Meta::Role::Method::Required::BEGIN@17 at line 17 of Moose/Meta/Role/Method/Required.pm
# once (30µs+12µs) by Moose::Meta::Role::Method::Conflicting::BEGIN@15 at line 15 of Moose/Meta/Role/Method/Conflicting.pm
# once (31µs+12µs) by Moose::Meta::TypeConstraint::Class::BEGIN@17 at line 17 of Moose/Meta/TypeConstraint/Class.pm
# once (29µs+13µs) by Moose::Meta::Instance::BEGIN@15 at line 15 of Moose/Meta/Instance.pm
# once (29µs+12µs) by Moose::Meta::Role::Method::BEGIN@13 at line 13 of Moose/Meta/Role/Method.pm
# once (29µs+13µs) by Class::MOP::Mixin::HasAttributes::BEGIN@15 at line 15 of Class/MOP/Mixin/HasAttributes.pm
# once (29µs+12µs) by Moose::Meta::Method::Augmented::BEGIN@12 at line 12 of Moose/Meta/Method/Augmented.pm
# once (28µs+12µs) by Class::MOP::Instance::BEGIN@15 at line 15 of Class/MOP/Instance.pm
# once (29µs+11µs) by Encode::BEGIN@13 at line 13 of Encode.pm
# once (28µs+12µs) by Moose::Meta::TypeConstraint::Parameterized::BEGIN@17 at line 17 of Moose/Meta/TypeConstraint/Parameterized.pm
# once (27µs+13µs) by Moose::Error::Default::BEGIN@17 at line 17 of Moose/Error/Default.pm
# once (28µs+12µs) by Moose::Meta::Role::Application::RoleSummation::BEGIN@17 at line 17 of Moose/Meta/Role/Application/RoleSummation.pm
# once (28µs+12µs) by Class::MOP::Method::Wrapped::BEGIN@16 at line 16 of Class/MOP/Method/Wrapped.pm
# once (27µs+12µs) by Moose::Meta::TypeConstraint::Parameterizable::BEGIN@13 at line 13 of Moose/Meta/TypeConstraint/Parameterizable.pm
# once (27µs+12µs) by Moose::Meta::Role::Application::ToClass::BEGIN@17 at line 17 of Moose/Meta/Role/Application/ToClass.pm
# once (27µs+12µs) by Moose::Meta::Role::Application::ToRole::BEGIN@15 at line 15 of Moose/Meta/Role/Application/ToRole.pm
# once (27µs+12µs) by Moose::Meta::TypeConstraint::Role::BEGIN@17 at line 17 of Moose/Meta/TypeConstraint/Role.pm
# once (28µs+11µs) by Class::MOP::Mixin::HasMethods::BEGIN@21 at line 21 of Class/MOP/Mixin/HasMethods.pm
# once (27µs+12µs) by Moose::Meta::Role::Application::ToInstance::BEGIN@16 at line 16 of Moose/Meta/Role/Application/ToInstance.pm
# once (27µs+12µs) by boolean::BEGIN@14 at line 14 of boolean.pm
# once (26µs+12µs) by Moose::Meta::TypeConstraint::Registry::BEGIN@16 at line 16 of Moose/Meta/TypeConstraint/Registry.pm
# once (27µs+12µs) by Moose::Meta::TypeConstraint::Enum::BEGIN@16 at line 16 of Moose/Meta/TypeConstraint/Enum.pm
# once (27µs+12µs) by Moose::Meta::TypeConstraint::DuckType::BEGIN@20 at line 20 of Moose/Meta/TypeConstraint/DuckType.pm
# once (26µs+11µs) by Moose::Meta::TypeConstraint::Union::BEGIN@19 at line 19 of Moose/Meta/TypeConstraint/Union.pm
# once (25µs+12µs) by Moose::Meta::TypeConstraint::BEGIN@26 at line 26 of Moose/Meta/TypeConstraint.pm
# once (4.16ms+-4.16ms) by DateTime::Locale::en::BEGIN@25 at line 25 of DateTime/Locale/en.pm
# once (29µs+-29µs) by Class::MOP::Method::Generated::BEGIN@16 at line 16 of Class/MOP/Method/Generated.pm
# once (31µs+-31µs) by Class::MOP::Method::Inlined::BEGIN@15 at line 15 of Class/MOP/Method/Inlined.pm
# once (537µs+-537µs) by Class::MOP::Method::BEGIN@16 at line 16 of Class/MOP/Method.pm
# once (1.17ms+-1.17ms) by Class::MOP::Module::BEGIN@16 at line 16 of Class/MOP/Module.pm
# once (32µs+-32µs) by Moose::Meta::Method::BEGIN@14 at line 14 of Moose/Meta/Method.pm
# once (29µs+-29µs) by Class::MOP::Package::BEGIN@18 at line 18 of Class/MOP/Package.pm
# once (155µs+-155µs) by DateTime::Locale::root::BEGIN@25 at line 25 of DateTime/Locale/root.pm
# once (30µs+-30µs) by Moose::Meta::Mixin::AttributeCore::BEGIN@12 at line 12 of Moose/Meta/Mixin/AttributeCore.pm | ||||
64 | 1413 | 3.03ms | 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 | if ( $inheritor eq $base ) { | ||||
77 | warn "Class '$inheritor' tried to inherit from itself\n"; | ||||
78 | } | ||||
79 | |||||
80 | 90 | 178µs | next if grep $_->isa($base), ($inheritor, @bases); # spent 178µs making 90 calls to UNIVERSAL::isa, avg 2µs/call | ||
81 | |||||
82 | 76 | 508µs | if (has_version($base)) { # spent 508µs making 76 calls to base::has_version, avg 7µs/call | ||
83 | ${$base.'::VERSION'} = '-1, set by base.pm' | ||||
84 | unless defined ${$base.'::VERSION'}; | ||||
85 | } | ||||
86 | else { | ||||
87 | my $sigdie; | ||||
88 | { | ||||
89 | local $SIG{__DIE__}; | ||||
90 | eval "require $base"; # spent 171µs executing statements in string eval
# spent 146µs executing statements in string eval
# spent 80µs executing statements in string eval
# spent 70µs executing statements in string eval
# spent 68µs executing statements in string eval
# spent 66µs executing statements in string eval
# spent 65µs executing statements in string eval
# spent 62µs executing statements in string eval
# spent 61µs executing statements in string eval
# spent 60µs executing statements in string eval
# spent 59µs executing statements in string eval
# spent 6µs executing statements in string eval | ||||
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 | 152 | 407µs | if ( has_fields($base) || has_attr($base) ) { # spent 233µs making 76 calls to base::has_fields, avg 3µs/call
# spent 174µs making 76 calls to base::has_attr, avg 2µ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 | push @{"$inheritor\::ISA"}, @isa_classes; | ||||
124 | |||||
125 | 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 | 10µs | 1; | ||
179 | |||||
180 | __END__ |