← Index
NYTProf Performance Profile   « line view »
For /Users/timbo/perl5/perlbrew/perls/perl-5.18.2/bin/perlcritic
  Run on Sat Mar 19 22:12:22 2016
Reported on Sat Mar 19 22:14:12 2016

Filename/Users/timbo/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/Class/Tiny.pm
StatementsExecuted 401 statements in 2.53ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
1411895µs895µsClass::Tiny::::_gen_accessor Class::Tiny::_gen_accessor
1333185µs1.01msClass::Tiny::Object::::newClass::Tiny::Object::new
411176µs1.09msClass::Tiny::::create_attributes Class::Tiny::create_attributes
111171µs71µsClass::Tiny::Object::::DESTROYClass::Tiny::Object::DESTROY
31147µs98µsClass::Tiny::Object::::__ANON__[:99]Class::Tiny::Object::__ANON__[:99]
41146µs46µsClass::Tiny::::prepare_class Class::Tiny::prepare_class
44438µs1.17msClass::Tiny::::import Class::Tiny::import
31137µs51µsClass::Tiny::::get_all_attributes_for Class::Tiny::get_all_attributes_for
141117µs17µsClass::Tiny::::CORE:match Class::Tiny::CORE:match (opcode)
11115µs15µsPod::Wordlist::::BEGIN@1.10 Pod::Wordlist::BEGIN@1.10
11110µs20µsClass::Tiny::Object::::BEGIN@92Class::Tiny::Object::BEGIN@92
1119µs18µsClass::Tiny::Object::::BEGIN@149Class::Tiny::Object::BEGIN@149
1117µs11µsPod::Wordlist::::BEGIN@4.13 Pod::Wordlist::BEGIN@4.13
1117µs19µsPod::Wordlist::::BEGIN@2.11 Pod::Wordlist::BEGIN@2.11
1116µs15µsPod::Wordlist::::BEGIN@3.12 Pod::Wordlist::BEGIN@3.12
1113µs3µsClass::Tiny::::BEGIN@10 Class::Tiny::BEGIN@10
0000s0sClass::Tiny::::get_all_attribute_defaults_for Class::Tiny::get_all_attribute_defaults_for
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1240µs115µs
# spent 15µs within Pod::Wordlist::BEGIN@1.10 which was called: # once (15µs+0s) by Pod::Wordlist::BEGIN@8 at line 1
use 5.006;
# spent 15µs making 1 call to Pod::Wordlist::BEGIN@1.10
2224µs231µs
# spent 19µs (7+12) within Pod::Wordlist::BEGIN@2.11 which was called: # once (7µs+12µs) by Pod::Wordlist::BEGIN@8 at line 2
use strict;
# spent 19µs making 1 call to Pod::Wordlist::BEGIN@2.11 # spent 12µs making 1 call to strict::import
3219µs224µs
# spent 15µs (6+9) within Pod::Wordlist::BEGIN@3.12 which was called: # once (6µs+9µs) by Pod::Wordlist::BEGIN@8 at line 3
no strict 'refs';
# spent 15µs making 1 call to Pod::Wordlist::BEGIN@3.12 # spent 9µs making 1 call to strict::unimport
4232µs215µs
# spent 11µs (7+4) within Pod::Wordlist::BEGIN@4.13 which was called: # once (7µs+4µs) by Pod::Wordlist::BEGIN@8 at line 4
use warnings;
# spent 11µs making 1 call to Pod::Wordlist::BEGIN@4.13 # spent 4µs making 1 call to warnings::import
5
6package Class::Tiny;
7# ABSTRACT: Minimalist class construction
81600nsour $VERSION = '1.000'; # VERSION
9
102512µs13µs
# spent 3µs within Class::Tiny::BEGIN@10 which was called: # once (3µs+0s) by Pod::Wordlist::BEGIN@8 at line 10
use Carp ();
# spent 3µs making 1 call to Class::Tiny::BEGIN@10
11
12# load as .pm to hide from min version scanners
13171µsrequire( $] >= 5.010 ? "mro.pm" : "MRO/Compat.pm" ); ## no critic:
14
151100nsmy %CLASS_ATTRIBUTES;
16
17
# spent 1.17ms (38µs+1.13) within Class::Tiny::import which was called 4 times, avg 293µs/call: # once (10µs+348µs) by Path::IsDev::Object::BEGIN@64 at line 75 of Path/IsDev/Object.pm # once (9µs+305µs) by Path::FindDev::Object::BEGIN@40 at line 48 of Path/FindDev/Object.pm # once (12µs+252µs) by Pod::Wordlist::BEGIN@8 at line 12 of Pod/Wordlist.pm # once (8µs+228µs) by Path::IsDev::Result::BEGIN@54 at line 54 of Path/IsDev/Result.pm
sub import {
1841µs my $class = shift;
1945µs my $pkg = caller;
2045µs446µs $class->prepare_class($pkg);
# spent 46µs making 4 calls to Class::Tiny::prepare_class, avg 12µs/call
21418µs41.09ms $class->create_attributes( $pkg, @_ ) if @_;
# spent 1.09ms making 4 calls to Class::Tiny::create_attributes, avg 272µs/call
22}
23
24
# spent 46µs within Class::Tiny::prepare_class which was called 4 times, avg 12µs/call: # 4 times (46µs+0s) by Class::Tiny::import at line 20, avg 12µs/call
sub prepare_class {
2542µs my ( $class, $pkg ) = @_;
26452µs @{"${pkg}::ISA"} = "Class::Tiny::Object" unless @{"${pkg}::ISA"};
27}
28
29# adapted from Object::Tiny and Object::Tiny::RW
30
# spent 1.09ms (176µs+912µs) within Class::Tiny::create_attributes which was called 4 times, avg 272µs/call: # 4 times (176µs+912µs) by Class::Tiny::import at line 21, avg 272µs/call
sub create_attributes {
3143µs my ( $class, $pkg, @spec ) = @_;
32416µs my %defaults = map { ref $_ eq 'HASH' ? %$_ : ( $_ => undef ) } @spec;
331448µs1417µs my @attr = grep {
# spent 17µs making 14 calls to Class::Tiny::CORE:match, avg 1µs/call
34410µs defined and !ref and /^[^\W\d]\w*$/s
35 or Carp::croak "Invalid accessor name '$_'"
36 } keys %defaults;
37418µs $CLASS_ATTRIBUTES{$pkg}{$_} = $defaults{$_} for @attr;
38462µs14895µs _gen_accessor( $pkg, $_ ) for grep { !*{"$pkg\::$_"}{CODE} } @attr;
# spent 895µs making 14 calls to Class::Tiny::_gen_accessor, avg 64µs/call
39413µs Carp::croak("Failed to generate attributes for $pkg: $@\n") if $@;
40}
41
42
# spent 895µs within Class::Tiny::_gen_accessor which was called 14 times, avg 64µs/call: # 14 times (895µs+0s) by Class::Tiny::create_attributes at line 38, avg 64µs/call
sub _gen_accessor {
43145µs my ( $pkg, $name ) = @_;
441410µs my $outer_default = $CLASS_ATTRIBUTES{$pkg}{$name};
45
46146µs my $sub = "sub $name { if (\@_ == 1) {";
471411µs if ( defined $outer_default && ref $outer_default eq 'CODE' ) {
48 $sub .= "if ( !exists \$_[0]{$name} ) { \$_[0]{$name} = \$default->(\$_[0]) }";
49 }
50 elsif ( defined $outer_default ) {
51 $sub .= "if ( !exists \$_[0]{$name} ) { \$_[0]{$name} = \$default }";
52 }
53146µs $sub .= "return \$_[0]{$name} } else { return \$_[0]{$name}=\$_[1] } }";
54
55 # default = outer_default avoids "won't stay shared" bug
5614802µs eval "package $pkg; my \$default=\$outer_default; $sub"; ## no critic
# spent 925µs executing statements in string eval
# includes 683µs spent executing 338 calls to 1 sub defined therein. # spent 550µs executing statements in string eval
# includes 308µs spent executing 235 calls to 1 sub defined therein. # spent 52µs executing statements in string eval
# includes 33µs spent executing 22 calls to 1 sub defined therein. # spent 43µs executing statements in string eval
# includes 34µs spent executing 11 calls to 1 sub defined therein. # spent 41µs executing statements in string eval
# includes 30µs spent executing 11 calls to 1 sub defined therein. # spent 9µs executing statements in string eval
# includes 7µs spent executing 1 call to 1 sub defined therein. # spent 8µs executing statements in string eval
# includes 7µs spent executing 1 call to 1 sub defined therein. # spent 7µs executing statements in string eval
# includes 6µs spent executing 1 call to 1 sub defined therein. # spent 2µs executing statements in string eval # spent 2µs executing statements in string eval # spent 2µs executing statements in string eval # spent 2µs executing statements in string eval # spent 2µs executing statements in string eval # spent 2µs executing statements in string eval
571439µs Carp::croak("Failed to generate attributes for $pkg: $@\n") if $@;
58}
59
60
# spent 51µs (37+14) within Class::Tiny::get_all_attributes_for which was called 3 times, avg 17µs/call: # 3 times (37µs+14µs) by Class::Tiny::Object::__ANON__[/Users/timbo/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/Class/Tiny.pm:99] at line 97, avg 17µs/call
sub get_all_attributes_for {
6131µs my ( $class, $pkg ) = @_;
62 my %attr =
63 map { $_ => undef }
64342µs314µs map { keys %{ $CLASS_ATTRIBUTES{$_} || {} } } @{ mro::get_linear_isa($pkg) };
# spent 14µs making 3 calls to mro::get_linear_isa, avg 5µs/call
65311µs return keys %attr;
66}
67
68sub get_all_attribute_defaults_for {
69 my ( $class, $pkg ) = @_;
70 my $defaults = {};
71 for my $p ( reverse @{ mro::get_linear_isa($pkg) } ) {
72 while ( my ( $k, $v ) = each %{ $CLASS_ATTRIBUTES{$p} || {} } ) {
73 $defaults->{$k} = $v;
74 }
75 }
76 return $defaults;
77}
78
79package Class::Tiny::Object;
80# ABSTRACT: Base class for classes built with Class::Tiny
811400nsour $VERSION = '1.000'; # VERSION
82
831100nsmy ( %LINEAR_ISA_CACHE, %BUILD_CACHE, %DEMOLISH_CACHE, %ATTR_CACHE );
84
85
# spent 98µs (47+51) within Class::Tiny::Object::__ANON__[/Users/timbo/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/Class/Tiny.pm:99] which was called 3 times, avg 33µs/call: # 3 times (47µs+51µs) by Class::Tiny::Object::new at line 103, avg 33µs/call
my $_PRECACHE = sub {
8631µs my ($class) = @_;
87 $LINEAR_ISA_CACHE{$class} =
88311µs @{"$class\::ISA"} == 1 && ${"$class\::ISA"}[0] eq "Class::Tiny::Object"
89 ? [$class]
90 : mro::get_linear_isa($class);
9133µs for my $s ( @{ $LINEAR_ISA_CACHE{$class} } ) {
922301µs230µs
# spent 20µs (10+10) within Class::Tiny::Object::BEGIN@92 which was called: # once (10µs+10µs) by Pod::Wordlist::BEGIN@8 at line 92
no warnings 'once'; # needed to avoid downstream warnings
# spent 20µs making 1 call to Class::Tiny::Object::BEGIN@92 # spent 10µs making 1 call to warnings::unimport
9334µs $BUILD_CACHE{$s} = *{"$s\::BUILD"}{CODE};
9437µs $DEMOLISH_CACHE{$s} = *{"$s\::DEMOLISH"}{CODE};
95 }
96 $ATTR_CACHE{$class} =
97311µs351µs { map { $_ => 1 } Class::Tiny->get_all_attributes_for($class) };
# spent 51µs making 3 calls to Class::Tiny::get_all_attributes_for, avg 17µs/call
9838µs return $LINEAR_ISA_CACHE{$class};
9912µs};
100
101
# spent 1.01ms (185µs+822µs) within Class::Tiny::Object::new which was called 13 times, avg 77µs/call: # 11 times (153µs+747µs) by Path::IsDev::Object::_matches at line 194 of Path/IsDev/Object.pm, avg 82µs/call # once (19µs+48µs) by Path::FindDev::__ANON__[/Users/timbo/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/Path/FindDev.pm:81] at line 78 of Path/FindDev.pm # once (13µs+27µs) by Path::FindDev::Object::__ANON__[/Users/timbo/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/Path/FindDev/Object.pm:47] at line 46 of Path/FindDev/Object.pm
sub new {
102134µs my $class = shift;
1031310µs398µs my $linear_isa = $LINEAR_ISA_CACHE{$class} || $_PRECACHE->($class);
# spent 98µs making 3 calls to Class::Tiny::Object::__ANON__[Class/Tiny.pm:99], avg 33µs/call
104134µs my $valid_attrs = $ATTR_CACHE{$class};
105
106 # handle hash ref or key/value arguments
107132µs my $args;
1081320µs if ( @_ == 1 && ref $_[0] ) {
10921µs my %copy = eval { %{ $_[0] } }; # try shallow copy
1101300ns Carp::croak("Argument to $class->new() could not be dereferenced as a hash") if $@;
1111700ns $args = \%copy;
112 }
113 elsif ( @_ % 2 == 0 ) {
114 $args = {@_};
115 }
116 else {
117 Carp::croak("$class->new() got an odd number of elements");
118 }
119
120 # create object and invoke BUILD (unless we were given __no_BUILD__)
121 my $self =
1221344µs bless { map { $_ => $args->{$_} } grep { exists $valid_attrs->{$_} } keys %$args },
123 $class;
1241315µs for my $s ( delete $args->{__no_BUILD__} ? () : reverse @$linear_isa ) {
125135µs next unless my $builder = $BUILD_CACHE{$s};
1261326µs13724µs $builder->( $self, $args );
# spent 721µs making 11 calls to Path::IsDev::Result::BUILD, avg 66µs/call # spent 2µs making 1 call to Path::FindDev::Object::BUILD # spent 2µs making 1 call to Path::IsDev::Object::BUILD
127 }
128
1291334µs return $self;
130}
131
132# Adapted from Moo and its dependencies
1331800nsrequire Devel::GlobalDestruction unless defined ${^GLOBAL_PHASE};
134
135
# spent 71µs within Class::Tiny::Object::DESTROY which was called 11 times, avg 6µs/call: # 11 times (71µs+0s) by Path::IsDev::Object::matches at line 200 of Path/FindDev/Object.pm, avg 6µs/call
sub DESTROY {
136113µs my $self = shift;
137118µs my $class = ref $self;
1381114µs my $in_global_destruction =
139 defined ${^GLOBAL_PHASE}
140 ? ${^GLOBAL_PHASE} eq 'DESTRUCT'
141 : Devel::GlobalDestruction::in_global_destruction();
1421142µs for my $s ( @{ $LINEAR_ISA_CACHE{$class} } ) {
143117µs next unless my $demolisher = $DEMOLISH_CACHE{$s};
144 my $e = do {
145 local ( $?, $@ );
146 eval { $demolisher->( $self, $in_global_destruction ) };
147 $@;
148 };
149248µs228µs
# spent 18µs (9+9) within Class::Tiny::Object::BEGIN@149 which was called: # once (9µs+9µs) by Pod::Wordlist::BEGIN@8 at line 149
no warnings 'misc'; # avoid (in cleanup) warnings
# spent 18µs making 1 call to Class::Tiny::Object::BEGIN@149 # spent 9µs making 1 call to warnings::unimport
150 die $e if $e; # rethrow
151 }
152}
153
15414µs1;
155
156
157# vim: ts=4 sts=4 sw=4 et:
158
159__END__
 
# spent 17µs within Class::Tiny::CORE:match which was called 14 times, avg 1µs/call: # 14 times (17µs+0s) by Class::Tiny::create_attributes at line 33, avg 1µs/call
sub Class::Tiny::CORE:match; # opcode