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