1 package Class::MOP::Class::Immutable::Trait;
9 use Scalar::Util 'blessed', 'weaken';
11 # the original class of the metaclass instance
12 sub _get_mutable_metaclass_name { $_[0]{__immutable}{original_class} }
15 sub is_immutable { 1 }
17 sub _immutable_metaclass { ref $_[1] }
22 confess "This method is read-only" if @_;
26 sub _immutable_cannot_call {
28 Carp::confess "The '$name' method cannot be called on an immutable instance";
31 for my $name (qw/add_method alias_method remove_method add_attribute remove_attribute remove_package_symbol add_package_symbol/) {
33 *{__PACKAGE__."::$name"} = sub { _immutable_cannot_call($name) };
36 sub class_precedence_list {
39 @{ $self->{__immutable}{class_precedence_list}
40 ||= [ $self->$orig ] };
46 @{ $self->{__immutable}{linearized_isa} ||= [ $self->$orig ] };
52 @{ $self->{__immutable}{get_all_methods} ||= [ $self->$orig ] };
55 sub get_all_method_names {
58 @{ $self->{__immutable}{get_all_method_names} ||= [ $self->$orig ] };
61 sub get_all_attributes {
64 @{ $self->{__immutable}{get_all_attributes} ||= [ $self->$orig ] };
67 sub get_meta_instance {
70 $self->{__immutable}{get_meta_instance} ||= $self->$orig;
76 $self->{__immutable}{_method_map} ||= $self->$orig;
81 # ABSTRACT: Implements immutability for metaclass objects
89 This class provides a pseudo-trait that is applied to immutable metaclass
90 objects. In reality, it is simply a parent class.
92 It implements caching and read-only-ness for various metaclass methods.