| Filename | /home/ss5/perl5/perlbrew/perls/perl-5.22.0/lib/site_perl/5.22.0/Method/Generate/Accessor.pm |
| Statements | Executed 4518 statements in 5.53ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 72 | 2 | 2 | 1.28ms | 5.81ms | Method::Generate::Accessor::generate_method |
| 71 | 1 | 1 | 395µs | 1.14ms | Method::Generate::Accessor::_generate_populate_set |
| 63 | 4 | 1 | 310µs | 2.67ms | Method::Generate::Accessor::_generate_xs |
| 86 | 3 | 1 | 274µs | 626µs | Method::Generate::Accessor::_generate_simple_set |
| 86 | 1 | 1 | 151µs | 249µs | Method::Generate::Accessor::_generate_core_set |
| 71 | 1 | 1 | 151µs | 1.29ms | Method::Generate::Accessor::generate_populate_set |
| 15 | 2 | 1 | 91µs | 486µs | Method::Generate::Accessor::_generate_get |
| 42 | 2 | 1 | 84µs | 202µs | Method::Generate::Accessor::_generate_get_default |
| 87 | 3 | 1 | 81µs | 81µs | Method::Generate::Accessor::is_simple_get |
| 15 | 1 | 1 | 81µs | 261µs | Method::Generate::Accessor::_generate_use_default |
| 78 | 2 | 2 | 61µs | 61µs | Method::Generate::Accessor::has_eager_default |
| 30 | 2 | 1 | 60µs | 111µs | Method::Generate::Accessor::_generate_simple_get |
| 8 | 1 | 1 | 54µs | 65µs | Method::Generate::Accessor::_validate_codulatable |
| 5 | 1 | 1 | 45µs | 88µs | Method::Generate::Accessor::_generate_call_code |
| 17 | 2 | 1 | 37µs | 59µs | Method::Generate::Accessor::_generate_simple_has |
| 18 | 1 | 1 | 26µs | 26µs | Method::Generate::Accessor::_generate_delegation |
| 14 | 2 | 1 | 26µs | 26µs | Method::Generate::Accessor::CORE:regcomp (opcode) |
| 19 | 1 | 1 | 25µs | 25µs | Method::Generate::Accessor::has_default |
| 5 | 1 | 1 | 22µs | 31µs | Method::Generate::Accessor::_sanitize_name |
| 10 | 2 | 1 | 22µs | 22µs | Method::Generate::Accessor::is_simple_set |
| 77 | 2 | 1 | 20µs | 20µs | Method::Generate::Accessor::CORE:subst (opcode) |
| 14 | 2 | 1 | 18µs | 18µs | Method::Generate::Accessor::CORE:match (opcode) |
| 1 | 1 | 1 | 13µs | 1.19ms | Method::Generate::Accessor::BEGIN@11 |
| 2 | 1 | 1 | 11µs | 75µs | Method::Generate::Accessor::_generate_asserter |
| 1 | 1 | 1 | 10µs | 28µs | Method::Generate::Accessor::BEGIN@3 |
| 10 | 1 | 1 | 9µs | 9µs | Method::Generate::Accessor::default_construction_string |
| 1 | 1 | 1 | 7µs | 63µs | Method::Generate::Accessor::BEGIN@4 |
| 1 | 1 | 1 | 6µs | 18µs | Method::Generate::Accessor::BEGIN@10 |
| 1 | 1 | 1 | 6µs | 21µs | Method::Generate::Accessor::BEGIN@8 |
| 1 | 1 | 1 | 5µs | 28µs | Method::Generate::Accessor::BEGIN@7 |
| 1 | 1 | 1 | 4µs | 6µs | Method::Generate::Accessor::_generate_simple_clear |
| 5 | 1 | 1 | 3µs | 3µs | Method::Generate::Accessor::CORE:substcont (opcode) |
| 1 | 1 | 1 | 2µs | 2µs | Method::Generate::Accessor::BEGIN@9 |
| 1 | 1 | 1 | 2µs | 2µs | Method::Generate::Accessor::BEGIN@5 |
| 1 | 1 | 1 | 2µs | 2µs | Method::Generate::Accessor::CORE:qr (opcode) |
| 0 | 0 | 0 | 0s | 0s | Method::Generate::Accessor::__ANON__[:78] |
| 0 | 0 | 0 | 0s | 0s | Method::Generate::Accessor::_attr_desc |
| 0 | 0 | 0 | 0s | 0s | Method::Generate::Accessor::_die_overwrite |
| 0 | 0 | 0 | 0s | 0s | Method::Generate::Accessor::_generate_coerce |
| 0 | 0 | 0 | 0s | 0s | Method::Generate::Accessor::_generate_getset |
| 0 | 0 | 0 | 0s | 0s | Method::Generate::Accessor::_generate_isa_check |
| 0 | 0 | 0 | 0s | 0s | Method::Generate::Accessor::_generate_set |
| 0 | 0 | 0 | 0s | 0s | Method::Generate::Accessor::_generate_trigger |
| 0 | 0 | 0 | 0s | 0s | Method::Generate::Accessor::_wrap_attr_exception |
| 0 | 0 | 0 | 0s | 0s | Method::Generate::Accessor::generate_coerce |
| 0 | 0 | 0 | 0s | 0s | Method::Generate::Accessor::generate_get_default |
| 0 | 0 | 0 | 0s | 0s | Method::Generate::Accessor::generate_isa_check |
| 0 | 0 | 0 | 0s | 0s | Method::Generate::Accessor::generate_simple_get |
| 0 | 0 | 0 | 0s | 0s | Method::Generate::Accessor::generate_simple_has |
| 0 | 0 | 0 | 0s | 0s | Method::Generate::Accessor::generate_trigger |
| 0 | 0 | 0 | 0s | 0s | Method::Generate::Accessor::generate_use_default |
| 0 | 0 | 0 | 0s | 0s | Method::Generate::Accessor::is_simple_attribute |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | package Method::Generate::Accessor; | ||||
| 2 | |||||
| 3 | 2 | 20µs | 2 | 46µs | # spent 28µs (10+18) within Method::Generate::Accessor::BEGIN@3 which was called:
# once (10µs+18µs) by Moo::_accessor_maker_for at line 3 # spent 28µs making 1 call to Method::Generate::Accessor::BEGIN@3
# spent 18µs making 1 call to Moo::_strictures::import |
| 4 | 2 | 17µs | 2 | 119µs | # spent 63µs (7+56) within Method::Generate::Accessor::BEGIN@4 which was called:
# once (7µs+56µs) by Moo::_accessor_maker_for at line 4 # spent 63µs making 1 call to Method::Generate::Accessor::BEGIN@4
# spent 56µs making 1 call to Exporter::import |
| 5 | 2 | 26µs | 1 | 2µs | # spent 2µs within Method::Generate::Accessor::BEGIN@5 which was called:
# once (2µs+0s) by Moo::_accessor_maker_for at line 5 # spent 2µs making 1 call to Method::Generate::Accessor::BEGIN@5 |
| 6 | 1 | 5µs | our @ISA = qw(Moo::Object); | ||
| 7 | 2 | 18µs | 2 | 50µs | # spent 28µs (5+22) within Method::Generate::Accessor::BEGIN@7 which was called:
# once (5µs+22µs) by Moo::_accessor_maker_for at line 7 # spent 28µs making 1 call to Method::Generate::Accessor::BEGIN@7
# spent 22µs making 1 call to Exporter::import |
| 8 | 2 | 15µs | 2 | 36µs | # spent 21µs (6+15) within Method::Generate::Accessor::BEGIN@8 which was called:
# once (6µs+15µs) by Moo::_accessor_maker_for at line 8 # spent 21µs making 1 call to Method::Generate::Accessor::BEGIN@8
# spent 15µs making 1 call to Exporter::import |
| 9 | 2 | 15µs | 1 | 2µs | # spent 2µs within Method::Generate::Accessor::BEGIN@9 which was called:
# once (2µs+0s) by Moo::_accessor_maker_for at line 9 # spent 2µs making 1 call to Method::Generate::Accessor::BEGIN@9 |
| 10 | 2 | 51µs | 2 | 31µs | # spent 18µs (6+12) within Method::Generate::Accessor::BEGIN@10 which was called:
# once (6µs+12µs) by Moo::_accessor_maker_for at line 10 # spent 18µs making 1 call to Method::Generate::Accessor::BEGIN@10
# spent 12µs making 1 call to Module::Runtime::import |
| 11 | # spent 1.19ms (13µs+1.18) within Method::Generate::Accessor::BEGIN@11 which was called:
# once (13µs+1.18ms) by Moo::_accessor_maker_for at line 23 | ||||
| 12 | our $CAN_HAZ_XS = | ||||
| 13 | !$ENV{MOO_XS_DISABLE} | ||||
| 14 | && | ||||
| 15 | _maybe_load_module('Class::XSAccessor') | ||||
| 16 | && | ||||
| 17 | 2 | 10µs | 2 | 1.18ms | (eval { Class::XSAccessor->VERSION('1.07') }) # spent 1.18ms making 1 call to Moo::_Utils::_maybe_load_module
# spent 3µs making 1 call to UNIVERSAL::VERSION |
| 18 | ; | ||||
| 19 | our $CAN_HAZ_XS_PRED = | ||||
| 20 | $CAN_HAZ_XS && | ||||
| 21 | 2 | 6µs | 1 | 2µs | (eval { Class::XSAccessor->VERSION('1.17') }) # spent 2µs making 1 call to UNIVERSAL::VERSION |
| 22 | ; | ||||
| 23 | 1 | 2.04ms | 1 | 1.19ms | } # spent 1.19ms making 1 call to Method::Generate::Accessor::BEGIN@11 |
| 24 | |||||
| 25 | 1 | 22µs | 2 | 14µs | my $module_name_only = qr/\A$Module::Runtime::module_name_rx\z/; # spent 12µs making 1 call to Method::Generate::Accessor::CORE:regcomp
# spent 2µs making 1 call to Method::Generate::Accessor::CORE:qr |
| 26 | |||||
| 27 | sub _die_overwrite | ||||
| 28 | { | ||||
| 29 | my ($pkg, $method, $type) = @_; | ||||
| 30 | die "You cannot overwrite a locally defined method ($method) with " | ||||
| 31 | . ( $type || 'an accessor' ); | ||||
| 32 | } | ||||
| 33 | |||||
| 34 | # spent 5.81ms (1.28+4.53) within Method::Generate::Accessor::generate_method which was called 72 times, avg 81µs/call:
# 51 times (926µs+3.24ms) by Moo::Role::has at line 55 of Moo/Role.pm, avg 82µs/call
# 21 times (354µs+1.29ms) by Moo::has at line 57 of Moo.pm, avg 79µs/call | ||||
| 35 | 72 | 22µs | my ($self, $into, $name, $spec, $quote_opts) = @_; | ||
| 36 | 72 | 92µs | 72 | 15µs | $spec->{allow_overwrite}++ if $name =~ s/^\+//; # spent 15µs making 72 calls to Method::Generate::Accessor::CORE:subst, avg 203ns/call |
| 37 | 72 | 20µs | die "Must have an is" unless my $is = $spec->{is}; | ||
| 38 | 72 | 56µs | if ($is eq 'ro') { | ||
| 39 | $spec->{reader} = $name unless exists $spec->{reader}; | ||||
| 40 | } elsif ($is eq 'rw') { | ||||
| 41 | $spec->{accessor} = $name unless exists $spec->{accessor} | ||||
| 42 | or ( $spec->{reader} and $spec->{writer} ); | ||||
| 43 | } elsif ($is eq 'lazy') { | ||||
| 44 | 13 | 6µs | $spec->{reader} = $name unless exists $spec->{reader}; | ||
| 45 | 13 | 4µs | $spec->{lazy} = 1; | ||
| 46 | 13 | 10µs | $spec->{builder} ||= '_build_'.$name unless exists $spec->{default}; | ||
| 47 | } elsif ($is eq 'rwp') { | ||||
| 48 | 3 | 1µs | $spec->{reader} = $name unless exists $spec->{reader}; | ||
| 49 | 3 | 2µs | $spec->{writer} = "_set_${name}" unless exists $spec->{writer}; | ||
| 50 | } elsif ($is ne 'bare') { | ||||
| 51 | die "Unknown is ${is}"; | ||||
| 52 | } | ||||
| 53 | 72 | 13µs | if (exists $spec->{builder}) { | ||
| 54 | 13 | 2µs | if(ref $spec->{builder}) { | ||
| 55 | $self->_validate_codulatable('builder', $spec->{builder}, | ||||
| 56 | "$into->$name", 'or a method name'); | ||||
| 57 | $spec->{builder_sub} = $spec->{builder}; | ||||
| 58 | $spec->{builder} = 1; | ||||
| 59 | } | ||||
| 60 | 13 | 3µs | $spec->{builder} = '_build_'.$name if ($spec->{builder}||0) eq 1; | ||
| 61 | die "Invalid builder for $into->$name - not a valid method name" | ||||
| 62 | 13 | 62µs | 26 | 31µs | if $spec->{builder} !~ $module_name_only; # spent 18µs making 13 calls to Method::Generate::Accessor::CORE:match, avg 1µs/call
# spent 13µs making 13 calls to Method::Generate::Accessor::CORE:regcomp, avg 1µs/call |
| 63 | } | ||||
| 64 | 72 | 30µs | if (($spec->{predicate}||0) eq 1) { | ||
| 65 | $spec->{predicate} = $name =~ /^_/ ? "_has${name}" : "has_${name}"; | ||||
| 66 | } | ||||
| 67 | 72 | 16µs | if (($spec->{clearer}||0) eq 1) { | ||
| 68 | 1 | 2µs | 1 | 300ns | $spec->{clearer} = $name =~ /^_/ ? "_clear${name}" : "clear_${name}"; # spent 300ns making 1 call to Method::Generate::Accessor::CORE:match |
| 69 | } | ||||
| 70 | 72 | 29µs | if (($spec->{trigger}||0) eq 1) { | ||
| 71 | $spec->{trigger} = quote_sub('shift->_trigger_'.$name.'(@_)'); | ||||
| 72 | } | ||||
| 73 | 72 | 18µs | if (($spec->{coerce}||0) eq 1) { | ||
| 74 | my $isa = $spec->{isa}; | ||||
| 75 | if (blessed $isa and $isa->can('coercion')) { | ||||
| 76 | $spec->{coerce} = $isa->coercion; | ||||
| 77 | } elsif (blessed $isa and $isa->can('coerce')) { | ||||
| 78 | $spec->{coerce} = sub { $isa->coerce(@_) }; | ||||
| 79 | } else { | ||||
| 80 | die "Invalid coercion for $into->$name - no appropriate type constraint"; | ||||
| 81 | } | ||||
| 82 | } | ||||
| 83 | |||||
| 84 | 72 | 45µs | foreach my $setting (qw( isa coerce )) { | ||
| 85 | 144 | 30µs | next if !exists $spec->{$setting}; | ||
| 86 | $self->_validate_codulatable($setting, $spec->{$setting}, "$into->$name"); | ||||
| 87 | } | ||||
| 88 | |||||
| 89 | 72 | 31µs | 8 | 65µs | if (exists $spec->{default}) { # spent 65µs making 8 calls to Method::Generate::Accessor::_validate_codulatable, avg 8µs/call |
| 90 | if (ref $spec->{default}) { | ||||
| 91 | $self->_validate_codulatable('default', $spec->{default}, "$into->$name", | ||||
| 92 | 'or a non-ref'); | ||||
| 93 | } | ||||
| 94 | } | ||||
| 95 | |||||
| 96 | 72 | 9µs | if (exists $spec->{moosify}) { | ||
| 97 | if (ref $spec->{moosify} ne 'ARRAY') { | ||||
| 98 | $spec->{moosify} = [$spec->{moosify}]; | ||||
| 99 | } | ||||
| 100 | |||||
| 101 | foreach my $spec (@{$spec->{moosify}}) { | ||||
| 102 | $self->_validate_codulatable('moosify', $spec, "$into->$name"); | ||||
| 103 | } | ||||
| 104 | } | ||||
| 105 | |||||
| 106 | 72 | 10µs | my %methods; | ||
| 107 | 72 | 33µs | if (my $reader = $spec->{reader}) { | ||
| 108 | _die_overwrite($into, $reader, 'a reader') | ||||
| 109 | 65 | 119µs | if !$spec->{allow_overwrite} && defined &{"${into}::${reader}"}; | ||
| 110 | 65 | 130µs | 117 | 2.34ms | if (our $CAN_HAZ_XS && $self->is_simple_get($name, $spec)) { # spent 2.27ms making 52 calls to Method::Generate::Accessor::_generate_xs, avg 44µs/call
# spent 66µs making 65 calls to Method::Generate::Accessor::is_simple_get, avg 1µs/call |
| 111 | $methods{$reader} = $self->_generate_xs( | ||||
| 112 | getters => $into, $reader, $name, $spec | ||||
| 113 | ); | ||||
| 114 | } else { | ||||
| 115 | 13 | 7µs | $self->{captures} = {}; | ||
| 116 | $methods{$reader} = | ||||
| 117 | quote_sub "${into}::${reader}" | ||||
| 118 | => ' die "'.$reader.' is a read-only accessor" if @_ > 1;'."\n" | ||||
| 119 | .$self->_generate_get($name, $spec) | ||||
| 120 | => delete $self->{captures} | ||||
| 121 | 13 | 39µs | 26 | 925µs | ; # spent 498µs making 13 calls to Sub::Quote::quote_sub, avg 38µs/call
# spent 428µs making 13 calls to Method::Generate::Accessor::_generate_get, avg 33µs/call |
| 122 | } | ||||
| 123 | } | ||||
| 124 | 72 | 22µs | if (my $accessor = $spec->{accessor}) { | ||
| 125 | _die_overwrite($into, $accessor, 'an accessor') | ||||
| 126 | 7 | 14µs | if !$spec->{allow_overwrite} && defined &{"${into}::${accessor}"}; | ||
| 127 | 7 | 22µs | 21 | 289µs | if ( # spent 268µs making 7 calls to Method::Generate::Accessor::_generate_xs, avg 38µs/call
# spent 15µs making 7 calls to Method::Generate::Accessor::is_simple_set, avg 2µs/call
# spent 5µs making 7 calls to Method::Generate::Accessor::is_simple_get, avg 743ns/call |
| 128 | our $CAN_HAZ_XS | ||||
| 129 | && $self->is_simple_get($name, $spec) | ||||
| 130 | && $self->is_simple_set($name, $spec) | ||||
| 131 | ) { | ||||
| 132 | $methods{$accessor} = $self->_generate_xs( | ||||
| 133 | accessors => $into, $accessor, $name, $spec | ||||
| 134 | ); | ||||
| 135 | } else { | ||||
| 136 | $self->{captures} = {}; | ||||
| 137 | $methods{$accessor} = | ||||
| 138 | quote_sub "${into}::${accessor}" | ||||
| 139 | => $self->_generate_getset($name, $spec) | ||||
| 140 | => delete $self->{captures} | ||||
| 141 | ; | ||||
| 142 | } | ||||
| 143 | } | ||||
| 144 | 72 | 17µs | if (my $writer = $spec->{writer}) { | ||
| 145 | _die_overwrite($into, $writer, 'a writer') | ||||
| 146 | 3 | 4µs | if !$spec->{allow_overwrite} && defined &{"${into}::${writer}"}; | ||
| 147 | 3 | 6µs | 6 | 106µs | if ( # spent 99µs making 3 calls to Method::Generate::Accessor::_generate_xs, avg 33µs/call
# spent 7µs making 3 calls to Method::Generate::Accessor::is_simple_set, avg 2µs/call |
| 148 | our $CAN_HAZ_XS | ||||
| 149 | && $self->is_simple_set($name, $spec) | ||||
| 150 | ) { | ||||
| 151 | $methods{$writer} = $self->_generate_xs( | ||||
| 152 | setters => $into, $writer, $name, $spec | ||||
| 153 | ); | ||||
| 154 | } else { | ||||
| 155 | $self->{captures} = {}; | ||||
| 156 | $methods{$writer} = | ||||
| 157 | quote_sub "${into}::${writer}" | ||||
| 158 | => $self->_generate_set($name, $spec) | ||||
| 159 | => delete $self->{captures} | ||||
| 160 | ; | ||||
| 161 | } | ||||
| 162 | } | ||||
| 163 | 72 | 17µs | if (my $pred = $spec->{predicate}) { | ||
| 164 | _die_overwrite($into, $pred, 'a predicate') | ||||
| 165 | 1 | 2µs | if !$spec->{allow_overwrite} && defined &{"${into}::${pred}"}; | ||
| 166 | 1 | 1µs | 1 | 34µs | if (our $CAN_HAZ_XS && our $CAN_HAZ_XS_PRED) { # spent 34µs making 1 call to Method::Generate::Accessor::_generate_xs |
| 167 | $methods{$pred} = $self->_generate_xs( | ||||
| 168 | exists_predicates => $into, $pred, $name, $spec | ||||
| 169 | ); | ||||
| 170 | } else { | ||||
| 171 | $methods{$pred} = | ||||
| 172 | quote_sub "${into}::${pred}" => | ||||
| 173 | ' '.$self->_generate_simple_has('$_[0]', $name, $spec)."\n" | ||||
| 174 | ; | ||||
| 175 | } | ||||
| 176 | } | ||||
| 177 | 72 | 15µs | if (my $pred = $spec->{builder_sub}) { | ||
| 178 | _install_coderef( "${into}::$spec->{builder}" => $spec->{builder_sub} ); | ||||
| 179 | } | ||||
| 180 | 72 | 13µs | if (my $cl = $spec->{clearer}) { | ||
| 181 | _die_overwrite($into, $cl, 'a clearer') | ||||
| 182 | 1 | 2µs | if !$spec->{allow_overwrite} && defined &{"${into}::${cl}"}; | ||
| 183 | 1 | 4µs | 2 | 38µs | $methods{$cl} = # spent 32µs making 1 call to Sub::Quote::quote_sub
# spent 6µs making 1 call to Method::Generate::Accessor::_generate_simple_clear |
| 184 | quote_sub "${into}::${cl}" => | ||||
| 185 | $self->_generate_simple_clear('$_[0]', $name, $spec)."\n" | ||||
| 186 | ; | ||||
| 187 | } | ||||
| 188 | 72 | 16µs | if (my $hspec = $spec->{handles}) { | ||
| 189 | 2 | 2µs | my $asserter = $spec->{asserter} ||= '_assert_'.$name; | ||
| 190 | 2 | 3µs | my @specs = do { | ||
| 191 | 2 | 7µs | if (ref($hspec) eq 'ARRAY') { | ||
| 192 | map [ $_ => $_ ], @$hspec; | ||||
| 193 | } elsif (ref($hspec) eq 'HASH') { | ||||
| 194 | map [ $_ => ref($hspec->{$_}) ? @{$hspec->{$_}} : $hspec->{$_} ], | ||||
| 195 | keys %$hspec; | ||||
| 196 | } elsif (!ref($hspec)) { | ||||
| 197 | map [ $_ => $_ ], use_module('Moo::Role')->methods_provided_by(use_module($hspec)) | ||||
| 198 | } else { | ||||
| 199 | die "You gave me a handles of ${hspec} and I have no idea why"; | ||||
| 200 | } | ||||
| 201 | }; | ||||
| 202 | 2 | 3µs | foreach my $delegation_spec (@specs) { | ||
| 203 | 18 | 7µs | my ($proxy, $target, @args) = @$delegation_spec; | ||
| 204 | _die_overwrite($into, $proxy, 'a delegation') | ||||
| 205 | 18 | 37µs | if !$spec->{allow_overwrite} && defined &{"${into}::${proxy}"}; | ||
| 206 | 18 | 5µs | $self->{captures} = {}; | ||
| 207 | $methods{$proxy} = | ||||
| 208 | quote_sub "${into}::${proxy}" => | ||||
| 209 | $self->_generate_delegation($asserter, $target, \@args), | ||||
| 210 | delete $self->{captures} | ||||
| 211 | 18 | 39µs | 36 | 550µs | ; # spent 524µs making 18 calls to Sub::Quote::quote_sub, avg 29µs/call
# spent 26µs making 18 calls to Method::Generate::Accessor::_generate_delegation, avg 1µs/call |
| 212 | } | ||||
| 213 | } | ||||
| 214 | 72 | 18µs | if (my $asserter = $spec->{asserter}) { | ||
| 215 | 2 | 1µs | $self->{captures} = {}; | ||
| 216 | |||||
| 217 | |||||
| 218 | $methods{$asserter} = | ||||
| 219 | quote_sub "${into}::${asserter}" => | ||||
| 220 | $self->_generate_asserter($name, $spec), | ||||
| 221 | 2 | 8µs | 4 | 142µs | delete $self->{captures}; # spent 75µs making 2 calls to Method::Generate::Accessor::_generate_asserter, avg 37µs/call
# spent 67µs making 2 calls to Sub::Quote::quote_sub, avg 34µs/call |
| 222 | } | ||||
| 223 | 72 | 100µs | \%methods; | ||
| 224 | } | ||||
| 225 | |||||
| 226 | sub is_simple_attribute { | ||||
| 227 | my ($self, $name, $spec) = @_; | ||||
| 228 | # clearer doesn't have to be listed because it doesn't | ||||
| 229 | # affect whether defined/exists makes a difference | ||||
| 230 | !grep $spec->{$_}, | ||||
| 231 | qw(lazy default builder coerce isa trigger predicate weak_ref); | ||||
| 232 | } | ||||
| 233 | |||||
| 234 | # spent 81µs within Method::Generate::Accessor::is_simple_get which was called 87 times, avg 936ns/call:
# 65 times (66µs+0s) by Method::Generate::Accessor::generate_method at line 110, avg 1µs/call
# 15 times (10µs+0s) by Method::Generate::Accessor::_generate_get at line 257, avg 647ns/call
# 7 times (5µs+0s) by Method::Generate::Accessor::generate_method at line 127, avg 743ns/call | ||||
| 235 | 87 | 22µs | my ($self, $name, $spec) = @_; | ||
| 236 | 87 | 112µs | !($spec->{lazy} and (exists $spec->{default} or $spec->{builder})); | ||
| 237 | } | ||||
| 238 | |||||
| 239 | sub is_simple_set { | ||||
| 240 | 10 | 3µs | my ($self, $name, $spec) = @_; | ||
| 241 | 10 | 27µs | !grep $spec->{$_}, qw(coerce isa trigger weak_ref); | ||
| 242 | } | ||||
| 243 | |||||
| 244 | # spent 25µs within Method::Generate::Accessor::has_default which was called 19 times, avg 1µs/call:
# 19 times (25µs+0s) by Method::Generate::Constructor::register_attribute_specs at line 30 of Method/Generate/Constructor.pm, avg 1µs/call | ||||
| 245 | 19 | 5µs | my ($self, $name, $spec) = @_; | ||
| 246 | 19 | 30µs | $spec->{builder} or exists $spec->{default} or (($spec->{is}||'') eq 'lazy'); | ||
| 247 | } | ||||
| 248 | |||||
| 249 | # spent 61µs within Method::Generate::Accessor::has_eager_default which was called 78 times, avg 781ns/call:
# 71 times (56µs+0s) by Method::Generate::Accessor::_generate_populate_set at line 502, avg 794ns/call
# 7 times (4µs+0s) by Method::Generate::Constructor::_assign_new at line 210 of Method/Generate/Constructor.pm, avg 643ns/call | ||||
| 250 | 78 | 14µs | my ($self, $name, $spec) = @_; | ||
| 251 | 78 | 102µs | (!$spec->{lazy} and (exists $spec->{default} or $spec->{builder})); | ||
| 252 | } | ||||
| 253 | |||||
| 254 | # spent 486µs (91+395) within Method::Generate::Accessor::_generate_get which was called 15 times, avg 32µs/call:
# 13 times (81µs+347µs) by Method::Generate::Accessor::generate_method at line 121, avg 33µs/call
# 2 times (10µs+48µs) by Method::Generate::Accessor::_generate_asserter at line 621, avg 29µs/call | ||||
| 255 | 15 | 4µs | my ($self, $name, $spec) = @_; | ||
| 256 | 15 | 14µs | 15 | 71µs | my $simple = $self->_generate_simple_get('$_[0]', $name, $spec); # spent 71µs making 15 calls to Method::Generate::Accessor::_generate_simple_get, avg 5µs/call |
| 257 | 15 | 25µs | 15 | 10µs | if ($self->is_simple_get($name, $spec)) { # spent 10µs making 15 calls to Method::Generate::Accessor::is_simple_get, avg 647ns/call |
| 258 | $simple; | ||||
| 259 | } else { | ||||
| 260 | 15 | 23µs | 30 | 314µs | $self->_generate_use_default( # spent 261µs making 15 calls to Method::Generate::Accessor::_generate_use_default, avg 17µs/call
# spent 53µs making 15 calls to Method::Generate::Accessor::_generate_simple_has, avg 4µs/call |
| 261 | '$_[0]', $name, $spec, | ||||
| 262 | $self->_generate_simple_has('$_[0]', $name, $spec), | ||||
| 263 | ); | ||||
| 264 | } | ||||
| 265 | } | ||||
| 266 | |||||
| 267 | sub generate_simple_has { | ||||
| 268 | my $self = shift; | ||||
| 269 | $self->{captures} = {}; | ||||
| 270 | my $code = $self->_generate_simple_has(@_); | ||||
| 271 | ($code, delete $self->{captures}); | ||||
| 272 | } | ||||
| 273 | |||||
| 274 | # spent 59µs (37+23) within Method::Generate::Accessor::_generate_simple_has which was called 17 times, avg 3µs/call:
# 15 times (33µs+20µs) by Method::Generate::Accessor::_generate_get at line 260, avg 4µs/call
# 2 times (4µs+2µs) by Method::Generate::Accessor::_generate_asserter at line 621, avg 3µs/call | ||||
| 275 | 17 | 4µs | my ($self, $me, $name) = @_; | ||
| 276 | 17 | 34µs | 17 | 22µs | "exists ${me}->{${\quotify $name}}"; # spent 22µs making 17 calls to Sub::Quote::quotify, avg 1µs/call |
| 277 | } | ||||
| 278 | |||||
| 279 | # spent 6µs (4+2) within Method::Generate::Accessor::_generate_simple_clear which was called:
# once (4µs+2µs) by Method::Generate::Accessor::generate_method at line 183 | ||||
| 280 | 1 | 400ns | my ($self, $me, $name) = @_; | ||
| 281 | 1 | 7µs | 1 | 2µs | " delete ${me}->{${\quotify $name}}\n" # spent 2µs making 1 call to Sub::Quote::quotify |
| 282 | } | ||||
| 283 | |||||
| 284 | sub generate_get_default { | ||||
| 285 | my $self = shift; | ||||
| 286 | $self->{captures} = {}; | ||||
| 287 | my $code = $self->_generate_get_default(@_); | ||||
| 288 | ($code, delete $self->{captures}); | ||||
| 289 | } | ||||
| 290 | |||||
| 291 | sub generate_use_default { | ||||
| 292 | my $self = shift; | ||||
| 293 | $self->{captures} = {}; | ||||
| 294 | my $code = $self->_generate_use_default(@_); | ||||
| 295 | ($code, delete $self->{captures}); | ||||
| 296 | } | ||||
| 297 | |||||
| 298 | # spent 261µs (81+180) within Method::Generate::Accessor::_generate_use_default which was called 15 times, avg 17µs/call:
# 15 times (81µs+180µs) by Method::Generate::Accessor::_generate_get at line 260, avg 17µs/call | ||||
| 299 | 15 | 4µs | my ($self, $me, $name, $spec, $test) = @_; | ||
| 300 | 15 | 13µs | 15 | 23µs | my $get_value = $self->_generate_get_default($me, $name, $spec); # spent 23µs making 15 calls to Method::Generate::Accessor::_generate_get_default, avg 2µs/call |
| 301 | 15 | 3µs | if ($spec->{coerce}) { | ||
| 302 | $get_value = $self->_generate_coerce( | ||||
| 303 | $name, $get_value, | ||||
| 304 | $spec->{coerce} | ||||
| 305 | ) | ||||
| 306 | } | ||||
| 307 | $test." ? \n" | ||||
| 308 | .$self->_generate_simple_get($me, $name, $spec)."\n:" | ||||
| 309 | .($spec->{isa} ? | ||||
| 310 | " do {\n my \$value = ".$get_value.";\n" | ||||
| 311 | 15 | 42µs | 30 | 157µs | ." ".$self->_generate_isa_check($name, '$value', $spec->{isa}).";\n" # spent 117µs making 15 calls to Method::Generate::Accessor::_generate_simple_set, avg 8µs/call
# spent 40µs making 15 calls to Method::Generate::Accessor::_generate_simple_get, avg 3µs/call |
| 312 | ." ".$self->_generate_simple_set($me, $name, $spec, '$value')."\n" | ||||
| 313 | ." }\n" | ||||
| 314 | : ' ('.$self->_generate_simple_set($me, $name, $spec, $get_value).")\n" | ||||
| 315 | ); | ||||
| 316 | } | ||||
| 317 | |||||
| 318 | # spent 202µs (84+117) within Method::Generate::Accessor::_generate_get_default which was called 42 times, avg 5µs/call:
# 27 times (62µs+117µs) by Method::Generate::Accessor::_generate_populate_set at line 504, avg 7µs/call
# 15 times (23µs+0s) by Method::Generate::Accessor::_generate_use_default at line 300, avg 2µs/call | ||||
| 319 | 42 | 10µs | my ($self, $me, $name, $spec) = @_; | ||
| 320 | 42 | 71µs | 27 | 117µs | if (exists $spec->{default}) { # spent 88µs making 5 calls to Method::Generate::Accessor::_generate_call_code, avg 18µs/call
# spent 29µs making 22 calls to Sub::Quote::quotify, avg 1µs/call |
| 321 | ref $spec->{default} | ||||
| 322 | ? $self->_generate_call_code($name, 'default', $me, $spec->{default}) | ||||
| 323 | : quotify $spec->{default}; | ||||
| 324 | } | ||||
| 325 | else { | ||||
| 326 | 15 | 7µs | "${me}->${\$spec->{builder}}" | ||
| 327 | } | ||||
| 328 | } | ||||
| 329 | |||||
| 330 | sub generate_simple_get { | ||||
| 331 | my ($self, @args) = @_; | ||||
| 332 | $self->{captures} = {}; | ||||
| 333 | my $code = $self->_generate_simple_get(@args); | ||||
| 334 | ($code, delete $self->{captures}); | ||||
| 335 | } | ||||
| 336 | |||||
| 337 | # spent 111µs (60+52) within Method::Generate::Accessor::_generate_simple_get which was called 30 times, avg 4µs/call:
# 15 times (38µs+33µs) by Method::Generate::Accessor::_generate_get at line 256, avg 5µs/call
# 15 times (22µs+18µs) by Method::Generate::Accessor::_generate_use_default at line 311, avg 3µs/call | ||||
| 338 | 30 | 6µs | my ($self, $me, $name) = @_; | ||
| 339 | 30 | 17µs | 30 | 52µs | my $name_str = quotify $name; # spent 52µs making 30 calls to Sub::Quote::quotify, avg 2µs/call |
| 340 | 30 | 38µs | "${me}->{${name_str}}"; | ||
| 341 | } | ||||
| 342 | |||||
| 343 | sub _generate_set { | ||||
| 344 | my ($self, $name, $spec) = @_; | ||||
| 345 | if ($self->is_simple_set($name, $spec)) { | ||||
| 346 | $self->_generate_simple_set('$_[0]', $name, $spec, '$_[1]'); | ||||
| 347 | } else { | ||||
| 348 | my ($coerce, $trigger, $isa_check) = @{$spec}{qw(coerce trigger isa)}; | ||||
| 349 | my $value_store = '$_[0]'; | ||||
| 350 | my $code; | ||||
| 351 | if ($coerce) { | ||||
| 352 | $value_store = '$value'; | ||||
| 353 | $code = "do { my (\$self, \$value) = \@_;\n" | ||||
| 354 | ." \$value = " | ||||
| 355 | .$self->_generate_coerce($name, $value_store, $coerce).";\n"; | ||||
| 356 | } | ||||
| 357 | else { | ||||
| 358 | $code = "do { my \$self = shift;\n"; | ||||
| 359 | } | ||||
| 360 | if ($isa_check) { | ||||
| 361 | $code .= | ||||
| 362 | " ".$self->_generate_isa_check($name, $value_store, $isa_check).";\n"; | ||||
| 363 | } | ||||
| 364 | my $simple = $self->_generate_simple_set('$self', $name, $spec, $value_store); | ||||
| 365 | if ($trigger) { | ||||
| 366 | my $fire = $self->_generate_trigger($name, '$self', $value_store, $trigger); | ||||
| 367 | $code .= | ||||
| 368 | " ".$simple.";\n ".$fire.";\n" | ||||
| 369 | ." $value_store;\n"; | ||||
| 370 | } else { | ||||
| 371 | $code .= " ".$simple.";\n"; | ||||
| 372 | } | ||||
| 373 | $code .= " }"; | ||||
| 374 | $code; | ||||
| 375 | } | ||||
| 376 | } | ||||
| 377 | |||||
| 378 | sub generate_coerce { | ||||
| 379 | my $self = shift; | ||||
| 380 | $self->{captures} = {}; | ||||
| 381 | my $code = $self->_generate_coerce(@_); | ||||
| 382 | ($code, delete $self->{captures}); | ||||
| 383 | } | ||||
| 384 | |||||
| 385 | sub _attr_desc { | ||||
| 386 | my ($name, $init_arg) = @_; | ||||
| 387 | return quotify($name) if !defined($init_arg) or $init_arg eq $name; | ||||
| 388 | return quotify($name).' (constructor argument: '.quotify($init_arg).')'; | ||||
| 389 | } | ||||
| 390 | |||||
| 391 | sub _generate_coerce { | ||||
| 392 | my ($self, $name, $value, $coerce, $init_arg) = @_; | ||||
| 393 | $self->_wrap_attr_exception( | ||||
| 394 | $name, | ||||
| 395 | "coercion", | ||||
| 396 | $init_arg, | ||||
| 397 | $self->_generate_call_code($name, 'coerce', "${value}", $coerce), | ||||
| 398 | 1, | ||||
| 399 | ); | ||||
| 400 | } | ||||
| 401 | |||||
| 402 | sub generate_trigger { | ||||
| 403 | my $self = shift; | ||||
| 404 | $self->{captures} = {}; | ||||
| 405 | my $code = $self->_generate_trigger(@_); | ||||
| 406 | ($code, delete $self->{captures}); | ||||
| 407 | } | ||||
| 408 | |||||
| 409 | sub _generate_trigger { | ||||
| 410 | my ($self, $name, $obj, $value, $trigger) = @_; | ||||
| 411 | $self->_generate_call_code($name, 'trigger', "${obj}, ${value}", $trigger); | ||||
| 412 | } | ||||
| 413 | |||||
| 414 | sub generate_isa_check { | ||||
| 415 | my ($self, @args) = @_; | ||||
| 416 | $self->{captures} = {}; | ||||
| 417 | my $code = $self->_generate_isa_check(@args); | ||||
| 418 | ($code, delete $self->{captures}); | ||||
| 419 | } | ||||
| 420 | |||||
| 421 | sub _wrap_attr_exception { | ||||
| 422 | my ($self, $name, $step, $arg, $code, $want_return) = @_; | ||||
| 423 | my $prefix = quotify("${step} for "._attr_desc($name, $arg).' failed: '); | ||||
| 424 | "do {\n" | ||||
| 425 | .' local $Method::Generate::Accessor::CurrentAttribute = {'."\n" | ||||
| 426 | .' init_arg => '.quotify($arg).",\n" | ||||
| 427 | .' name => '.quotify($name).",\n" | ||||
| 428 | .' step => '.quotify($step).",\n" | ||||
| 429 | ." };\n" | ||||
| 430 | .($want_return ? ' my $_return;'."\n" : '') | ||||
| 431 | .' my $_error;'."\n" | ||||
| 432 | ." {\n" | ||||
| 433 | .' my $_old_error = $@;'."\n" | ||||
| 434 | ." if (!eval {\n" | ||||
| 435 | .' $@ = $_old_error;'."\n" | ||||
| 436 | .($want_return ? ' $_return ='."\n" : '') | ||||
| 437 | .' '.$code.";\n" | ||||
| 438 | ." 1;\n" | ||||
| 439 | ." }) {\n" | ||||
| 440 | .' $_error = $@;'."\n" | ||||
| 441 | .' if (!ref $_error) {'."\n" | ||||
| 442 | .' $_error = '.$prefix.'.$_error;'."\n" | ||||
| 443 | ." }\n" | ||||
| 444 | ." }\n" | ||||
| 445 | .' $@ = $_old_error;'."\n" | ||||
| 446 | ." }\n" | ||||
| 447 | .' die $_error if $_error;'."\n" | ||||
| 448 | .($want_return ? ' $_return;'."\n" : '') | ||||
| 449 | ."}\n" | ||||
| 450 | } | ||||
| 451 | |||||
| 452 | sub _generate_isa_check { | ||||
| 453 | my ($self, $name, $value, $check, $init_arg) = @_; | ||||
| 454 | $self->_wrap_attr_exception( | ||||
| 455 | $name, | ||||
| 456 | "isa check", | ||||
| 457 | $init_arg, | ||||
| 458 | $self->_generate_call_code($name, 'isa_check', $value, $check) | ||||
| 459 | ); | ||||
| 460 | } | ||||
| 461 | |||||
| 462 | # spent 88µs (45+43) within Method::Generate::Accessor::_generate_call_code which was called 5 times, avg 18µs/call:
# 5 times (45µs+43µs) by Method::Generate::Accessor::_generate_get_default at line 320, avg 18µs/call | ||||
| 463 | 5 | 2µs | my ($self, $name, $type, $values, $sub) = @_; | ||
| 464 | 5 | 12µs | 5 | 2µs | $sub = \&{$sub} if blessed($sub); # coderef if blessed # spent 2µs making 5 calls to Scalar::Util::blessed, avg 380ns/call |
| 465 | 5 | 14µs | 5 | 11µs | if (my $quoted = quoted_from_sub($sub)) { # spent 11µs making 5 calls to Sub::Quote::quoted_from_sub, avg 2µs/call |
| 466 | my $local = 1; | ||||
| 467 | if ($values eq '@_' || $values eq '$_[0]') { | ||||
| 468 | $local = 0; | ||||
| 469 | $values = '@_'; | ||||
| 470 | } | ||||
| 471 | my $code = $quoted->[1]; | ||||
| 472 | if (my $captures = $quoted->[2]) { | ||||
| 473 | my $cap_name = qq{\$${type}_captures_for_}.$self->_sanitize_name($name); | ||||
| 474 | $self->{captures}->{$cap_name} = \$captures; | ||||
| 475 | Sub::Quote::inlinify($code, $values, | ||||
| 476 | Sub::Quote::capture_unroll($cap_name, $captures, 6), $local); | ||||
| 477 | } else { | ||||
| 478 | Sub::Quote::inlinify($code, $values, undef, $local); | ||||
| 479 | } | ||||
| 480 | } else { | ||||
| 481 | 5 | 8µs | 5 | 31µs | my $cap_name = qq{\$${type}_for_}.$self->_sanitize_name($name); # spent 31µs making 5 calls to Method::Generate::Accessor::_sanitize_name, avg 6µs/call |
| 482 | 5 | 5µs | $self->{captures}->{$cap_name} = \$sub; | ||
| 483 | 5 | 3µs | "${cap_name}->(${values})"; | ||
| 484 | } | ||||
| 485 | } | ||||
| 486 | |||||
| 487 | # spent 31µs (22+8) within Method::Generate::Accessor::_sanitize_name which was called 5 times, avg 6µs/call:
# 5 times (22µs+8µs) by Method::Generate::Accessor::_generate_call_code at line 481, avg 6µs/call | ||||
| 488 | 5 | 1µs | my ($self, $name) = @_; | ||
| 489 | 5 | 25µs | 10 | 8µs | $name =~ s/([_\W])/sprintf('_%x', ord($1))/ge; # spent 5µs making 5 calls to Method::Generate::Accessor::CORE:subst, avg 1µs/call
# spent 3µs making 5 calls to Method::Generate::Accessor::CORE:substcont, avg 660ns/call |
| 490 | 5 | 8µs | $name; | ||
| 491 | } | ||||
| 492 | |||||
| 493 | # spent 1.29ms (151µs+1.14) within Method::Generate::Accessor::generate_populate_set which was called 71 times, avg 18µs/call:
# 71 times (151µs+1.14ms) by Method::Generate::Constructor::_assign_new at line 219 of Method/Generate/Constructor.pm, avg 18µs/call | ||||
| 494 | 71 | 7µs | my $self = shift; | ||
| 495 | 71 | 19µs | $self->{captures} = {}; | ||
| 496 | 71 | 45µs | 71 | 1.14ms | my $code = $self->_generate_populate_set(@_); # spent 1.14ms making 71 calls to Method::Generate::Accessor::_generate_populate_set, avg 16µs/call |
| 497 | 71 | 79µs | ($code, delete $self->{captures}); | ||
| 498 | } | ||||
| 499 | |||||
| 500 | # spent 1.14ms (395µs+744µs) within Method::Generate::Accessor::_generate_populate_set which was called 71 times, avg 16µs/call:
# 71 times (395µs+744µs) by Method::Generate::Accessor::generate_populate_set at line 496, avg 16µs/call | ||||
| 501 | 71 | 25µs | my ($self, $me, $name, $spec, $source, $test, $init_arg) = @_; | ||
| 502 | 71 | 122µs | 71 | 56µs | if ($self->has_eager_default($name, $spec)) { # spent 56µs making 71 calls to Method::Generate::Accessor::has_eager_default, avg 794ns/call |
| 503 | 27 | 14µs | my $get_indent = ' ' x ($spec->{isa} ? 6 : 4); | ||
| 504 | 27 | 24µs | 27 | 179µs | my $get_default = $self->_generate_get_default( # spent 179µs making 27 calls to Method::Generate::Accessor::_generate_get_default, avg 7µs/call |
| 505 | '$new', $name, $spec | ||||
| 506 | ); | ||||
| 507 | my $get_value = | ||||
| 508 | defined($spec->{init_arg}) | ||||
| 509 | 27 | 35µs | ? "(\n${get_indent} ${test}\n" | ||
| 510 | ."${get_indent} ? ${source}\n${get_indent} : " | ||||
| 511 | .$get_default | ||||
| 512 | ."\n${get_indent})" | ||||
| 513 | : $get_default; | ||||
| 514 | 27 | 4µs | if ($spec->{coerce}) { | ||
| 515 | $get_value = $self->_generate_coerce( | ||||
| 516 | $name, $get_value, | ||||
| 517 | $spec->{coerce}, $init_arg | ||||
| 518 | ) | ||||
| 519 | } | ||||
| 520 | ($spec->{isa} | ||||
| 521 | ? " {\n my \$value = ".$get_value.";\n " | ||||
| 522 | .$self->_generate_isa_check( | ||||
| 523 | $name, '$value', $spec->{isa}, $init_arg | ||||
| 524 | ).";\n" | ||||
| 525 | .' '.$self->_generate_simple_set($me, $name, $spec, '$value').";\n" | ||||
| 526 | ." }\n" | ||||
| 527 | : ' '.$self->_generate_simple_set($me, $name, $spec, $get_value).";\n" | ||||
| 528 | ) | ||||
| 529 | .($spec->{trigger} | ||||
| 530 | ? ' ' | ||||
| 531 | .$self->_generate_trigger( | ||||
| 532 | $name, $me, $self->_generate_simple_get($me, $name, $spec), | ||||
| 533 | $spec->{trigger} | ||||
| 534 | 27 | 42µs | 27 | 207µs | )." if ${test};\n" # spent 207µs making 27 calls to Method::Generate::Accessor::_generate_simple_set, avg 8µs/call |
| 535 | : '' | ||||
| 536 | ); | ||||
| 537 | } else { | ||||
| 538 | " if (${test}) {\n" | ||||
| 539 | .($spec->{coerce} | ||||
| 540 | ? " $source = " | ||||
| 541 | .$self->_generate_coerce( | ||||
| 542 | $name, $source, | ||||
| 543 | $spec->{coerce}, $init_arg | ||||
| 544 | ).";\n" | ||||
| 545 | : "" | ||||
| 546 | ) | ||||
| 547 | .($spec->{isa} | ||||
| 548 | ? " " | ||||
| 549 | .$self->_generate_isa_check( | ||||
| 550 | $name, $source, $spec->{isa}, $init_arg | ||||
| 551 | ).";\n" | ||||
| 552 | : "" | ||||
| 553 | ) | ||||
| 554 | ." ".$self->_generate_simple_set($me, $name, $spec, $source).";\n" | ||||
| 555 | .($spec->{trigger} | ||||
| 556 | ? " " | ||||
| 557 | .$self->_generate_trigger( | ||||
| 558 | $name, $me, $self->_generate_simple_get($me, $name, $spec), | ||||
| 559 | $spec->{trigger} | ||||
| 560 | 44 | 67µs | 44 | 302µs | ).";\n" # spent 302µs making 44 calls to Method::Generate::Accessor::_generate_simple_set, avg 7µs/call |
| 561 | : "" | ||||
| 562 | ) | ||||
| 563 | ." }\n"; | ||||
| 564 | } | ||||
| 565 | } | ||||
| 566 | |||||
| 567 | # spent 249µs (151+97) within Method::Generate::Accessor::_generate_core_set which was called 86 times, avg 3µs/call:
# 86 times (151µs+97µs) by Method::Generate::Accessor::_generate_simple_set at line 576, avg 3µs/call | ||||
| 568 | 86 | 15µs | my ($self, $me, $name, $spec, $value) = @_; | ||
| 569 | 86 | 34µs | 86 | 97µs | my $name_str = quotify $name; # spent 97µs making 86 calls to Sub::Quote::quotify, avg 1µs/call |
| 570 | 86 | 110µs | "${me}->{${name_str}} = ${value}"; | ||
| 571 | } | ||||
| 572 | |||||
| 573 | # spent 626µs (274+352) within Method::Generate::Accessor::_generate_simple_set which was called 86 times, avg 7µs/call:
# 44 times (129µs+173µs) by Method::Generate::Accessor::_generate_populate_set at line 560, avg 7µs/call
# 27 times (91µs+116µs) by Method::Generate::Accessor::_generate_populate_set at line 534, avg 8µs/call
# 15 times (53µs+64µs) by Method::Generate::Accessor::_generate_use_default at line 311, avg 8µs/call | ||||
| 574 | 86 | 21µs | my ($self, $me, $name, $spec, $value) = @_; | ||
| 575 | 86 | 36µs | 86 | 103µs | my $name_str = quotify $name; # spent 103µs making 86 calls to Sub::Quote::quotify, avg 1µs/call |
| 576 | 86 | 48µs | 86 | 249µs | my $simple = $self->_generate_core_set($me, $name, $spec, $value); # spent 249µs making 86 calls to Method::Generate::Accessor::_generate_core_set, avg 3µs/call |
| 577 | |||||
| 578 | 86 | 102µs | if ($spec->{weak_ref}) { | ||
| 579 | require Scalar::Util; | ||||
| 580 | my $get = $self->_generate_simple_get($me, $name, $spec); | ||||
| 581 | |||||
| 582 | # Perl < 5.8.3 can't weaken refs to readonly vars | ||||
| 583 | # (e.g. string constants). This *can* be solved by: | ||||
| 584 | # | ||||
| 585 | # &Internals::SvREADONLY($foo, 0); | ||||
| 586 | # Scalar::Util::weaken($foo); | ||||
| 587 | # &Internals::SvREADONLY($foo, 1); | ||||
| 588 | # | ||||
| 589 | # but requires Internal functions and is just too damn crazy | ||||
| 590 | # so simply throw a better exception | ||||
| 591 | my $weak_simple = "do { Scalar::Util::weaken(${simple}); no warnings 'void'; $get }"; | ||||
| 592 | Moo::_Utils::lt_5_8_3() ? <<"EOC" : $weak_simple; | ||||
| 593 | eval { Scalar::Util::weaken($simple); 1 } | ||||
| 594 | ? do { no warnings 'void'; $get } | ||||
| 595 | : do { | ||||
| 596 | if( \$@ =~ /Modification of a read-only value attempted/) { | ||||
| 597 | require Carp; | ||||
| 598 | Carp::croak( sprintf ( | ||||
| 599 | 'Reference to readonly value in "%s" can not be weakened on Perl < 5.8.3', | ||||
| 600 | $name_str, | ||||
| 601 | ) ); | ||||
| 602 | } else { | ||||
| 603 | die \$@; | ||||
| 604 | } | ||||
| 605 | } | ||||
| 606 | EOC | ||||
| 607 | } else { | ||||
| 608 | 86 | 15µs | $simple; | ||
| 609 | } | ||||
| 610 | } | ||||
| 611 | |||||
| 612 | sub _generate_getset { | ||||
| 613 | my ($self, $name, $spec) = @_; | ||||
| 614 | q{(@_ > 1}."\n ? ".$self->_generate_set($name, $spec) | ||||
| 615 | ."\n : ".$self->_generate_get($name, $spec)."\n )"; | ||||
| 616 | } | ||||
| 617 | |||||
| 618 | # spent 75µs (11+64) within Method::Generate::Accessor::_generate_asserter which was called 2 times, avg 37µs/call:
# 2 times (11µs+64µs) by Method::Generate::Accessor::generate_method at line 221, avg 37µs/call | ||||
| 619 | 2 | 1µs | my ($self, $name, $spec) = @_; | ||
| 620 | |||||
| 621 | 2 | 8µs | 4 | 64µs | "do {\n" # spent 58µs making 2 calls to Method::Generate::Accessor::_generate_get, avg 29µs/call
# spent 6µs making 2 calls to Method::Generate::Accessor::_generate_simple_has, avg 3µs/call |
| 622 | ." my \$val = ".$self->_generate_get($name, $spec).";\n" | ||||
| 623 | ." unless (".$self->_generate_simple_has('$_[0]', $name, $spec).") {\n" | ||||
| 624 | .qq! die "Attempted to access '${name}' but it is not set";\n! | ||||
| 625 | ." }\n" | ||||
| 626 | ." \$val;\n" | ||||
| 627 | ."}\n"; | ||||
| 628 | } | ||||
| 629 | # spent 26µs within Method::Generate::Accessor::_generate_delegation which was called 18 times, avg 1µs/call:
# 18 times (26µs+0s) by Method::Generate::Accessor::generate_method at line 211, avg 1µs/call | ||||
| 630 | 18 | 4µs | my ($self, $asserter, $target, $args) = @_; | ||
| 631 | 18 | 3µs | my $arg_string = do { | ||
| 632 | 18 | 4µs | if (@$args) { | ||
| 633 | # I could, I reckon, linearise out non-refs here using quotify | ||||
| 634 | # plus something to check for numbers but I'm unsure if it's worth it | ||||
| 635 | $self->{captures}{'@curries'} = $args; | ||||
| 636 | '@curries, @_'; | ||||
| 637 | } else { | ||||
| 638 | 18 | 3µs | '@_'; | ||
| 639 | } | ||||
| 640 | }; | ||||
| 641 | 18 | 24µs | "shift->${asserter}->${target}(${arg_string});"; | ||
| 642 | } | ||||
| 643 | |||||
| 644 | # spent 2.67ms (310µs+2.36) within Method::Generate::Accessor::_generate_xs which was called 63 times, avg 42µs/call:
# 52 times (271µs+2.00ms) by Method::Generate::Accessor::generate_method at line 110, avg 44µs/call
# 7 times (26µs+243µs) by Method::Generate::Accessor::generate_method at line 127, avg 38µs/call
# 3 times (10µs+89µs) by Method::Generate::Accessor::generate_method at line 147, avg 33µs/call
# once (3µs+31µs) by Method::Generate::Accessor::generate_method at line 166 | ||||
| 645 | 63 | 20µs | my ($self, $type, $into, $name, $slot) = @_; | ||
| 646 | 63 | 128µs | 63 | 2.31ms | Class::XSAccessor->import( # spent 2.31ms making 63 calls to Class::XSAccessor::import, avg 37µs/call |
| 647 | class => $into, | ||||
| 648 | $type => { $name => $slot }, | ||||
| 649 | replace => 1, | ||||
| 650 | ); | ||||
| 651 | 63 | 217µs | 63 | 48µs | $into->can($name); # spent 48µs making 63 calls to UNIVERSAL::can, avg 768ns/call |
| 652 | } | ||||
| 653 | |||||
| 654 | 10 | 14µs | # spent 9µs within Method::Generate::Accessor::default_construction_string which was called 10 times, avg 860ns/call:
# 10 times (9µs+0s) by Method::Generate::Constructor::_build_construction_string at line 69 of Method/Generate/Constructor.pm, avg 860ns/call | ||
| 655 | |||||
| 656 | # spent 65µs (54+11) within Method::Generate::Accessor::_validate_codulatable which was called 8 times, avg 8µs/call:
# 8 times (54µs+11µs) by Method::Generate::Accessor::generate_method at line 89, avg 8µs/call | ||||
| 657 | 8 | 3µs | my ($self, $setting, $value, $into, $appended) = @_; | ||
| 658 | 8 | 21µs | 8 | 11µs | my $invalid = "Invalid $setting '" . overload::StrVal($value) # spent 11µs making 8 calls to overload::AddrRef, avg 1µs/call |
| 659 | . "' for $into not a coderef"; | ||||
| 660 | 8 | 4µs | $invalid .= " $appended" if $appended; | ||
| 661 | |||||
| 662 | 8 | 4µs | unless (ref $value and (ref $value eq 'CODE' or blessed($value))) { | ||
| 663 | die "$invalid or code-convertible object"; | ||||
| 664 | } | ||||
| 665 | |||||
| 666 | 16 | 6µs | unless (eval { \&$value }) { | ||
| 667 | die "$invalid and could not be converted to a coderef: $@"; | ||||
| 668 | } | ||||
| 669 | |||||
| 670 | 8 | 10µs | 1; | ||
| 671 | } | ||||
| 672 | |||||
| 673 | 1 | 3µs | 1; | ||
sub Method::Generate::Accessor::CORE:match; # opcode | |||||
# spent 2µs within Method::Generate::Accessor::CORE:qr which was called:
# once (2µs+0s) by Moo::_accessor_maker_for at line 25 | |||||
sub Method::Generate::Accessor::CORE:regcomp; # opcode | |||||
sub Method::Generate::Accessor::CORE:subst; # opcode | |||||
# spent 3µs within Method::Generate::Accessor::CORE:substcont which was called 5 times, avg 660ns/call:
# 5 times (3µs+0s) by Method::Generate::Accessor::_sanitize_name at line 489, avg 660ns/call |