The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

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

SYNOPSIS

  package Foo;
  
  use metaclass 'InsideOutClass' => (
     # tell our metaclass to use the 
     # InsideOut attribute metclass 
     # to construct all it's attributes
    ':attribute_metaclass' => 'InsideOutClass::Attribute'
  );
  
  __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

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.

First step is to subclass Class::MOP::Class and override the construct_instance method. The default construct_instance will create a HASH reference using the parameters and attribute default values. Since inside-out objects don't use HASH refs, and use package variables instead, we need to write code to handle this difference.

The next step is to create the subclass of Class::MOP::Attribute and override the method generation code. This requires overloading generate_accessor_method, generate_reader_method, generate_writer_method and generate_predicate_method. All other aspects are taken care of with the existing Class::MOP::Attribute infastructure.

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, but this is an example. A real implementation is left as an exercise to the reader.

AUTHOR

Stevan Little <stevan@iinteractive.com>

COPYRIGHT AND LICENSE

Copyright 2006 by Infinity Interactive, Inc.

http://www.iinteractive.com

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.