1 package Class::MOP::Class::Immutable::Trait;
9 use Scalar::Util 'blessed', 'weaken';
11 our $AUTHORITY = 'cpan:STEVAN';
13 # the original class of the metaclass instance
14 sub _get_mutable_metaclass_name { $_[0]{__immutable}{original_class} }
17 sub is_immutable { 1 }
19 sub _immutable_metaclass { ref $_[1] }
24 confess "This method is read-only" if @_;
28 sub _immutable_cannot_call {
30 Carp::confess "The '$name' method cannot be called on an immutable instance";
33 for my $name (qw/add_method alias_method remove_method add_attribute remove_attribute remove_package_symbol add_package_symbol/) {
35 *{__PACKAGE__."::$name"} = sub { _immutable_cannot_call($name) };
38 sub class_precedence_list {
41 @{ $self->{__immutable}{class_precedence_list}
42 ||= [ $self->$orig ] };
48 @{ $self->{__immutable}{linearized_isa} ||= [ $self->$orig ] };
54 @{ $self->{__immutable}{get_all_methods} ||= [ $self->$orig ] };
57 sub get_all_method_names {
60 @{ $self->{__immutable}{get_all_method_names} ||= [ $self->$orig ] };
63 sub get_all_attributes {
66 @{ $self->{__immutable}{get_all_attributes} ||= [ $self->$orig ] };
69 sub get_meta_instance {
72 $self->{__immutable}{get_meta_instance} ||= $self->$orig;
78 $self->{__immutable}{_method_map} ||= $self->$orig;
83 # ABSTRACT: Implements immutability for metaclass objects
91 This class provides a pseudo-trait that is applied to immutable metaclass
92 objects. In reality, it is simply a parent class.
94 It implements caching and read-only-ness for various metaclass methods.