InsideOutClass - A set of example metaclasses which implement the Inside-Out technique
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
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.
get_slot_value
set_slot_value
slot_initialized
initialize_slot
add_slot
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.
DESTROY
Stevan Little <stevan@iinteractive.com>
Yuval Kogman <nothingmuch@woobling.com>
Copyright 2006-2008 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.
To install Moose, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Moose
CPAN shell
perl -MCPAN -e shell install Moose
For more information on module installation, please visit the detailed CPAN module installation guide.