1 package Class::MOP::Class::Immutable::Trait;
9 use Scalar::Util 'blessed', 'weaken';
11 our $VERSION = '0.97_01';
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 {
32 Carp::confess "The '$name' method cannot be called on an immutable instance";
35 for my $name (qw/add_method alias_method remove_method add_attribute remove_attribute remove_package_symbol/) {
37 *{__PACKAGE__."::$name"} = sub { _immutable_cannot_call($name) };
40 sub class_precedence_list {
43 @{ $self->{__immutable}{class_precedence_list}
44 ||= [ $self->$orig ] };
50 @{ $self->{__immutable}{linearized_isa} ||= [ $self->$orig ] };
56 @{ $self->{__immutable}{get_all_methods} ||= [ $self->$orig ] };
59 sub get_all_method_names {
62 @{ $self->{__immutable}{get_all_method_names} ||= [ $self->$orig ] };
65 sub get_all_attributes {
68 @{ $self->{__immutable}{get_all_attributes} ||= [ $self->$orig ] };
71 sub get_meta_instance {
74 $self->{__immutable}{get_meta_instance} ||= $self->$orig;
80 $self->{__immutable}{_get_method_map} ||= $self->$orig;
83 sub add_package_symbol {
86 confess "Cannot add package symbols to an immutable metaclass"
87 unless ( caller(3) )[3] eq 'Class::MOP::Package::get_package_symbol';
100 Class::MOP::Class::Immutable::Trait - Implements immutability for metaclass objects
104 This class provides a pseudo-trait that is applied to immutable metaclass
105 objects. In reality, it is simply a parent class.
107 It implements caching and read-only-ness for various metaclass methods.
111 Yuval Kogman E<lt>nothingmuch@cpan.orgE<gt>
113 =head1 COPYRIGHT AND LICENSE
115 Copyright 2009 by Infinity Interactive, Inc.
117 L<http://www.iinteractive.com>
119 This library is free software; you can redistribute it and/or modify
120 it under the same terms as Perl itself.