Commit | Line | Data |
857f87a7 |
1 | |
2 | package Class::MOP::Class::Immutable; |
3 | |
4 | use strict; |
5 | use warnings; |
6 | |
7 | use Carp 'confess'; |
8 | use Scalar::Util 'blessed'; |
9 | |
10 | our $VERSION = '0.01'; |
11 | |
12 | use base 'Class::MOP::Class'; |
13 | |
14 | # methods which can *not* be called |
15 | |
16 | sub reinitialize { confess 'Cannot call method "reinitialize" on an immutable instance' } |
17 | |
18 | sub add_method { confess 'Cannot call method "add_method" on an immutable instance' } |
19 | sub alias_method { confess 'Cannot call method "alias_method" on an immutable instance' } |
20 | sub remove_method { confess 'Cannot call method "remove_method" on an immutable instance' } |
21 | |
22 | sub add_attribute { confess 'Cannot call method "add_attribute" on an immutable instance' } |
23 | sub remove_attribute { confess 'Cannot call method "remove_attribute" on an immutable instance' } |
24 | |
25 | sub add_package_variable { confess 'Cannot call method "add_package_variable" on an immutable instance' } |
26 | sub remove_package_variable { confess 'Cannot call method "remove_package_variable" on an immutable instance' } |
27 | |
28 | # NOTE: |
29 | # superclasses is an accessor, so |
30 | # it just cannot be changed |
31 | sub superclasses { |
32 | my $class = shift; |
33 | (!@_) || confess 'Cannot change the "superclasses" on an immmutable instance'; |
34 | no strict 'refs'; |
35 | @{$class->name . '::ISA'}; |
36 | } |
37 | |
38 | # predicates |
39 | |
40 | sub is_mutable { 0 } |
41 | sub is_immutable { 1 } |
42 | |
43 | sub make_immutable { () } |
44 | |
45 | sub make_metaclass_immutable { |
46 | my ($class, $metaclass) = @_; |
47 | $metaclass->{'___class_precedence_list'} = [ $metaclass->class_precedence_list ]; |
48 | $metaclass->{'___get_meta_instance'} = $metaclass->get_meta_instance; |
49 | $metaclass->{'___compute_all_applicable_attributes'} = [ $metaclass->compute_all_applicable_attributes ]; |
50 | $metaclass->{'___original_class'} = blessed($metaclass); |
51 | bless $metaclass => $class; |
52 | } |
53 | |
54 | # cached methods |
55 | |
56 | sub get_meta_instance { (shift)->{'___get_meta_instance'} } |
57 | |
58 | sub class_precedence_list { |
59 | @{ (shift)->{'___class_precedence_list'} } |
60 | } |
61 | |
62 | sub compute_all_applicable_attributes { |
63 | @{ (shift)->{'___compute_all_applicable_attributes'} } |
64 | } |
65 | |
66 | 1; |
67 | |
68 | __END__ |
69 | |
70 | =pod |
71 | |
72 | =head1 NAME |
73 | |
74 | Class::MOP::Class::Immutable - An immutable version of Class::MOP::Class |
75 | |
76 | =head1 SYNOPSIS |
77 | |
78 | =head1 DESCRIPTION |
79 | |
80 | =head1 METHODS |
81 | |
82 | =over 4 |
83 | |
84 | =item B<meta> |
85 | |
86 | This will return a B<Class::MOP::Class> instance which is related |
87 | to this class. |
88 | |
89 | =back |
90 | |
2243a22b |
91 | =head2 Methods which will die if you touch them. |
92 | |
93 | =over 4 |
94 | |
95 | =item B<add_attribute> |
96 | |
97 | =item B<add_method> |
98 | |
99 | =item B<add_package_variable> |
100 | |
101 | =item B<alias_method> |
102 | |
103 | =item B<reinitialize> |
104 | |
105 | =item B<remove_attribute> |
106 | |
107 | =item B<remove_method> |
108 | |
109 | =item B<remove_package_variable> |
110 | |
111 | =item B<superclasses> |
112 | |
113 | =back |
114 | |
115 | =head2 Cached methods |
116 | |
857f87a7 |
117 | =over 4 |
118 | |
2243a22b |
119 | =item B<class_precedence_list> |
120 | |
121 | =item B<compute_all_applicable_attributes> |
122 | |
123 | =item B<get_meta_instance> |
124 | |
125 | =back |
126 | |
127 | =head2 Introspection and Construction |
128 | |
129 | =over 4 |
130 | |
131 | =item B<is_immutable> |
132 | |
133 | =item B<is_mutable> |
134 | |
135 | =item B<make_immutable> |
136 | |
137 | =item B<make_metaclass_immutable> |
857f87a7 |
138 | |
139 | =back |
140 | |
141 | =head1 AUTHOR |
142 | |
143 | Stevan Little E<lt>stevan@iinteractive.comE<gt> |
144 | |
145 | =head1 COPYRIGHT AND LICENSE |
146 | |
147 | Copyright 2006 by Infinity Interactive, Inc. |
148 | |
149 | L<http://www.iinteractive.com> |
150 | |
151 | This library is free software; you can redistribute it and/or modify |
152 | it under the same terms as Perl itself. |
153 | |
154 | =cut |