Class::MOP::Immutable.3pm

Langue: en

Version: 2009-04-01 (fedora - 05/07/09)

Section: 3 (Bibliothèques de fonctions)

NAME

Class::MOP::Immutable - A class to transform Class::MOP::Class metaclasses

SYNOPSIS

     use Class::MOP::Immutable;
 
     my $immutable_metaclass = Class::MOP::Immutable->new($metaclass, {
         read_only   => [qw/superclasses/],
         cannot_call => [qw/
             add_method
             alias_method
             remove_method
             add_attribute
             remove_attribute
             add_package_symbol
             remove_package_symbol
         /],
         memoize     => {
             class_precedence_list             => 'ARRAY',
             compute_all_applicable_attributes => 'ARRAY',
             get_meta_instance                 => 'SCALAR',
             get_method_map                    => 'SCALAR',
         }
     });
 
     $immutable_metaclass->make_metaclass_immutable;
 
 

DESCRIPTION

This class encapsulates the logic behind immutabilization.

This class provides generic immutabilization logic. Decisions about what gets transformed are up to the caller.

Immutabilization allows for a number of transformations. It can ask the calling metaclass to inline methods such as the constructor, destructor, or accessors. It can memoize metaclass accessors themselves. It can also turn read-write accessors in the metaclass into read-only methods, and make attempting to set these values an error. Finally, it can make some methods throw an exception when they are called. This is used to disable methods that can alter the class.

METHODS

Class::MOP::Immutable->new($metaclass, %options)
This method takes a metaclass object (typically a Class::MOP::Class object) and a hash of options.

It returns a new transformer, but does not actually do any transforming yet.

This method accepts the following options:

inline_accessors
inline_constructor
inline_destructor

These are all booleans indicating whether the specified method(s) should be inlined.

By default, accessors and the constructor are inlined, but not the destructor.

replace_constructor

This is a boolean indicating whether an existing constructor should be replaced when inlining a constructor. This defaults to false.

constructor_name

This is the constructor method name. This defaults to ``new''.

constructor_class

The name of the method metaclass for constructors. It will be used to generate the inlined constructor. This defaults to ``Class::MOP::Method::Constructor''.

destructor_class

The name of the method metaclass for destructors. It will be used to generate the inlined destructor. This defaults to ``Class::MOP::Method::Denstructor''.

memoize

This option takes a hash reference. They keys are method names to be memoized, and the values are the type of data the method returns. This can be one of ``SCALAR'', ``ARRAY'', or ``HASH''.

read_only

This option takes an array reference of read-write methods which will be made read-only. After they are transformed, attempting to set them will throw an error.

cannot_call

This option takes an array reference of methods which cannot be called after immutabilization. Attempting to call these methods will throw an error.

wrapped

This option takes a hash reference. The keys are method names and the body is a subroutine reference which will wrap the named method. This allows you to do some sort of custom transformation to a method.

$transformer->options
Returns a hash reference of the options passed to "new".
$transformer->metaclass
Returns the metaclass object passed to "new".
$transformer->immutable_metaclass
Returns the immutable metaclass object that is created by the transformation process.
$transformer->inlined_constructor
If the constructor was inlined, this returns the constructor method object that was created to do this.
$transformer->make_metaclass_immutable
Makes the transformer's metaclass immutable.
$transformer->make_metaclass_mutable
Makes the transformer's metaclass mutable.

AUTHORS

Stevan Little <stevan@iinteractive.com> Copyright 2006-2009 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.