3 package Class::MOP::Instance::Inlinable;
8 # cheap ass pseudo-mixin
10 # inlinable operation snippets
12 sub inline_get_slot_value {
13 my ($self, $instance, $slot_name) = @_;
14 sprintf "%s->{%s}", $instance, $slot_name;
17 sub inline_set_slot_value {
18 my ($self, $instance, $slot_name, $value) = @_;
19 $self->_inline_slot_lvalue( $instance, $slot_name ) . " = $value",
22 sub inline_set_slot_value_with_init {
23 my ($self, $instance, $slot_name, $value) = @_;
25 $self->_join_statements(
26 $self->inline_initialize_slot( $instance, $slot_name ),
27 $self->inline_set_slot_value( $instance, $slot_name, $value ),
31 sub inline_set_slot_value_weak {
32 my ($self, $instance, $slot_name, $value) = @_;
34 $self->_join_statements(
35 $self->inline_set_slot_value( $instance, $slot_name, $value ),
36 $self->inline_weaken_slot_value( $instance, $slot_name ),
40 sub inline_weaken_slot_value {
41 my ($self, $instance, $slot_name) = @_;
42 sprintf "Scalar::Util::weaken( %s )", $self->_inline_slot_lvalue( $instance, $slot_name );
45 sub inline_initialize_slot {
49 sub inline_slot_initialized {
50 my ($self, $instance, $slot_name) = @_;
51 "exists " . $self->inline_get_slot_value;
54 sub _join_statements {
55 my ( $self, @statements ) = @_;
56 my @filtered = grep { length } @statements;
57 return $filtered[0] if @filtered == 1;
58 return join("; ", @filtered);
61 sub _inline_slot_lvalue {
62 my ($self, $instance, $slot_name) = @_;
63 $self->inline_get_slot_value( $instance, $slot_name );
74 Class::MOP::Instance::Inlinable - Generate inline slot operations.
78 # see Moose::Meta::Attribute for an example
82 This pseudo-mixin class provides additional methods to work along side
83 L<Class::MOP::Instance>, which can be used to generate accessors with inlined