| File | /usr/lib/perl5/5.10.1/base.pm |
| Statements Executed | 3645 |
| Statement Execution Time | 54.5ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 129 | 129 | 122 | 112ms | 357ms | base::import |
| 139 | 1 | 1 | 3.70ms | 3.70ms | base::has_version |
| 139 | 1 | 1 | 3.38ms | 3.38ms | base::has_attr |
| 139 | 1 | 1 | 2.39ms | 2.39ms | base::has_fields |
| 1 | 1 | 1 | 72µs | 151µs | base::BEGIN@4 |
| 1 | 1 | 1 | 44µs | 90µ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 | 135µs | 2 | 137µs | # spent 90µs (44+47) within base::BEGIN@3 which was called
# once (44µs+47µs) by Class::MOP::Mixin::AttributeCore::BEGIN@12 at line 3 # spent 90µs making 1 call to base::BEGIN@3
# spent 47µs making 1 call to strict::import |
| 4 | 3 | 3.61ms | 2 | 230µs | # spent 151µs (72+79) within base::BEGIN@4 which was called
# once (72µs+79µs) by Class::MOP::Mixin::AttributeCore::BEGIN@12 at line 4 # spent 151µs making 1 call to base::BEGIN@4
# spent 79µs making 1 call to vars::import |
| 5 | 1 | 3µs | $VERSION = '2.14'; | ||
| 6 | 1 | 44µs | $VERSION = eval $VERSION; | ||
| 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 | 3µs | my $Fattr = \%fields::attr; | ||
| 18 | |||||
| 19 | # spent 2.39ms within base::has_fields which was called 139 times, avg 17µs/call:
# 139 times (2.39ms+0s) by base::import at line 113, avg 17µs/call | ||||
| 20 | 139 | 350µs | my($base) = shift; | ||
| 21 | 139 | 868µs | my $fglob = ${"$base\::"}{FIELDS}; | ||
| 22 | 139 | 1.54ms | return( ($fglob && 'GLOB' eq ref($fglob) && *$fglob{HASH}) ? 1 : 0 ); | ||
| 23 | } | ||||
| 24 | |||||
| 25 | # spent 3.70ms within base::has_version which was called 139 times, avg 27µs/call:
# 139 times (3.70ms+0s) by base::import at line 83, avg 27µs/call | ||||
| 26 | 139 | 559µs | my($base) = shift; | ||
| 27 | 139 | 1.30ms | my $vglob = ${$base.'::'}{VERSION}; | ||
| 28 | 139 | 2.21ms | return( ($vglob && *$vglob{SCALAR}) ? 1 : 0 ); | ||
| 29 | } | ||||
| 30 | |||||
| 31 | # spent 3.38ms within base::has_attr which was called 139 times, avg 24µs/call:
# 139 times (3.38ms+0s) by base::import at line 113, avg 24µs/call | ||||
| 32 | 139 | 371µs | my($proto) = shift; | ||
| 33 | 139 | 1.73ms | my($class) = ref $proto || $proto; | ||
| 34 | 139 | 1.51ms | 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 | 9µs | } | ||
| 63 | |||||
| 64 | # spent 357ms (112+245) within base::import which was called 129 times, avg 2.76ms/call:
# once (5.38ms+146ms) by Epoll::View::TT::BEGIN@4 at line 4 of Epoll/View/TT.pm
# once (947µs+34.1ms) by Epoll::Model::Vote::BEGIN@5 at line 5 of Epoll/Model/Vote.pm
# once (2.80ms+29.5ms) by Moose::Meta::Attribute::BEGIN@20 at line 20 of Moose/Meta/Attribute.pm
# once (10.3ms+14.0ms) by Sub::Name::BEGIN@50 at line 50 of Sub/Name.pm
# once (10.0ms+9.35ms) by Epoll::I18N::BEGIN@3 at line 3 of (eval 0)[Locale/Maketext/Simple.pm:146] at line 146 of Locale/Maketext/Simple.pm
# once (2.03ms+9.59ms) by Class::MOP::Class::BEGIN@22 at line 22 of Class/MOP/Class.pm
# once (4.09ms+6.30ms) by Class::MOP::Method::Wrapped::BEGIN@14 at line 14 of Class/MOP/Method/Wrapped.pm
# once (3.22ms+5.60ms) by Class::MOP::Method::Accessor::BEGIN@14 at line 14 of Class/MOP/Method/Accessor.pm
# once (1.43ms+6.60ms) by HTML::Prototype::BEGIN@4 at line 4 of HTML/Prototype.pm
# once (4.30ms+2.68ms) by Epoll::DB::BEGIN@7 at line 7 of Epoll/DB.pm
# once (3.21ms+858µs) by Class::MOP::Method::Constructor::BEGIN@14 at line 14 of Class/MOP/Method/Constructor.pm
# once (3.18ms+590µs) by Crypt::RSA::BEGIN@16 at line 16 of Crypt/RSA.pm
# once (1.98ms+426µs) by Moose::Meta::Method::Overridden::BEGIN@10 at line 10 of Moose/Meta/Method/Overridden.pm
# once (2.00ms+75µs) by Moose::Meta::TypeConstraint::Parameterized::BEGIN@15 at line 15 of Moose/Meta/TypeConstraint/Parameterized.pm
# once (1.11ms+804µs) by Mail::Mailer::smtp::BEGIN@11 at line 11 of Mail/Mailer/smtp.pm
# once (1.48ms+324µs) by Tree::Simple::Visitor::FindByUID::BEGIN@11 at line 11 of Tree/Simple/Visitor/FindByUID.pm
# once (1.60ms+195µs) by Crypt::RSA::BEGIN@17 at line 17 of Crypt/RSA.pm
# once (1.33ms+448µs) by Class::MOP::Mixin::AttributeCore::BEGIN@12 at line 12 of Class/MOP/Mixin/AttributeCore.pm
# once (1.52ms+250µs) by Config::Any::INI::BEGIN@6 at line 6 of Config/Any/INI.pm
# once (1.07ms+590µs) by Class::MOP::Instance::BEGIN@13 at line 13 of Class/MOP/Instance.pm
# once (302µs+1.22ms) by Moose::Meta::TypeConstraint::Registry::BEGIN@14 at line 14 of Moose/Meta/TypeConstraint/Registry.pm
# once (1.22ms+275µs) by Catalyst::Plugin::Prototype::BEGIN@4 at line 4 of Catalyst/Plugin/Prototype.pm
# once (734µs+571µs) by Catalyst::Plugin::Session::Store::DBI::BEGIN@5 at line 5 of Catalyst/Plugin/Session/Store/DBI.pm
# once (212µs+570µs) by Moose::Meta::Method::Destructor::BEGIN@15 at line 15 of Moose/Meta/Method/Destructor.pm
# once (587µs+115µs) by Moose::Meta::Method::Constructor::BEGIN@12 at line 12 of Moose/Meta/Method/Constructor.pm
# once (586µs+114µs) by Epoll::DB::Poll::BSubmit::BEGIN@7 at line 7 of Epoll/DB/Poll/BSubmit.pm
# once (409µs+182µs) by Moose::Meta::TypeCoercion::Union::BEGIN@14 at line 14 of Moose/Meta/TypeCoercion/Union.pm
# once (339µs+219µs) by Epoll::DB::Poll::BEGIN@7 at line 7 of Epoll/DB/Poll.pm
# once (338µs+109µs) by Epoll::DB::Voting::BEGIN@7 at line 7 of Epoll/DB/Voting.pm
# once (176µs+255µs) by Variable::Magic::BEGIN@561 at line 561 of Variable/Magic.pm
# once (141µs+245µs) by Moose::Meta::TypeConstraint::Parameterizable::BEGIN@11 at line 11 of Moose/Meta/TypeConstraint/Parameterizable.pm
# once (327µs+56µs) by Epoll::DB::Poll::Type::Binary::BEGIN@7 at line 7 of Epoll/DB/Poll/Type/Binary.pm
# once (259µs+124µs) by Moose::Meta::Method::Accessor::BEGIN@11 at line 11 of Moose/Meta/Method/Accessor.pm
# once (292µs+50µs) by Epoll::Controller::Vote::BEGIN@5 at line 5 of Epoll/Controller/Vote.pm
# once (215µs+119µs) by Class::MOP::Attribute::BEGIN@17 at line 17 of Class/MOP/Attribute.pm
# once (274µs+51µs) by YAML::XS::LibYAML::BEGIN@8 at line 8 of YAML/XS/LibYAML.pm
# once (200µs+125µs) by Moose::Meta::Method::Delegation::BEGIN@14 at line 14 of Moose/Meta/Method/Delegation.pm
# once (237µs+57µs) by File::Slurp::BEGIN@60 at line 60 of File/Slurp.pm
# once (231µs+59µs) by Epoll::DB::Choice::BEGIN@7 at line 7 of Epoll/DB/Choice.pm
# once (187µs+99µs) by Moose::Meta::Role::Application::ToInstance::BEGIN@13 at line 13 of Moose/Meta/Role/Application/ToInstance.pm
# once (210µs+60µs) by Template::Parser::BEGIN@37 at line 37 of Template/Parser.pm
# once (208µs+61µs) by LaTeX::Driver::hack::BEGIN@76 at line 76 of Epoll/View/Latex.pm
# once (219µs+48µs) by Epoll::View::Latex::BEGIN@4 at line 4 of Epoll/View/Latex.pm
# once (201µs+65µs) by HTML::Prototype::Helper::Tag::BEGIN@4 at line 4 of HTML/Prototype/Helper/Tag.pm
# once (171µs+93µs) by Moose::Meta::TypeConstraint::Class::BEGIN@14 at line 14 of Moose/Meta/TypeConstraint/Class.pm
# once (204µs+58µs) by Path::Class::Dir::BEGIN@9 at line 9 of Path/Class/Dir.pm
# once (201µs+61µs) by Config::Any::XML::BEGIN@6 at line 6 of Config/Any/XML.pm
# once (201µs+60µs) by Epoll::View::Mail::BEGIN@4 at line 4 of Epoll/View/Mail.pm
# once (152µs+108µs) by Moose::Meta::Instance::BEGIN@11 at line 11 of Moose/Meta/Instance.pm
# once (195µs+60µs) by Epoll::Controller::Admin::BEGIN@5 at line 5 of Epoll/Controller/Admin.pm
# once (188µs+66µs) by Moose::Meta::TypeConstraint::Enum::BEGIN@13 at line 13 of Moose/Meta/TypeConstraint/Enum.pm
# once (192µs+61µs) by Devel::InnerPackage::BEGIN@4 at line 4 of Devel/InnerPackage.pm
# once (192µs+59µs) by Epoll::Controller::Newpoll::BEGIN@5 at line 5 of Epoll/Controller/Newpoll.pm
# once (179µs+68µs) by Crypt::RSA::Key::Private::SSH::Buffer::BEGIN@15 at line 15 of Crypt/RSA/Key/Private/SSH.pm
# once (188µs+58µs) by Encode::BEGIN@13 at line 13 of Encode.pm
# once (126µs+118µs) by Epoll::DB::Poll::Bdata::BEGIN@7 at line 7 of Epoll/DB/Poll/Bdata.pm
# once (127µs+116µs) by Encode::Alias::BEGIN@8 at line 8 of Encode/Alias.pm
# once (168µs+73µs) by Moose::Meta::Role::BEGIN@23 at line 23 of Moose/Meta/Role.pm
# once (184µs+57µs) by Class::MOP::Mixin::HasAttributes::BEGIN@13 at line 13 of Class/MOP/Mixin/HasAttributes.pm
# once (148µs+75µs) by Moose::Meta::Role::Application::ToRole::BEGIN@13 at line 13 of Moose/Meta/Role/Application/ToRole.pm
# once (151µs+72µs) by LaTeX::Driver::Exception::BEGIN@3 at line 3 of (eval 0)[Exception/Class.pm:179] at line 179 of Exception/Class.pm
# once (147µs+75µs) by Moose::Meta::Class::Immutable::Trait::BEGIN@12 at line 12 of Moose/Meta/Class/Immutable/Trait.pm
# once (162µs+59µs) by Mail::Util::BEGIN@11 at line 11 of Mail/Util.pm
# once (167µs+52µs) by Crypt::RSA::Key::BEGIN@14 at line 14 of Crypt/RSA/Key.pm
# once (117µs+101µs) by Moose::Meta::Role::Attribute::BEGIN@13 at line 13 of Moose/Meta/Role/Attribute.pm
# once (67µs+140µs) by Tree::Simple::Visitor::FindByPath::BEGIN@11 at line 11 of Tree/Simple/Visitor/FindByPath.pm
# once (145µs+59µs) by Moose::Meta::Role::Composite::BEGIN@13 at line 13 of Moose/Meta/Role/Composite.pm
# once (145µs+59µs) by File::Temp::BEGIN@162 at line 162 of File/Temp.pm
# once (143µs+60µs) by Moose::Meta::Class::BEGIN@25 at line 25 of Moose/Meta/Class.pm
# once (140µs+61µs) by Path::Class::File::BEGIN@8 at line 8 of Path/Class/File.pm
# once (142µs+57µs) by Moose::Meta::TypeConstraint::Role::BEGIN@14 at line 14 of Moose/Meta/TypeConstraint/Role.pm
# once (136µs+62µs) by Moose::Meta::TypeConstraint::DuckType::BEGIN@17 at line 17 of Moose/Meta/TypeConstraint/DuckType.pm
# once (127µs+69µs) by Template::Filters::BEGIN@25 at line 25 of Template/Filters.pm
# once (137µs+59µs) by Epoll::Controller::Ballot::BEGIN@5 at line 5 of Epoll/Controller/Ballot.pm
# once (133µs+61µs) by Exception::Class::Base::BEGIN@11 at line 11 of Exception/Class/Base.pm
# once (133µs+60µs) by Crypt::RSA::Key::Public::BEGIN@16 at line 16 of Crypt/RSA/Key/Public.pm
# once (132µs+61µs) by Template::Iterator::BEGIN@26 at line 26 of Template/Iterator.pm
# once (135µs+58µs) by Epoll::View::Ajax::BEGIN@5 at line 5 of Epoll/View/Ajax.pm
# once (130µs+62µs) by Epoll::DB::Ballot::BEGIN@7 at line 7 of Epoll/DB/Ballot.pm
# once (132µs+60µs) by Moose::Meta::Role::Application::RoleSummation::BEGIN@15 at line 15 of Moose/Meta/Role/Application/RoleSummation.pm
# once (132µs+60µs) by Moose::Meta::TypeConstraint::Union::BEGIN@16 at line 16 of Moose/Meta/TypeConstraint/Union.pm
# once (131µs+60µs) by Moose::Meta::Role::Application::ToClass::BEGIN@14 at line 14 of Moose/Meta/Role/Application/ToClass.pm
# once (130µs+60µs) by Crypt::RSA::Key::Private::BEGIN@14 at line 14 of Crypt/RSA/Key/Private.pm
# once (132µs+57µs) by Config::Any::YAML::BEGIN@6 at line 6 of Config/Any/YAML.pm
# once (131µs+57µs) by Crypt::RSA::Key::Private::SSH::BEGIN@57 at line 57 of Crypt/RSA/Key/Private/SSH.pm
# once (127µs+58µs) by Template::Plugins::BEGIN@28 at line 28 of Template/Plugins.pm
# once (126µs+59µs) by YAML::XS::BEGIN@29 at line 29 of YAML/XS.pm
# once (122µs+62µs) by Moose::Meta::TypeConstraint::BEGIN@14 at line 14 of Moose/Meta/TypeConstraint.pm
# once (128µs+55µs) by Epoll::Model::Vote::BEGIN@6 at line 6 of Epoll/Model/Vote.pm
# once (129µs+54µs) by Moose::Meta::Method::Augmented::BEGIN@10 at line 10 of Moose/Meta/Method/Augmented.pm
# once (122µs+59µs) by Config::Any::General::BEGIN@6 at line 6 of Config/Any/General.pm
# once (123µs+58µs) by Config::Any::JSON::BEGIN@6 at line 6 of Config/Any/JSON.pm
# once (144µs+33µs) by HTTP::Body::OctetStream::BEGIN@4 at line 4 of HTTP/Body/OctetStream.pm
# once (122µs+56µs) by Config::Any::Perl::BEGIN@6 at line 6 of Config/Any/Perl.pm
# once (123µs+54µs) by Crypt::RSA::Key::BEGIN@13 at line 13 of Crypt/RSA/Key.pm
# once (120µs+56µs) by Class::MOP::Mixin::HasMethods::BEGIN@14 at line 14 of Class/MOP/Mixin/HasMethods.pm
# once (123µs+52µs) by Sub::Name::BEGIN@49 at line 49 of Sub/Name.pm
# once (117µs+55µs) by LaTeX::Driver::BEGIN@32 at line 32 of LaTeX/Driver.pm
# once (117µs+53µs) by Mail::Mailer::BEGIN@11 at line 11 of Mail/Mailer.pm
# once (116µs+52µs) by Template::Directive::BEGIN@31 at line 31 of Template/Directive.pm
# once (140µs+27µs) by HTTP::Body::XFormsMultipart::BEGIN@4 at line 4 of HTTP/Body/XFormsMultipart.pm
# once (107µs+32µs) by HTTP::Body::UrlEncoded::BEGIN@4 at line 4 of HTTP/Body/UrlEncoded.pm
# once (99µs+32µs) by Moose::Meta::Role::Method::BEGIN@11 at line 11 of Moose/Meta/Role/Method.pm
# once (80µs+28µs) by HTTP::Body::MultiPart::BEGIN@4 at line 4 of HTTP/Body/MultiPart.pm
# once (75µs+28µs) by Moose::Meta::Role::Method::Required::BEGIN@11 at line 11 of Moose/Meta/Role/Method/Required.pm
# once (72µs+30µs) by Epoll::Controller::Ajax::BEGIN@5 at line 5 of Epoll/Controller/Ajax.pm
# once (67µs+30µs) by Epoll::Controller::Root::BEGIN@5 at line 5 of Epoll/Controller/Root.pm
# once (66µs+30µs) by MooseX::Types::Util::BEGIN@14 at line 14 of MooseX/Types/Util.pm
# once (63µs+28µs) by HTTP::Body::XForms::BEGIN@4 at line 4 of HTTP/Body/XForms.pm
# once (61µs+29µs) by Moose::Meta::Role::Method::Conflicting::BEGIN@9 at line 9 of Moose/Meta/Role/Method/Conflicting.pm
# once (26µs+2µs) by File::Temp::BEGIN@173 at line 173 of File/Temp.pm
# once (995µs+-995µs) by Catalyst::View::TT::BEGIN@6 at line 6 of Catalyst/View/TT.pm
# once (124µs+-124µs) by Epoll::DB::common::BEGIN@9 at line 9 of Epoll/DB/common.pm
# once (131µs+-131µs) by Moose::Meta::Method::BEGIN@10 at line 10 of Moose/Meta/Method.pm
# once (13.7ms+-13.7ms) by Template::Timer::BEGIN@60 at line 60 of Template/Timer.pm
# once (141µs+-141µs) by Moose::Meta::Mixin::AttributeCore::BEGIN@9 at line 9 of Moose/Meta/Mixin/AttributeCore.pm
# once (117µs+-117µs) by Template::Document::BEGIN@26 at line 26 of Template/Document.pm
# once (174µs+-174µs) by Template::Provider::BEGIN@43 at line 43 of Template/Provider.pm
# once (125µs+-125µs) by Class::MOP::Method::Inlined::BEGIN@13 at line 13 of Class/MOP/Method/Inlined.pm
# once (182µs+-182µs) by Class::MOP::Method::Generated::BEGIN@13 at line 13 of Class/MOP/Method/Generated.pm
# once (5.84ms+-5.84ms) by Class::Accessor::Fast::BEGIN@2 at line 2 of Class/Accessor/Fast.pm
# once (7.04ms+-7.04ms) by Class::MOP::Module::BEGIN@14 at line 14 of Class/MOP/Module.pm
# once (129µs+-129µs) by Mail::Mailer::rfc822::BEGIN@11 at line 11 of Mail/Mailer/rfc822.pm
# once (118µs+-118µs) by Template::Context::BEGIN@25 at line 25 of Template/Context.pm
# once (2.32ms+-2.32ms) by Template::BEGIN@25 at line 25 of Template.pm
# once (316µs+-316µs) by Class::MOP::Package::BEGIN@14 at line 14 of Class/MOP/Package.pm
# once (246µs+-246µs) by Class::MOP::Method::BEGIN@14 at line 14 of Class/MOP/Method.pm
# once (135µs+-135µs) by Template::Service::BEGIN@25 at line 25 of Template/Service.pm
# once (180µs+-180µs) by Template::Config::BEGIN@23 at line 23 of Template/Config.pm | ||||
| 65 | 129 | 452µs | my $class = shift; | ||
| 66 | |||||
| 67 | 129 | 210µs | return SUCCESS unless @_; | ||
| 68 | |||||
| 69 | # List of base classes from which we will inherit %FIELDS. | ||||
| 70 | 129 | 163µs | my $fields_base; | ||
| 71 | |||||
| 72 | 129 | 328µs | my $inheritor = caller(0); | ||
| 73 | 129 | 277µs | my @isa_classes; | ||
| 74 | |||||
| 75 | 129 | 154µs | my @bases; | ||
| 76 | 129 | 630µs | foreach my $base (@_) { | ||
| 77 | 140 | 273µs | if ( $inheritor eq $base ) { | ||
| 78 | warn "Class '$inheritor' tried to inherit from itself\n"; | ||||
| 79 | } | ||||
| 80 | |||||
| 81 | 140 | 6.28ms | 151 | 1.55ms | next if grep $_->isa($base), ($inheritor, @bases); # spent 1.55ms making 151 calls to UNIVERSAL::isa, avg 10µs/call |
| 82 | |||||
| 83 | 139 | 1.69ms | 139 | 3.70ms | if (has_version($base)) { # spent 3.70ms making 139 calls to base::has_version, avg 27µs/call |
| 84 | ${$base.'::VERSION'} = '-1, set by base.pm' | ||||
| 85 | 107 | 755µs | unless defined ${$base.'::VERSION'}; | ||
| 86 | } | ||||
| 87 | else { | ||||
| 88 | 32 | 48µs | my $sigdie; | ||
| 89 | { | ||||
| 90 | 64 | 409µs | local $SIG{__DIE__}; | ||
| 91 | 32 | 13.7ms | eval "require $base"; | ||
| 92 | # Only ignore "Can't locate" errors from our eval require. | ||||
| 93 | # Other fatal errors (syntax etc) must be reported. | ||||
| 94 | 32 | 182µs | die if $@ && $@ !~ /^Can't locate .*? at \(eval /; | ||
| 95 | 32 | 383µ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 | 32 | 286µs | $sigdie = $SIG{__DIE__} || undef; | ||
| 105 | } | ||||
| 106 | # Make sure a global $SIG{__DIE__} makes it out of the localization. | ||||
| 107 | 32 | 104µs | $SIG{__DIE__} = $sigdie if defined $sigdie; | ||
| 108 | ${$base.'::VERSION'} = "-1, set by base.pm" | ||||
| 109 | 32 | 710µs | unless defined ${$base.'::VERSION'}; | ||
| 110 | } | ||||
| 111 | 139 | 531µs | push @bases, $base; | ||
| 112 | |||||
| 113 | 139 | 4.57ms | 278 | 5.77ms | if ( has_fields($base) || has_attr($base) ) { # spent 3.38ms making 139 calls to base::has_attr, avg 24µs/call
# spent 2.39ms making 139 calls to base::has_fields, 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 | 129 | 1.52ms | push @{"$inheritor\::ISA"}, @isa_classes; | ||
| 125 | |||||
| 126 | 129 | 3.82ms | push @{"$inheritor\::ISA"}, @bases; | ||
| 127 | |||||
| 128 | 129 | 2.79ms | 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 | 16µs | 1; | ||
| 182 | |||||
| 183 | __END__ | ||||
| 184 | |||||
| 185 | =head1 NAME | ||||
| 186 | |||||
| 187 | base - Establish an ISA relationship with base classes at compile time | ||||
| 188 | |||||
| 189 | =head1 SYNOPSIS | ||||
| 190 | |||||
| 191 | package Baz; | ||||
| 192 | use base qw(Foo Bar); | ||||
| 193 | |||||
| 194 | =head1 DESCRIPTION | ||||
| 195 | |||||
| 196 | Unless you are using the C<fields> pragma, consider this module discouraged | ||||
| 197 | in favor of the lighter-weight C<parent>. | ||||
| 198 | |||||
| 199 | Allows you to both load one or more modules, while setting up inheritance from | ||||
| 200 | those modules at the same time. Roughly similar in effect to | ||||
| 201 | |||||
| 202 | package Baz; | ||||
| 203 | BEGIN { | ||||
| 204 | require Foo; | ||||
| 205 | require Bar; | ||||
| 206 | push @ISA, qw(Foo Bar); | ||||
| 207 | } | ||||
| 208 | |||||
| 209 | C<base> employs some heuristics to determine if a module has already been | ||||
| 210 | loaded, if it has it doesn't try again. If C<base> tries to C<require> the | ||||
| 211 | module it will not die if it cannot find the module's file, but will die on any | ||||
| 212 | other error. After all this, should your base class be empty, containing no | ||||
| 213 | symbols, it will die. This is useful for inheriting from classes in the same | ||||
| 214 | file as yourself, like so: | ||||
| 215 | |||||
| 216 | package Foo; | ||||
| 217 | sub exclaim { "I can have such a thing?!" } | ||||
| 218 | |||||
| 219 | package Bar; | ||||
| 220 | use base "Foo"; | ||||
| 221 | |||||
| 222 | If $VERSION is not detected even after loading it, <base> will define $VERSION | ||||
| 223 | in the base package, setting it to the string C<-1, set by base.pm>. | ||||
| 224 | |||||
| 225 | C<base> will also initialize the fields if one of the base classes has it. | ||||
| 226 | Multiple inheritance of fields is B<NOT> supported, if two or more base classes | ||||
| 227 | each have inheritable fields the 'base' pragma will croak. See L<fields>, | ||||
| 228 | L<public> and L<protected> for a description of this feature. | ||||
| 229 | |||||
| 230 | The base class' C<import> method is B<not> called. | ||||
| 231 | |||||
| 232 | |||||
| 233 | =head1 DIAGNOSTICS | ||||
| 234 | |||||
| 235 | =over 4 | ||||
| 236 | |||||
| 237 | =item Base class package "%s" is empty. | ||||
| 238 | |||||
| 239 | base.pm was unable to require the base package, because it was not | ||||
| 240 | found in your path. | ||||
| 241 | |||||
| 242 | =item Class 'Foo' tried to inherit from itself | ||||
| 243 | |||||
| 244 | Attempting to inherit from yourself generates a warning. | ||||
| 245 | |||||
| 246 | use Foo; | ||||
| 247 | use base 'Foo'; | ||||
| 248 | |||||
| 249 | =back | ||||
| 250 | |||||
| 251 | =head1 HISTORY | ||||
| 252 | |||||
| 253 | This module was introduced with Perl 5.004_04. | ||||
| 254 | |||||
| 255 | =head1 CAVEATS | ||||
| 256 | |||||
| 257 | Due to the limitations of the implementation, you must use | ||||
| 258 | base I<before> you declare any of your own fields. | ||||
| 259 | |||||
| 260 | |||||
| 261 | =head1 SEE ALSO | ||||
| 262 | |||||
| 263 | L<fields> | ||||
| 264 | |||||
| 265 | =cut |