}
+sub inline_get {
+ my $self = shift;
+ my ($instance) = @_;
+
+ return $self->associated_class->get_meta_instance->inline_get_slot_value(
+ $instance, $self->name );
+}
+
+sub inline_set {
+ my $self = shift;
+ my ( $instance, $value ) = @_;
+
+ return $self->associated_class->get_meta_instance->inline_set_slot_value(
+ $instance, $self->name, $value );
+}
+
+sub inline_has {
+ my $self = shift;
+ my ($instance) = @_;
+
+ return
+ $self->associated_class->get_meta_instance
+ ->inline_is_slot_initialized( $instance, $self->name );
+}
+
+sub inline_clear {
+ my $self = shift;
+ my ($instance) = @_;
+
+ return
+ $self->associated_class->get_meta_instance
+ ->inline_deinitialize_slot( $instance, $self->name );
+}
+
1;
__END__
This does not currently remove methods from the list returned by
C<associated_methods>.
+=item B<< $attr->inline_get >>
+
+=item B<< $attr->inline_set >>
+
+=item B<< $attr->inline_has >>
+
+=item B<< $attr->inline_clear >>
+
+These methods return a code snippet suitable for inlining the relevant
+operation. They expect strings containing variable names to be used in the
+inlining, like C<'$self'> or C<'$_[1]'>.
+
=back
=head2 Introspection
## Inline methods
sub _generate_accessor_method_inline {
- my $self = shift;
- my $attr = $self->associated_attribute;
- my $attr_name = $attr->name;
- my $meta_instance = $attr->associated_class->instance_metaclass;
+ my $self = shift;
+ my $attr = $self->associated_attribute;
my ( $code, $e ) = $self->_eval_closure(
{},
'sub {'
- . $meta_instance->inline_set_slot_value('$_[0]', $attr_name, '$_[1]')
- . ' if scalar(@_) == 2; '
- . $meta_instance->inline_get_slot_value('$_[0]', $attr_name)
- . '}'
+ . $attr->inline_set( '$_[0]', '$_[1]' )
+ . ' if scalar(@_) == 2; '
+ . $attr->inline_get('$_[0]') . '}'
);
confess "Could not generate inline accessor because : $e" if $e;
}
sub _generate_reader_method_inline {
- my $self = shift;
- my $attr = $self->associated_attribute;
- my $attr_name = $attr->name;
- my $meta_instance = $attr->associated_class->instance_metaclass;
+ my $self = shift;
+ my $attr = $self->associated_attribute;
- my ( $code, $e ) = $self->_eval_closure(
- {},
+ my ( $code, $e ) = $self->_eval_closure(
+ {},
'sub {'
- . 'confess "Cannot assign a value to a read-only accessor" if @_ > 1;'
- . $meta_instance->inline_get_slot_value('$_[0]', $attr_name)
- . '}'
+ . 'confess "Cannot assign a value to a read-only accessor" if @_ > 1;'
+ . $attr->inline_get('$_[0]') . '}'
);
confess "Could not generate inline reader because : $e" if $e;
}
sub _generate_writer_method_inline {
- my $self = shift;
- my $attr = $self->associated_attribute;
- my $attr_name = $attr->name;
- my $meta_instance = $attr->associated_class->instance_metaclass;
+ my $self = shift;
+ my $attr = $self->associated_attribute;
my ( $code, $e ) = $self->_eval_closure(
{},
- 'sub {'
- . $meta_instance->inline_set_slot_value('$_[0]', $attr_name, '$_[1]')
- . '}'
+ 'sub {' . $attr->inline_set( '$_[0]', '$_[1]' ) . '}'
);
confess "Could not generate inline writer because : $e" if $e;
}
sub _generate_predicate_method_inline {
- my $self = shift;
- my $attr = $self->associated_attribute;
- my $attr_name = $attr->name;
- my $meta_instance = $attr->associated_class->instance_metaclass;
+ my $self = shift;
+ my $attr = $self->associated_attribute;
my ( $code, $e ) = $self->_eval_closure(
{},
- 'sub {'
- . $meta_instance->inline_is_slot_initialized('$_[0]', $attr_name)
- . '}'
+ 'sub {' . $attr->inline_has('$_[0]') . '}'
);
confess "Could not generate inline predicate because : $e" if $e;
}
sub _generate_clearer_method_inline {
- my $self = shift;
- my $attr = $self->associated_attribute;
- my $attr_name = $attr->name;
- my $meta_instance = $attr->associated_class->instance_metaclass;
+ my $self = shift;
+ my $attr = $self->associated_attribute;
my ( $code, $e ) = $self->_eval_closure(
{},
- 'sub {'
- . $meta_instance->inline_deinitialize_slot('$_[0]', $attr_name)
- . '}'
+ 'sub {' . $attr->inline_clear('$_[0]') . '}'
);
confess "Could not generate inline clearer because : $e" if $e;