← 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