1 package Class::MOP::Class::Immutable::Trait;
9 use Scalar::Util 'blessed', 'weaken';
11 our $VERSION = '0.87';
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} } }
24 confess "This method is read-only" if @_ > 1;
28 sub _immutable_cannot_call {
29 Carp::confess "This method cannot be called on an immutable instance";
32 sub add_method { shift->_immutable_cannot_call }
33 sub alias_method { shift->_immutable_cannot_call }
34 sub remove_method { shift->_immutable_cannot_call }
35 sub add_attribute { shift->_immutable_cannot_call }
36 sub remove_attribute { shift->_immutable_cannot_call }
37 sub remove_package_symbol { shift->_immutable_cannot_call }
39 sub class_precedence_list {
40 @{ $_[0]{__immutable}{class_precedence_list}
41 ||= [ shift->next::method ] };
45 @{ $_[0]{__immutable}{linearized_isa} ||= [ shift->next::method ] };
49 @{ $_[0]{__immutable}{get_all_methods} ||= [ shift->next::method ] };
52 sub get_all_method_names {
53 @{ $_[0]{__immutable}{get_all_method_names} ||= [ shift->next::method ] };
56 sub get_all_attributes {
57 @{ $_[0]{__immutable}{get_all_attributes} ||= [ shift->next::method ] };
60 sub get_meta_instance {
61 $_[0]{__immutable}{get_meta_instance} ||= shift->next::method;
65 $_[0]{__immutable}{get_method_map} ||= shift->next::method;
68 sub add_package_symbol {
69 confess "Cannot add package symbols to an immutable metaclass"
70 unless ( caller(1) )[3] eq 'Class::MOP::Package::get_package_symbol';
72 shift->next::method(@_);
83 Class::MOP::Class::Immutable::Trait - Implements immutability for metaclass objects
87 This class provides a pseudo-trait that is applied to immutable metaclass
88 objects. In reality, it is simply a parent class.
90 It implements caching and read-only-ness for various metaclass methods.
94 Yuval Kogman E<lt>nothingmuch@cpan.orgE<gt>
96 =head1 COPYRIGHT AND LICENSE
98 Copyright 2009 by Infinity Interactive, Inc.
100 L<http://www.iinteractive.com>
102 This library is free software; you can redistribute it and/or modify
103 it under the same terms as Perl itself.