| Filename | /usr/local/share/perl/5.18.2/Method/Generate/Accessor.pm |
| Statements | Executed 913 statements in 7.58ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 12 | 2 | 1 | 7.58ms | 7.80ms | Method::Generate::Accessor::_generate_call_code |
| 1 | 1 | 1 | 1.49ms | 2.14ms | Method::Generate::Accessor::BEGIN@9 |
| 9 | 1 | 1 | 302µs | 1.43ms | Method::Generate::Accessor::generate_method |
| 15 | 1 | 1 | 279µs | 8.71ms | Method::Generate::Accessor::_generate_populate_set |
| 15 | 1 | 1 | 136µs | 380µs | Method::Generate::Accessor::_generate_simple_set |
| 12 | 1 | 1 | 135µs | 186µs | Method::Generate::Accessor::_sanitize_name |
| 15 | 1 | 1 | 108µs | 8.82ms | Method::Generate::Accessor::generate_populate_set |
| 12 | 2 | 1 | 99µs | 119µs | Method::Generate::Accessor::_validate_codulatable |
| 15 | 1 | 1 | 94µs | 166µs | Method::Generate::Accessor::_generate_core_set |
| 9 | 2 | 1 | 91µs | 972µs | Method::Generate::Accessor::_generate_xs |
| 3 | 1 | 1 | 61µs | 138µs | Method::Generate::Accessor::_wrap_attr_exception |
| 9 | 1 | 1 | 48µs | 7.76ms | Method::Generate::Accessor::_generate_get_default |
| 15 | 1 | 1 | 38µs | 38µs | Method::Generate::Accessor::has_eager_default |
| 21 | 2 | 1 | 37µs | 37µs | Method::Generate::Accessor::CORE:subst (opcode) |
| 3 | 1 | 1 | 25µs | 254µs | Method::Generate::Accessor::_generate_isa_check |
| 1 | 1 | 1 | 24µs | 2.34ms | Method::Generate::Accessor::BEGIN@11 |
| 1 | 1 | 1 | 20µs | 20µs | Method::Generate::Accessor::CORE:regcomp (opcode) |
| 9 | 2 | 1 | 20µs | 20µs | Method::Generate::Accessor::is_simple_get |
| 14 | 1 | 1 | 17µs | 17µs | Method::Generate::Accessor::CORE:substcont (opcode) |
| 3 | 1 | 1 | 16µs | 30µs | Method::Generate::Accessor::_attr_desc |
| 1 | 1 | 1 | 15µs | 48µs | Method::Generate::Accessor::BEGIN@3 |
| 4 | 1 | 1 | 15µs | 15µs | Method::Generate::Accessor::is_simple_set |
| 1 | 1 | 1 | 11µs | 32µs | Method::Generate::Accessor::BEGIN@10 |
| 1 | 1 | 1 | 11µs | 106µs | Method::Generate::Accessor::BEGIN@4 |
| 1 | 1 | 1 | 10µs | 53µs | Method::Generate::Accessor::BEGIN@7 |
| 1 | 1 | 1 | 9µs | 40µs | Method::Generate::Accessor::BEGIN@8 |
| 1 | 1 | 1 | 8µs | 8µs | Method::Generate::Accessor::BEGIN@5 |
| 2 | 1 | 1 | 3µs | 3µs | Method::Generate::Accessor::default_construction_string |
| 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::_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::_generate_get |
| 0 | 0 | 0 | 0s | 0s | Method::Generate::Accessor::_generate_getset |
| 0 | 0 | 0 | 0s | 0s | Method::Generate::Accessor::_generate_set |
| 0 | 0 | 0 | 0s | 0s | Method::Generate::Accessor::_generate_simple_clear |
| 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::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::has_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 | 35µs | 2 | 80µs | # spent 48µs (15+32) within Method::Generate::Accessor::BEGIN@3 which was called:
# once (15µs+32µs) by Moo::_accessor_maker_for at line 3 # spent 48µs making 1 call to Method::Generate::Accessor::BEGIN@3
# spent 32µs making 1 call to Moo::_strictures::import |
| 4 | 2 | 47µs | 2 | 202µs | # spent 106µs (11+96) within Method::Generate::Accessor::BEGIN@4 which was called:
# once (11µs+96µs) by Moo::_accessor_maker_for at line 4 # spent 106µs making 1 call to Method::Generate::Accessor::BEGIN@4
# spent 96µs making 1 call to Exporter::import |
| 5 | 2 | 59µs | 1 | 8µs | # spent 8µs within Method::Generate::Accessor::BEGIN@5 which was called:
# once (8µs+0s) by Moo::_accessor_maker_for at line 5 # spent 8µs making 1 call to Method::Generate::Accessor::BEGIN@5 |
| 6 | 1 | 10µs | our @ISA = qw(Moo::Object); | ||
| 7 | 2 | 36µs | 2 | 97µs | # spent 53µs (10+44) within Method::Generate::Accessor::BEGIN@7 which was called:
# once (10µs+44µs) by Moo::_accessor_maker_for at line 7 # spent 53µs making 1 call to Method::Generate::Accessor::BEGIN@7
# spent 44µs making 1 call to Exporter::import |
| 8 | 2 | 30µs | 2 | 72µs | # spent 40µs (9+31) within Method::Generate::Accessor::BEGIN@8 which was called:
# once (9µs+31µs) by Moo::_accessor_maker_for at line 8 # spent 40µs making 1 call to Method::Generate::Accessor::BEGIN@8
# spent 31µs making 1 call to Exporter::import |
| 9 | 2 | 682µs | 1 | 2.14ms | # spent 2.14ms (1.49+652µs) within Method::Generate::Accessor::BEGIN@9 which was called:
# once (1.49ms+652µs) by Moo::_accessor_maker_for at line 9 # spent 2.14ms making 1 call to Method::Generate::Accessor::BEGIN@9 |
| 10 | 2 | 102µs | 2 | 53µs | # spent 32µs (11+21) within Method::Generate::Accessor::BEGIN@10 which was called:
# once (11µs+21µs) by Moo::_accessor_maker_for at line 10 # spent 32µs making 1 call to Method::Generate::Accessor::BEGIN@10
# spent 21µs making 1 call to Module::Runtime::import |
| 11 | # spent 2.34ms (24µs+2.31) within Method::Generate::Accessor::BEGIN@11 which was called:
# once (24µs+2.31ms) 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 | 20µs | 2 | 2.31ms | (eval { Class::XSAccessor->VERSION('1.07') }) # spent 2.30ms making 1 call to Moo::_Utils::_maybe_load_module
# spent 7µs making 1 call to UNIVERSAL::VERSION |
| 18 | ; | ||||
| 19 | our $CAN_HAZ_XS_PRED = | ||||
| 20 | $CAN_HAZ_XS && | ||||
| 21 | 2 | 12µs | 1 | 4µs | (eval { Class::XSAccessor->VERSION('1.17') }) # spent 4µs making 1 call to UNIVERSAL::VERSION |
| 22 | ; | ||||
| 23 | 1 | 4.86ms | 1 | 2.34ms | } # spent 2.34ms making 1 call to Method::Generate::Accessor::BEGIN@11 |
| 24 | |||||
| 25 | 1 | 36µs | 2 | 22µs | my $module_name_only = qr/\A$Module::Runtime::module_name_rx\z/; # spent 20µ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 (302µs+1.13) within Method::Generate::Accessor::generate_method which was called 9 times, avg 159µs/call:
# 9 times (302µs+1.13ms) by Moo::has at line 57 of Moo.pm, avg 159µs/call | ||||
| 35 | 9 | 6µs | my ($self, $into, $name, $spec, $quote_opts) = @_; | ||
| 36 | 9 | 24µs | 9 | 3µs | $spec->{allow_overwrite}++ if $name =~ s/^\+//; # spent 3µs making 9 calls to Method::Generate::Accessor::CORE:subst, avg 311ns/call |
| 37 | 9 | 6µs | die "Must have an is" unless my $is = $spec->{is}; | ||
| 38 | 9 | 13µ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 | 9 | 4µ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 | 9 | 4µs | if (($spec->{predicate}||0) eq 1) { | ||
| 65 | $spec->{predicate} = $name =~ /^_/ ? "_has${name}" : "has_${name}"; | ||||
| 66 | } | ||||
| 67 | 9 | 3µs | if (($spec->{clearer}||0) eq 1) { | ||
| 68 | $spec->{clearer} = $name =~ /^_/ ? "_clear${name}" : "clear_${name}"; | ||||
| 69 | } | ||||
| 70 | 9 | 3µs | if (($spec->{trigger}||0) eq 1) { | ||
| 71 | $spec->{trigger} = quote_sub('shift->_trigger_'.$name.'(@_)'); | ||||
| 72 | } | ||||
| 73 | 9 | 3µ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 | 9 | 16µs | foreach my $setting (qw( isa coerce )) { | ||
| 85 | 18 | 9µs | next if !exists $spec->{$setting}; | ||
| 86 | 3 | 7µs | 3 | 29µs | $self->_validate_codulatable($setting, $spec->{$setting}, "$into->$name"); # spent 29µs making 3 calls to Method::Generate::Accessor::_validate_codulatable, avg 10µs/call |
| 87 | } | ||||
| 88 | |||||
| 89 | 9 | 23µs | 9 | 90µs | if (exists $spec->{default}) { # spent 90µs making 9 calls to Method::Generate::Accessor::_validate_codulatable, avg 10µ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 | 9 | 4µ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 | 9 | 2µs | my %methods; | ||
| 107 | 9 | 6µs | if (my $reader = $spec->{reader}) { | ||
| 108 | _die_overwrite($into, $reader, 'a reader') | ||||
| 109 | 5 | 17µs | if !$spec->{allow_overwrite} && defined &{"${into}::${reader}"}; | ||
| 110 | 5 | 19µs | 10 | 544µs | if (our $CAN_HAZ_XS && $self->is_simple_get($name, $spec)) { # spent 533µs making 5 calls to Method::Generate::Accessor::_generate_xs, avg 107µs/call
# spent 11µs making 5 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 | $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 | ; | ||||
| 122 | } | ||||
| 123 | } | ||||
| 124 | 9 | 7µs | if (my $accessor = $spec->{accessor}) { | ||
| 125 | _die_overwrite($into, $accessor, 'an accessor') | ||||
| 126 | 4 | 14µs | if !$spec->{allow_overwrite} && defined &{"${into}::${accessor}"}; | ||
| 127 | 4 | 22µs | 12 | 463µs | if ( # spent 439µs making 4 calls to Method::Generate::Accessor::_generate_xs, avg 110µs/call
# spent 15µs making 4 calls to Method::Generate::Accessor::is_simple_set, avg 4µs/call
# spent 9µs making 4 calls to Method::Generate::Accessor::is_simple_get, avg 2µs/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 | 9 | 4µs | if (my $writer = $spec->{writer}) { | ||
| 145 | _die_overwrite($into, $writer, 'a writer') | ||||
| 146 | if !$spec->{allow_overwrite} && defined &{"${into}::${writer}"}; | ||||
| 147 | if ( | ||||
| 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 | 9 | 3µs | if (my $pred = $spec->{predicate}) { | ||
| 164 | _die_overwrite($into, $pred, 'a predicate') | ||||
| 165 | if !$spec->{allow_overwrite} && defined &{"${into}::${pred}"}; | ||||
| 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 | 9 | 3µs | if (my $pred = $spec->{builder_sub}) { | ||
| 178 | _install_coderef( "${into}::$spec->{builder}" => $spec->{builder_sub} ); | ||||
| 179 | } | ||||
| 180 | 9 | 3µs | if (my $cl = $spec->{clearer}) { | ||
| 181 | _die_overwrite($into, $cl, 'a clearer') | ||||
| 182 | if !$spec->{allow_overwrite} && defined &{"${into}::${cl}"}; | ||||
| 183 | $methods{$cl} = | ||||
| 184 | quote_sub "${into}::${cl}" => | ||||
| 185 | $self->_generate_simple_clear('$_[0]', $name, $spec)."\n" | ||||
| 186 | ; | ||||
| 187 | } | ||||
| 188 | 9 | 3µ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} && defined &{"${into}::${proxy}"}; | ||||
| 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 | 9 | 3µ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 | 9 | 25µ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 | sub is_simple_get { | ||||
| 235 | 9 | 5µs | my ($self, $name, $spec) = @_; | ||
| 236 | 9 | 36µs | !($spec->{lazy} and (exists $spec->{default} or $spec->{builder})); | ||
| 237 | } | ||||
| 238 | |||||
| 239 | # spent 15µs within Method::Generate::Accessor::is_simple_set which was called 4 times, avg 4µs/call:
# 4 times (15µs+0s) by Method::Generate::Accessor::generate_method at line 127, avg 4µs/call | ||||
| 240 | 4 | 2µs | my ($self, $name, $spec) = @_; | ||
| 241 | 4 | 19µs | !grep $spec->{$_}, qw(coerce isa trigger weak_ref); | ||
| 242 | } | ||||
| 243 | |||||
| 244 | sub has_default { | ||||
| 245 | my ($self, $name, $spec) = @_; | ||||
| 246 | $spec->{builder} or exists $spec->{default} or (($spec->{is}||'') eq 'lazy'); | ||||
| 247 | } | ||||
| 248 | |||||
| 249 | # spent 38µs within Method::Generate::Accessor::has_eager_default which was called 15 times, avg 3µs/call:
# 15 times (38µs+0s) by Method::Generate::Accessor::_generate_populate_set at line 494, avg 3µs/call | ||||
| 250 | 15 | 6µs | my ($self, $name, $spec) = @_; | ||
| 251 | 15 | 62µs | (!$spec->{lazy} and (exists $spec->{default} or $spec->{builder})); | ||
| 252 | } | ||||
| 253 | |||||
| 254 | sub _generate_get { | ||||
| 255 | my ($self, $name, $spec) = @_; | ||||
| 256 | my $simple = $self->_generate_simple_get('$_[0]', $name, $spec); | ||||
| 257 | if ($self->is_simple_get($name, $spec)) { | ||||
| 258 | $simple; | ||||
| 259 | } else { | ||||
| 260 | $self->_generate_use_default( | ||||
| 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 | sub _generate_simple_has { | ||||
| 275 | my ($self, $me, $name) = @_; | ||||
| 276 | "exists ${me}->{${\quotify $name}}"; | ||||
| 277 | } | ||||
| 278 | |||||
| 279 | sub _generate_simple_clear { | ||||
| 280 | my ($self, $me, $name) = @_; | ||||
| 281 | " delete ${me}->{${\quotify $name}}\n" | ||||
| 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 | sub _generate_use_default { | ||||
| 299 | my ($self, $me, $name, $spec, $test) = @_; | ||||
| 300 | my $get_value = $self->_generate_get_default($me, $name, $spec); | ||||
| 301 | 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 | ." ".$self->_generate_isa_check($name, '$value', $spec->{isa}).";\n" | ||||
| 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 7.76ms (48µs+7.71) within Method::Generate::Accessor::_generate_get_default which was called 9 times, avg 862µs/call:
# 9 times (48µs+7.71ms) by Method::Generate::Accessor::_generate_populate_set at line 499, avg 862µs/call | ||||
| 319 | 9 | 5µs | my ($self, $me, $name, $spec) = @_; | ||
| 320 | 9 | 40µs | 9 | 7.71ms | if (exists $spec->{default}) { # spent 7.71ms making 9 calls to Method::Generate::Accessor::_generate_call_code, avg 857µs/call |
| 321 | ref $spec->{default} | ||||
| 322 | ? $self->_generate_call_code($name, 'default', $me, $spec->{default}) | ||||
| 323 | : quotify $spec->{default}; | ||||
| 324 | } | ||||
| 325 | else { | ||||
| 326 | "${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 | sub _generate_simple_get { | ||||
| 338 | my ($self, $me, $name) = @_; | ||||
| 339 | my $name_str = quotify $name; | ||||
| 340 | "${me}->{${name_str}}"; | ||||
| 341 | } | ||||
| 342 | |||||
| 343 | sub _generate_set { | ||||
| 344 | my ($self, $name, $spec) = @_; | ||||
| 345 | my ($me, $source) = ('$_[0]', '$_[1]'); | ||||
| 346 | if ($self->is_simple_set($name, $spec)) { | ||||
| 347 | return $self->_generate_simple_set($me, $name, $spec, $source); | ||||
| 348 | } | ||||
| 349 | |||||
| 350 | my ($coerce, $trigger, $isa_check) = @{$spec}{qw(coerce trigger isa)}; | ||||
| 351 | if ($coerce) { | ||||
| 352 | $source = $self->_generate_coerce($name, $source, $coerce); | ||||
| 353 | } | ||||
| 354 | if ($isa_check) { | ||||
| 355 | $source = 'scalar do { my $value = '.$source.";\n" | ||||
| 356 | .' ('.$self->_generate_isa_check($name, '$value', $isa_check)."),\n" | ||||
| 357 | .($trigger | ||||
| 358 | ? '('.$self->_generate_trigger($name, $me, '$value', $trigger).'),' | ||||
| 359 | : '') | ||||
| 360 | ." \$value\n" | ||||
| 361 | ."}"; | ||||
| 362 | } | ||||
| 363 | my $set = $self->_generate_simple_set($me, $name, $spec, $source); | ||||
| 364 | if (!$isa_check && $trigger) { | ||||
| 365 | "scalar (\n" | ||||
| 366 | . ' ('.$self->_generate_trigger($name, $me, "($set)", $trigger)."),\n" | ||||
| 367 | . ' ('.$self->_generate_simple_get($me, $name, $spec)."),\n" | ||||
| 368 | . ")"; | ||||
| 369 | } | ||||
| 370 | else { | ||||
| 371 | "($set)"; | ||||
| 372 | } | ||||
| 373 | } | ||||
| 374 | |||||
| 375 | sub generate_coerce { | ||||
| 376 | my $self = shift; | ||||
| 377 | $self->{captures} = {}; | ||||
| 378 | my $code = $self->_generate_coerce(@_); | ||||
| 379 | ($code, delete $self->{captures}); | ||||
| 380 | } | ||||
| 381 | |||||
| 382 | # spent 30µs (16+15) within Method::Generate::Accessor::_attr_desc which was called 3 times, avg 10µs/call:
# 3 times (16µs+15µs) by Method::Generate::Accessor::_wrap_attr_exception at line 420, avg 10µs/call | ||||
| 383 | 3 | 1µs | my ($name, $init_arg) = @_; | ||
| 384 | 3 | 14µs | 3 | 15µs | return quotify($name) if !defined($init_arg) or $init_arg eq $name; # spent 15µs making 3 calls to Sub::Quote::quotify, avg 5µs/call |
| 385 | return quotify($name).' (constructor argument: '.quotify($init_arg).')'; | ||||
| 386 | } | ||||
| 387 | |||||
| 388 | sub _generate_coerce { | ||||
| 389 | my ($self, $name, $value, $coerce, $init_arg) = @_; | ||||
| 390 | $self->_wrap_attr_exception( | ||||
| 391 | $name, | ||||
| 392 | "coercion", | ||||
| 393 | $init_arg, | ||||
| 394 | $self->_generate_call_code($name, 'coerce', "${value}", $coerce), | ||||
| 395 | 1, | ||||
| 396 | ); | ||||
| 397 | } | ||||
| 398 | |||||
| 399 | sub generate_trigger { | ||||
| 400 | my $self = shift; | ||||
| 401 | $self->{captures} = {}; | ||||
| 402 | my $code = $self->_generate_trigger(@_); | ||||
| 403 | ($code, delete $self->{captures}); | ||||
| 404 | } | ||||
| 405 | |||||
| 406 | sub _generate_trigger { | ||||
| 407 | my ($self, $name, $obj, $value, $trigger) = @_; | ||||
| 408 | $self->_generate_call_code($name, 'trigger', "${obj}, ${value}", $trigger); | ||||
| 409 | } | ||||
| 410 | |||||
| 411 | sub generate_isa_check { | ||||
| 412 | my ($self, @args) = @_; | ||||
| 413 | $self->{captures} = {}; | ||||
| 414 | my $code = $self->_generate_isa_check(@args); | ||||
| 415 | ($code, delete $self->{captures}); | ||||
| 416 | } | ||||
| 417 | |||||
| 418 | # spent 138µs (61+77) within Method::Generate::Accessor::_wrap_attr_exception which was called 3 times, avg 46µs/call:
# 3 times (61µs+77µs) by Method::Generate::Accessor::_generate_isa_check at line 445, avg 46µs/call | ||||
| 419 | 3 | 3µs | my ($self, $name, $step, $arg, $code, $want_return) = @_; | ||
| 420 | 3 | 12µs | 6 | 45µs | my $prefix = quotify("${step} for "._attr_desc($name, $arg).' failed: '); # spent 30µs making 3 calls to Method::Generate::Accessor::_attr_desc, avg 10µs/call
# spent 14µs making 3 calls to Sub::Quote::quotify, avg 5µs/call |
| 421 | 3 | 29µs | 9 | 32µs | "do {\n" # spent 32µs making 9 calls to Sub::Quote::quotify, avg 4µs/call |
| 422 | .' local $Method::Generate::Accessor::CurrentAttribute = {'."\n" | ||||
| 423 | .' init_arg => '.quotify($arg).",\n" | ||||
| 424 | .' name => '.quotify($name).",\n" | ||||
| 425 | .' step => '.quotify($step).",\n" | ||||
| 426 | ." };\n" | ||||
| 427 | .($want_return ? ' (my $_return),'."\n" : '') | ||||
| 428 | .' (my $_error), (my $_old_error = $@);'."\n" | ||||
| 429 | ." (eval {\n" | ||||
| 430 | .' ($@ = $_old_error),'."\n" | ||||
| 431 | .' (' | ||||
| 432 | .($want_return ? '$_return ='."\n" : '') | ||||
| 433 | .$code."),\n" | ||||
| 434 | ." 1\n" | ||||
| 435 | ." } or\n" | ||||
| 436 | .' $_error = ref $@ ? $@ : '.$prefix.'.$@);'."\n" | ||||
| 437 | .' ($@ = $_old_error),'."\n" | ||||
| 438 | .' (defined $_error and die $_error);'."\n" | ||||
| 439 | .($want_return ? ' $_return;'."\n" : '') | ||||
| 440 | ."}\n" | ||||
| 441 | } | ||||
| 442 | |||||
| 443 | # spent 254µs (25+229) within Method::Generate::Accessor::_generate_isa_check which was called 3 times, avg 85µs/call:
# 3 times (25µs+229µs) by Method::Generate::Accessor::_generate_populate_set at line 514, avg 85µs/call | ||||
| 444 | 3 | 2µs | my ($self, $name, $value, $check, $init_arg) = @_; | ||
| 445 | 3 | 21µs | 6 | 229µs | $self->_wrap_attr_exception( # spent 138µs making 3 calls to Method::Generate::Accessor::_wrap_attr_exception, avg 46µs/call
# spent 91µs making 3 calls to Method::Generate::Accessor::_generate_call_code, avg 30µs/call |
| 446 | $name, | ||||
| 447 | "isa check", | ||||
| 448 | $init_arg, | ||||
| 449 | $self->_generate_call_code($name, 'isa_check', $value, $check) | ||||
| 450 | ); | ||||
| 451 | } | ||||
| 452 | |||||
| 453 | # spent 7.80ms (7.58+226µs) within Method::Generate::Accessor::_generate_call_code which was called 12 times, avg 650µs/call:
# 9 times (7.54ms+170µs) by Method::Generate::Accessor::_generate_get_default at line 320, avg 857µs/call
# 3 times (36µs+56µs) by Method::Generate::Accessor::_generate_isa_check at line 445, avg 30µs/call | ||||
| 454 | 12 | 7µs | my ($self, $name, $type, $values, $sub) = @_; | ||
| 455 | 12 | 39µs | 12 | 9µs | $sub = \&{$sub} if blessed($sub); # coderef if blessed # spent 9µs making 12 calls to Scalar::Util::blessed, avg 783ns/call |
| 456 | 12 | 53µs | 12 | 30µs | if (my $quoted = quoted_from_sub($sub)) { # spent 30µs making 12 calls to Sub::Quote::quoted_from_sub, avg 3µs/call |
| 457 | my $local = 1; | ||||
| 458 | if ($values eq '@_' || $values eq '$_[0]') { | ||||
| 459 | $local = 0; | ||||
| 460 | $values = '@_'; | ||||
| 461 | } | ||||
| 462 | my $code = $quoted->[1]; | ||||
| 463 | if (my $captures = $quoted->[2]) { | ||||
| 464 | my $cap_name = qq{\$${type}_captures_for_}.$self->_sanitize_name($name); | ||||
| 465 | $self->{captures}->{$cap_name} = \$captures; | ||||
| 466 | Sub::Quote::inlinify($code, $values, | ||||
| 467 | Sub::Quote::capture_unroll($cap_name, $captures, 6), $local); | ||||
| 468 | } else { | ||||
| 469 | Sub::Quote::inlinify($code, $values, undef, $local); | ||||
| 470 | } | ||||
| 471 | } else { | ||||
| 472 | 12 | 32µs | 12 | 186µs | my $cap_name = qq{\$${type}_for_}.$self->_sanitize_name($name); # spent 186µs making 12 calls to Method::Generate::Accessor::_sanitize_name, avg 16µs/call |
| 473 | 12 | 19µs | $self->{captures}->{$cap_name} = \$sub; | ||
| 474 | 12 | 11µs | "${cap_name}->(${values})"; | ||
| 475 | } | ||||
| 476 | } | ||||
| 477 | |||||
| 478 | # spent 186µs (135+51) within Method::Generate::Accessor::_sanitize_name which was called 12 times, avg 16µs/call:
# 12 times (135µs+51µs) by Method::Generate::Accessor::_generate_call_code at line 472, avg 16µs/call | ||||
| 479 | 12 | 15µs | my ($self, $name) = @_; | ||
| 480 | 12 | 148µs | 26 | 51µs | $name =~ s/([_\W])/sprintf('_%x', ord($1))/ge; # spent 34µs making 12 calls to Method::Generate::Accessor::CORE:subst, avg 3µs/call
# spent 17µs making 14 calls to Method::Generate::Accessor::CORE:substcont, avg 1µs/call |
| 481 | 12 | 34µs | $name; | ||
| 482 | } | ||||
| 483 | |||||
| 484 | # spent 8.82ms (108µs+8.71) within Method::Generate::Accessor::generate_populate_set which was called 15 times, avg 588µs/call:
# 15 times (108µs+8.71ms) by Method::Generate::Constructor::_assign_new at line 217 of Method/Generate/Constructor.pm, avg 588µs/call | ||||
| 485 | 15 | 5µs | my $self = shift; | ||
| 486 | 15 | 21µs | $self->{captures} = {}; | ||
| 487 | 15 | 25µs | 15 | 8.71ms | my $code = $self->_generate_populate_set(@_); # spent 8.71ms making 15 calls to Method::Generate::Accessor::_generate_populate_set, avg 581µs/call |
| 488 | 15 | 53µs | ($code, delete $self->{captures}); | ||
| 489 | } | ||||
| 490 | |||||
| 491 | # spent 8.71ms (279µs+8.43) within Method::Generate::Accessor::_generate_populate_set which was called 15 times, avg 581µs/call:
# 15 times (279µs+8.43ms) by Method::Generate::Accessor::generate_populate_set at line 487, avg 581µs/call | ||||
| 492 | 15 | 38µs | my ($self, $me, $name, $spec, $source, $test, $init_arg) = @_; | ||
| 493 | |||||
| 494 | 15 | 23µs | 15 | 38µs | my $has_default = $self->has_eager_default($name, $spec); # spent 38µs making 15 calls to Method::Generate::Accessor::has_eager_default, avg 3µs/call |
| 495 | 15 | 4µs | if (!($has_default || $test)) { | ||
| 496 | return ''; | ||||
| 497 | } | ||||
| 498 | 15 | 5µs | if ($has_default) { | ||
| 499 | 9 | 16µs | 9 | 7.76ms | my $get_default = $self->_generate_get_default($me, $name, $spec); # spent 7.76ms making 9 calls to Method::Generate::Accessor::_generate_get_default, avg 862µs/call |
| 500 | 9 | 16µs | $source = | ||
| 501 | $test | ||||
| 502 | ? "(\n ${test}\n" | ||||
| 503 | ." ? ${source}\n : " | ||||
| 504 | .$get_default | ||||
| 505 | .")" | ||||
| 506 | : $get_default; | ||||
| 507 | } | ||||
| 508 | 15 | 7µs | if ($spec->{coerce}) { | ||
| 509 | $source = $self->_generate_coerce( | ||||
| 510 | $name, $source, | ||||
| 511 | $spec->{coerce}, $init_arg | ||||
| 512 | ) | ||||
| 513 | } | ||||
| 514 | 15 | 22µs | 3 | 254µs | if ($spec->{isa}) { # spent 254µs making 3 calls to Method::Generate::Accessor::_generate_isa_check, avg 85µs/call |
| 515 | $source = 'scalar do { my $value = '.$source.";\n" | ||||
| 516 | .' ('.$self->_generate_isa_check( | ||||
| 517 | $name, '$value', $spec->{isa}, $init_arg | ||||
| 518 | )."),\n" | ||||
| 519 | ." \$value\n" | ||||
| 520 | ."}\n"; | ||||
| 521 | } | ||||
| 522 | 15 | 28µs | 15 | 380µs | my $set = $self->_generate_simple_set($me, $name, $spec, $source); # spent 380µs making 15 calls to Method::Generate::Accessor::_generate_simple_set, avg 25µs/call |
| 523 | 15 | 9µs | my $trigger = $spec->{trigger} ? $self->_generate_trigger( | ||
| 524 | $name, $me, $self->_generate_simple_get($me, $name, $spec), | ||||
| 525 | $spec->{trigger} | ||||
| 526 | ) : undef; | ||||
| 527 | 15 | 58µs | if ($has_default) { | ||
| 528 | "($set)," . ($trigger ? "($test and $trigger)," : '') | ||||
| 529 | } | ||||
| 530 | else { | ||||
| 531 | 6 | 9µs | "($test and ($set)" . ($trigger ? ", ($trigger)" : '') . "),"; | ||
| 532 | } | ||||
| 533 | } | ||||
| 534 | |||||
| 535 | # spent 166µs (94+71) within Method::Generate::Accessor::_generate_core_set which was called 15 times, avg 11µs/call:
# 15 times (94µs+71µs) by Method::Generate::Accessor::_generate_simple_set at line 544, avg 11µs/call | ||||
| 536 | 15 | 11µs | my ($self, $me, $name, $spec, $value) = @_; | ||
| 537 | 15 | 18µs | 15 | 71µs | my $name_str = quotify $name; # spent 71µs making 15 calls to Sub::Quote::quotify, avg 5µs/call |
| 538 | 15 | 71µs | "${me}->{${name_str}} = ${value}"; | ||
| 539 | } | ||||
| 540 | |||||
| 541 | # spent 380µs (136+244) within Method::Generate::Accessor::_generate_simple_set which was called 15 times, avg 25µs/call:
# 15 times (136µs+244µs) by Method::Generate::Accessor::_generate_populate_set at line 522, avg 25µs/call | ||||
| 542 | 15 | 11µs | my ($self, $me, $name, $spec, $value) = @_; | ||
| 543 | 15 | 28µs | 15 | 78µs | my $name_str = quotify $name; # spent 78µs making 15 calls to Sub::Quote::quotify, avg 5µs/call |
| 544 | 15 | 25µs | 15 | 166µs | my $simple = $self->_generate_core_set($me, $name, $spec, $value); # spent 166µs making 15 calls to Method::Generate::Accessor::_generate_core_set, avg 11µs/call |
| 545 | |||||
| 546 | 15 | 49µs | if ($spec->{weak_ref}) { | ||
| 547 | require Scalar::Util; | ||||
| 548 | my $get = $self->_generate_simple_get($me, $name, $spec); | ||||
| 549 | |||||
| 550 | # Perl < 5.8.3 can't weaken refs to readonly vars | ||||
| 551 | # (e.g. string constants). This *can* be solved by: | ||||
| 552 | # | ||||
| 553 | # &Internals::SvREADONLY($foo, 0); | ||||
| 554 | # Scalar::Util::weaken($foo); | ||||
| 555 | # &Internals::SvREADONLY($foo, 1); | ||||
| 556 | # | ||||
| 557 | # but requires Internal functions and is just too damn crazy | ||||
| 558 | # so simply throw a better exception | ||||
| 559 | my $weak_simple = "do { Scalar::Util::weaken(${simple}); no warnings 'void'; $get }"; | ||||
| 560 | Moo::_Utils::lt_5_8_3() ? <<"EOC" : $weak_simple; | ||||
| 561 | eval { Scalar::Util::weaken($simple); 1 } | ||||
| 562 | ? do { no warnings 'void'; $get } | ||||
| 563 | : do { | ||||
| 564 | if( \$@ =~ /Modification of a read-only value attempted/) { | ||||
| 565 | require Carp; | ||||
| 566 | Carp::croak( sprintf ( | ||||
| 567 | 'Reference to readonly value in "%s" can not be weakened on Perl < 5.8.3', | ||||
| 568 | $name_str, | ||||
| 569 | ) ); | ||||
| 570 | } else { | ||||
| 571 | die \$@; | ||||
| 572 | } | ||||
| 573 | } | ||||
| 574 | EOC | ||||
| 575 | } else { | ||||
| 576 | 15 | 8µs | $simple; | ||
| 577 | } | ||||
| 578 | } | ||||
| 579 | |||||
| 580 | sub _generate_getset { | ||||
| 581 | my ($self, $name, $spec) = @_; | ||||
| 582 | q{(@_ > 1}."\n ? ".$self->_generate_set($name, $spec) | ||||
| 583 | ."\n : ".$self->_generate_get($name, $spec)."\n )"; | ||||
| 584 | } | ||||
| 585 | |||||
| 586 | sub _generate_asserter { | ||||
| 587 | my ($self, $name, $spec) = @_; | ||||
| 588 | |||||
| 589 | "do {\n" | ||||
| 590 | ." my \$val = ".$self->_generate_get($name, $spec).";\n" | ||||
| 591 | ." unless (".$self->_generate_simple_has('$_[0]', $name, $spec).") {\n" | ||||
| 592 | .qq! die "Attempted to access '${name}' but it is not set";\n! | ||||
| 593 | ." }\n" | ||||
| 594 | ." \$val;\n" | ||||
| 595 | ."}\n"; | ||||
| 596 | } | ||||
| 597 | sub _generate_delegation { | ||||
| 598 | my ($self, $asserter, $target, $args) = @_; | ||||
| 599 | my $arg_string = do { | ||||
| 600 | if (@$args) { | ||||
| 601 | # I could, I reckon, linearise out non-refs here using quotify | ||||
| 602 | # plus something to check for numbers but I'm unsure if it's worth it | ||||
| 603 | $self->{captures}{'@curries'} = $args; | ||||
| 604 | '@curries, @_'; | ||||
| 605 | } else { | ||||
| 606 | '@_'; | ||||
| 607 | } | ||||
| 608 | }; | ||||
| 609 | "shift->${asserter}->${target}(${arg_string});"; | ||||
| 610 | } | ||||
| 611 | |||||
| 612 | # spent 972µs (91+880) within Method::Generate::Accessor::_generate_xs which was called 9 times, avg 108µs/call:
# 5 times (52µs+481µs) by Method::Generate::Accessor::generate_method at line 110, avg 107µs/call
# 4 times (39µs+399µs) by Method::Generate::Accessor::generate_method at line 127, avg 110µs/call | ||||
| 613 | 9 | 6µs | my ($self, $type, $into, $name, $slot) = @_; | ||
| 614 | 9 | 30µs | 9 | 860µs | Class::XSAccessor->import( # spent 860µs making 9 calls to Class::XSAccessor::import, avg 96µs/call |
| 615 | class => $into, | ||||
| 616 | $type => { $name => $slot }, | ||||
| 617 | replace => 1, | ||||
| 618 | ); | ||||
| 619 | 9 | 67µs | 9 | 21µs | $into->can($name); # spent 21µs making 9 calls to UNIVERSAL::can, avg 2µs/call |
| 620 | } | ||||
| 621 | |||||
| 622 | 2 | 7µs | # spent 3µs within Method::Generate::Accessor::default_construction_string which was called 2 times, avg 2µs/call:
# 2 times (3µs+0s) by Method::Generate::Constructor::_build_construction_string at line 70 of Method/Generate/Constructor.pm, avg 2µs/call | ||
| 623 | |||||
| 624 | # spent 119µs (99+20) within Method::Generate::Accessor::_validate_codulatable which was called 12 times, avg 10µs/call:
# 9 times (76µs+15µs) by Method::Generate::Accessor::generate_method at line 89, avg 10µs/call
# 3 times (23µs+6µs) by Method::Generate::Accessor::generate_method at line 86, avg 10µs/call | ||||
| 625 | 12 | 7µs | my ($self, $setting, $value, $into, $appended) = @_; | ||
| 626 | 12 | 31µs | 12 | 20µs | my $invalid = "Invalid $setting '" . overload::StrVal($value) # spent 20µs making 12 calls to overload::AddrRef, avg 2µs/call |
| 627 | . "' for $into not a coderef"; | ||||
| 628 | 12 | 5µs | $invalid .= " $appended" if $appended; | ||
| 629 | |||||
| 630 | 12 | 7µs | unless (ref $value and (ref $value eq 'CODE' or blessed($value))) { | ||
| 631 | die "$invalid or code-convertible object"; | ||||
| 632 | } | ||||
| 633 | |||||
| 634 | 24 | 16µs | unless (eval { \&$value }) { | ||
| 635 | die "$invalid and could not be converted to a coderef: $@"; | ||||
| 636 | } | ||||
| 637 | |||||
| 638 | 12 | 31µs | 1; | ||
| 639 | } | ||||
| 640 | |||||
| 641 | 1 | 6µs | 1; | ||
# spent 2µs within Method::Generate::Accessor::CORE:qr which was called:
# once (2µs+0s) by Moo::_accessor_maker_for at line 25 | |||||
# spent 20µs within Method::Generate::Accessor::CORE:regcomp which was called:
# once (20µs+0s) by Moo::_accessor_maker_for at line 25 | |||||
sub Method::Generate::Accessor::CORE:subst; # opcode | |||||
# spent 17µs within Method::Generate::Accessor::CORE:substcont which was called 14 times, avg 1µs/call:
# 14 times (17µs+0s) by Method::Generate::Accessor::_sanitize_name at line 480, avg 1µs/call |