← Index
NYTProf Performance Profile   « block view • line view • sub view »
For mentat.storage.mongo.pl
  Run on Tue Jun 24 09:58:41 2014
Reported on Tue Jun 24 09:59:28 2014

Filename/usr/share/perl/5.14/base.pm
StatementsExecuted 2259 statements in 6.05ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
64646115.0ms27.7msbase::::importbase::import (recurses: max depth 2, inclusive time 9.26ms)
7611508µs508µsbase::::has_versionbase::has_version
7611233µs233µsbase::::has_fieldsbase::has_fields
7611174µs174µsbase::::has_attrbase::has_attr
11123µs47µsbase::::BEGIN@3base::BEGIN@3
11113µs54µsbase::::BEGIN@4base::BEGIN@4
0000s0sbase::::__ANON__[:53]base::__ANON__[:53]
0000s0sbase::::__ANON__[:60]base::__ANON__[:60]
0000s0sbase::::get_attrbase::get_attr
0000s0sbase::::inherit_fieldsbase::inherit_fields
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package base;
2
3256µs272µ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
use strict 'vars';
# spent 47µs making 1 call to base::BEGIN@3 # spent 24µs making 1 call to strict::import
421.79ms296µ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
use vars qw($VERSION);
# spent 54µs making 1 call to base::BEGIN@4 # spent 42µs making 1 call to vars::import
511µs$VERSION = '2.16';
6130µs$VERSION = eval $VERSION;
# spent 5µs executing statements in string eval
7
8# constant.pm is slow
9sub SUCCESS () { 1 }
10
11sub PUBLIC () { 2**0 }
12sub PRIVATE () { 2**1 }
13sub INHERITED () { 2**2 }
14sub PROTECTED () { 2**3 }
15
1612µsmy $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
sub has_fields {
197632µs my($base) = shift;
2015288µs my $fglob = ${"$base\::"}{FIELDS};
2176190µs 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
sub has_version {
257640µs my($base) = shift;
26152203µs my $vglob = ${$base.'::'}{VERSION};
2776341µs 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
sub has_attr {
317628µs my($proto) = shift;
327631µs my($class) = ref $proto || $proto;
3376165µs return exists $Fattr->{$class};
34}
35
36sub get_attr {
37 $Fattr->{$_[0]} = [1] unless $Fattr->{$_[0]};
38 return $Fattr->{$_[0]};
39}
40
4112µsif ($] < 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}
55else {
56 *get_fields = sub {
57 # Shut up a possible typo warning.
58 () = \%{$_[0].'::FIELDS'};
59 return \%{$_[0].'::FIELDS'};
60 }
6117µ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
sub import {
646431µs my $class = shift;
65
666428µs return SUCCESS unless @_;
67
68 # List of base classes from which we will inherit %FIELDS.
69648µs my $fields_base;
70
716436µs my $inheritor = caller(0);
726413µs my @isa_classes;
73
74646µs my @bases;
756465µs foreach my $base (@_) {
767624µs if ( $inheritor eq $base ) {
77 warn "Class '$inheritor' tried to inherit from itself\n";
78 }
79
8076785µs90178µs next if grep $_->isa($base), ($inheritor, @bases);
# spent 178µs making 90 calls to UNIVERSAL::isa, avg 2µs/call
81
8276133µs76508µs if (has_version($base)) {
# spent 508µs making 76 calls to base::has_version, avg 7µs/call
836625µs ${$base.'::VERSION'} = '-1, set by base.pm'
846468µs unless defined ${$base.'::VERSION'};
85 }
86 else {
87122µs my $sigdie;
88 {
892440µs local $SIG{__DIE__};
9012309µs 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.
93123µs die if $@ && $@ !~ /^Can't locate .*? at \(eval /;
942454µs unless (%{"$base\::"}) {
95 require Carp;
96 local $" = " ";
97 Carp::croak(<<ERROR);
98Base 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).
101ERROR
102 }
1031245µs $sigdie = $SIG{__DIE__} || undef;
104 }
105 # Make sure a global $SIG{__DIE__} makes it out of the localization.
106123µs $SIG{__DIE__} = $sigdie if defined $sigdie;
1071510µs ${$base.'::VERSION'} = "-1, set by base.pm"
1081231µs unless defined ${$base.'::VERSION'};
109 }
1107652µs push @bases, $base;
111
11276247µs152407µ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.
123128184µs push @{"$inheritor\::ISA"}, @isa_classes;
124
125128553µs push @{"$inheritor\::ISA"}, @bases;
126
12764278µs if( defined $fields_base ) {
128 inherit_fields($inheritor, $fields_base);
129 }
130}
131
132sub 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!
147This will cause problems. Be sure you use base BEFORE declaring fields.
148END
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
178110µs1;
179
180__END__