1 package Class::MOP::Class::Immutable::Trait;
9 use Scalar::Util 'blessed', 'weaken';
11 our $VERSION = '0.88';
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} }
18 sub immutable_options { %{ $_[0]{__immutable}{options} } }
21 sub is_immutable { 1 }
23 sub _immutable_metaclass { ref $_[1] }
28 confess "This method is read-only" if @_;
32 sub _immutable_cannot_call {
33 Carp::confess "This method cannot be called on an immutable instance";
36 sub add_method { _immutable_cannot_call() }
37 sub alias_method { _immutable_cannot_call() }
38 sub remove_method { _immutable_cannot_call() }
39 sub add_attribute { _immutable_cannot_call() }
40 sub remove_attribute { _immutable_cannot_call() }
41 sub remove_package_symbol { _immutable_cannot_call() }
43 sub class_precedence_list {
46 @{ $self->{__immutable}{class_precedence_list}
47 ||= [ $self->$orig ] };
53 @{ $self->{__immutable}{linearized_isa} ||= [ $self->$orig ] };
59 @{ $self->{__immutable}{get_all_methods} ||= [ $self->$orig ] };
62 sub get_all_method_names {
65 @{ $self->{__immutable}{get_all_method_names} ||= [ $self->$orig ] };
68 sub get_all_attributes {
71 @{ $self->{__immutable}{get_all_attributes} ||= [ $self->$orig ] };
74 sub get_meta_instance {
77 $self->{__immutable}{get_meta_instance} ||= $self->$orig;
83 $self->{__immutable}{get_method_map} ||= $self->$orig;
86 sub add_package_symbol {
89 confess "Cannot add package symbols to an immutable metaclass"
90 unless ( caller(3) )[3] eq 'Class::MOP::Package::get_package_symbol';
103 Class::MOP::Class::Immutable::Trait - Implements immutability for metaclass objects
107 This class provides a pseudo-trait that is applied to immutable metaclass
108 objects. In reality, it is simply a parent class.
110 It implements caching and read-only-ness for various metaclass methods.
114 Yuval Kogman E<lt>nothingmuch@cpan.orgE<gt>
116 =head1 COPYRIGHT AND LICENSE
118 Copyright 2009 by Infinity Interactive, Inc.
120 L<http://www.iinteractive.com>
122 This library is free software; you can redistribute it and/or modify
123 it under the same terms as Perl itself.