1 package Class::MOP::Class::Immutable::Trait;
9 use Scalar::Util 'blessed', 'weaken';
11 our $VERSION = '0.92';
12 $VERSION = eval $VERSION;
13 our $AUTHORITY = 'cpan:STEVAN';
15 # the original class of the metaclass instance
16 sub _get_mutable_metaclass_name { $_[0]{__immutable}{original_class} }
19 sub is_immutable { 1 }
21 sub _immutable_metaclass { ref $_[1] }
26 confess "This method is read-only" if @_;
30 sub _immutable_cannot_call {
31 Carp::confess "This method cannot be called on an immutable instance";
34 sub add_method { _immutable_cannot_call() }
35 sub alias_method { _immutable_cannot_call() }
36 sub remove_method { _immutable_cannot_call() }
37 sub add_attribute { _immutable_cannot_call() }
38 sub remove_attribute { _immutable_cannot_call() }
39 sub remove_package_symbol { _immutable_cannot_call() }
41 sub class_precedence_list {
44 @{ $self->{__immutable}{class_precedence_list}
45 ||= [ $self->$orig ] };
51 @{ $self->{__immutable}{linearized_isa} ||= [ $self->$orig ] };
57 @{ $self->{__immutable}{get_all_methods} ||= [ $self->$orig ] };
60 sub get_all_method_names {
63 @{ $self->{__immutable}{get_all_method_names} ||= [ $self->$orig ] };
66 sub get_all_attributes {
69 @{ $self->{__immutable}{get_all_attributes} ||= [ $self->$orig ] };
72 sub get_meta_instance {
75 $self->{__immutable}{get_meta_instance} ||= $self->$orig;
81 $self->{__immutable}{get_method_map} ||= $self->$orig;
84 sub add_package_symbol {
87 confess "Cannot add package symbols to an immutable metaclass"
88 unless ( caller(3) )[3] eq 'Class::MOP::Package::get_package_symbol';
101 Class::MOP::Class::Immutable::Trait - Implements immutability for metaclass objects
105 This class provides a pseudo-trait that is applied to immutable metaclass
106 objects. In reality, it is simply a parent class.
108 It implements caching and read-only-ness for various metaclass methods.
112 Yuval Kogman E<lt>nothingmuch@cpan.orgE<gt>
114 =head1 COPYRIGHT AND LICENSE
116 Copyright 2009 by Infinity Interactive, Inc.
118 L<http://www.iinteractive.com>
120 This library is free software; you can redistribute it and/or modify
121 it under the same terms as Perl itself.