InsideOutClass - A set of example metaclasses which implement the Inside-Out technique


Moose documentation  | view source Contained in the Moose distribution.

Index


NAME

Top

InsideOutClass - A set of example metaclasses which implement the Inside-Out technique

SYNOPSIS

Top

  package Foo;

  use metaclass (
    ':attribute_metaclass' => 'InsideOutClass::Attribute',
    ':instance_metaclass'  => 'InsideOutClass::Instance'
  );

  __PACKAGE__->meta->add_attribute('foo' => (
      reader => 'get_foo',
      writer => 'set_foo'
  ));    

  sub new  {
      my $class = shift;
      $class->meta->new_object(@_);
  } 

  # now you can just use the class as normal

DESCRIPTION

Top

This is a set of example metaclasses which implement the Inside-Out class technique. What follows is a brief explaination of the code found in this module.

We must create a subclass of Class::MOP::Instance and override the slot operations. This requires overloading get_slot_value, set_slot_value, slot_initialized, and initialize_slot, as well as their inline counterparts. Additionally we overload add_slot in order to initialize the global hash containing the actual slot values.

And that is pretty much all. Of course I am ignoring need for inside-out objects to be DESTROY-ed, and some other details as well (threading, etc), but this is an example. A real implementation is left as an exercise to the reader.

AUTHORS

Top

Stevan Little <stevan@iinteractive.com>

Yuval Kogman <nothingmuch@woobling.com>

COPYRIGHT AND LICENSE

Top


Moose documentation  | view source Contained in the Moose distribution.