1 package Class::MOP::Class::Immutable::Trait;
9 use Scalar::Util 'blessed', 'weaken';
14 # if it is not blessed, then someone is asking
15 # for the meta of Class::MOP::Class:;Immutable::Trait
16 return Class::MOP::Class->initialize($self) unless blessed($self);
18 # otherwise, they are asking for the metaclass
19 # which has been made immutable, which is itself
20 # except in the cases where it is a metaclass itself
21 # that has been made immutable and for that we need
24 if ( $self->isa('Class::MOP::Class') ) {
26 # except this is a lie... oh well
27 return Class::MOP::class_of( $self->get_mutable_metaclass_name );
34 # the original class of the metaclass instance
35 sub get_mutable_metaclass_name { $_[0]{__immutable}{original_class} }
37 sub immutable_options { %{ $_[0]{__immutable}{options} } }
43 confess "This method is read-only" if @_ > 1;
47 sub _immutable_cannot_call {
48 Carp::confess "This method cannot be called on an immutable instance";
51 sub add_method { shift->_immutable_cannot_call }
52 sub alias_method { shift->_immutable_cannot_call }
53 sub remove_method { shift->_immutable_cannot_call }
54 sub add_attribute { shift->_immutable_cannot_call }
55 sub remove_attribute { shift->_immutable_cannot_call }
56 sub remove_package_symbol { shift->_immutable_cannot_call }
58 sub class_precedence_list {
59 @{ $_[0]{__immutable}{class_precedence_list}
60 ||= [ shift->next::method ] };
64 @{ $_[0]{__immutable}{linearized_isa} ||= [ shift->next::method ] };
68 @{ $_[0]{__immutable}{get_all_methods} ||= [ shift->next::method ] };
71 sub get_all_method_names {
72 @{ $_[0]{__immutable}{get_all_method_names} ||= [ shift->next::method ] };
75 sub get_all_attributes {
76 @{ $_[0]{__immutable}{get_all_attributes} ||= [ shift->next::method ] };
79 sub get_meta_instance {
80 $_[0]{__immutable}{get_meta_instance} ||= shift->next::method;
84 $_[0]{__immutable}{get_method_map} ||= shift->next::method;
87 sub add_package_symbol {
88 confess "Cannot add package symbols to an immutable metaclass"
89 unless ( caller(1) )[3] eq 'Class::MOP::Package::get_package_symbol';
91 shift->next::method(@_);