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