2 package Class::MOP::Class::Immutable;
8 use Scalar::Util 'blessed';
10 our $VERSION = '0.01';
12 use base 'Class::MOP::Class';
14 # methods which can *not* be called
16 sub reinitialize { confess 'Cannot call method "reinitialize" on an immutable instance' }
18 sub add_method { confess 'Cannot call method "add_method" on an immutable instance' }
19 sub alias_method { confess 'Cannot call method "alias_method" on an immutable instance' }
20 sub remove_method { confess 'Cannot call method "remove_method" on an immutable instance' }
22 sub add_attribute { confess 'Cannot call method "add_attribute" on an immutable instance' }
23 sub remove_attribute { confess 'Cannot call method "remove_attribute" on an immutable instance' }
25 sub add_package_variable { confess 'Cannot call method "add_package_variable" on an immutable instance' }
26 sub remove_package_variable { confess 'Cannot call method "remove_package_variable" on an immutable instance' }
29 # superclasses is an accessor, so
30 # it just cannot be changed
33 (!@_) || confess 'Cannot change the "superclasses" on an immmutable instance';
35 @{$class->name . '::ISA'};
41 sub is_immutable { 1 }
43 sub make_immutable { () }
45 sub make_metaclass_immutable {
46 my ($class, $metaclass) = @_;
47 $metaclass->{'___class_precedence_list'} = [ $metaclass->class_precedence_list ];
48 $metaclass->{'___get_meta_instance'} = $metaclass->get_meta_instance;
49 $metaclass->{'___compute_all_applicable_attributes'} = [ $metaclass->compute_all_applicable_attributes ];
50 $metaclass->{'___original_class'} = blessed($metaclass);
51 bless $metaclass => $class;
56 sub get_meta_instance { (shift)->{'___get_meta_instance'} }
58 sub class_precedence_list {
59 @{ (shift)->{'___class_precedence_list'} }
62 sub compute_all_applicable_attributes {
63 @{ (shift)->{'___compute_all_applicable_attributes'} }
74 Class::MOP::Class::Immutable - An immutable version of Class::MOP::Class
86 This will return a B<Class::MOP::Class> instance which is related
98 Stevan Little E<lt>stevan@iinteractive.comE<gt>
100 =head1 COPYRIGHT AND LICENSE
102 Copyright 2006 by Infinity Interactive, Inc.
104 L<http://www.iinteractive.com>
106 This library is free software; you can redistribute it and/or modify
107 it under the same terms as Perl itself.