Commit | Line | Data |
0fa70d03 |
1 | package Moose::Meta::Class::Immutable::Trait; |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
6 | use Class::MOP; |
90a49845 |
7 | use Scalar::Util qw( blessed ); |
0fa70d03 |
8 | |
16c237c1 |
9 | our $AUTHORITY = 'cpan:STEVAN'; |
10 | |
0fa70d03 |
11 | use base 'Class::MOP::Class::Immutable::Trait'; |
12 | |
d9205410 |
13 | sub add_role { $_[1]->_immutable_cannot_call } |
0fa70d03 |
14 | |
aaf4b735 |
15 | sub calculate_all_roles { |
d9205410 |
16 | my $orig = shift; |
17 | my $self = shift; |
18 | @{ $self->{__immutable}{calculate_all_roles} ||= [ $self->$orig ] }; |
aaf4b735 |
19 | } |
0fa70d03 |
20 | |
5a5fd3c0 |
21 | sub calculate_all_roles_with_inheritance { |
22 | my $orig = shift; |
23 | my $self = shift; |
24 | @{ $self->{__immutable}{calculate_all_roles_with_inheritance} ||= [ $self->$orig ] }; |
25 | } |
26 | |
90a49845 |
27 | sub does_role { |
28 | shift; |
29 | my $self = shift; |
30 | my $role = shift; |
31 | |
32 | (defined $role) |
33 | || $self->throw_error("You must supply a role name to look for"); |
34 | |
35 | $self->{__immutable}{does_role} ||= { map { $_->name => 1 } $self->calculate_all_roles_with_inheritance }; |
36 | |
37 | my $name = blessed $role ? $role->name : $role; |
38 | |
39 | return $self->{__immutable}{does_role}{$name}; |
40 | } |
41 | |
0fa70d03 |
42 | 1; |
2dc27d6f |
43 | |
ad46f524 |
44 | # ABSTRACT: Implements immutability for metaclass objects |
45 | |
2dc27d6f |
46 | __END__ |
47 | |
48 | =pod |
49 | |
2dc27d6f |
50 | =head1 DESCRIPTION |
51 | |
52 | This class makes some Moose-specific metaclass methods immutable. This |
53 | is deep guts. |
54 | |
c5fc2c21 |
55 | =head1 BUGS |
56 | |
57 | See L<Moose/BUGS> for details on reporting bugs. |
58 | |
2dc27d6f |
59 | =cut |
60 | |