bump version to 1.19
[gitmo/Moose.git] / lib / Moose / Meta / Class / Immutable / Trait.pm
CommitLineData
0fa70d03 1package Moose::Meta::Class::Immutable::Trait;
2
3use strict;
4use warnings;
5
6use Class::MOP;
90a49845 7use Scalar::Util qw( blessed );
0fa70d03 8
245478d5 9our $VERSION = '1.19';
16c237c1 10$VERSION = eval $VERSION;
11our $AUTHORITY = 'cpan:STEVAN';
12
0fa70d03 13use base 'Class::MOP::Class::Immutable::Trait';
14
d9205410 15sub add_role { $_[1]->_immutable_cannot_call }
0fa70d03 16
aaf4b735 17sub calculate_all_roles {
d9205410 18 my $orig = shift;
19 my $self = shift;
20 @{ $self->{__immutable}{calculate_all_roles} ||= [ $self->$orig ] };
aaf4b735 21}
0fa70d03 22
5a5fd3c0 23sub calculate_all_roles_with_inheritance {
24 my $orig = shift;
25 my $self = shift;
26 @{ $self->{__immutable}{calculate_all_roles_with_inheritance} ||= [ $self->$orig ] };
27}
28
90a49845 29sub does_role {
30 shift;
31 my $self = shift;
32 my $role = shift;
33
34 (defined $role)
35 || $self->throw_error("You must supply a role name to look for");
36
37 $self->{__immutable}{does_role} ||= { map { $_->name => 1 } $self->calculate_all_roles_with_inheritance };
38
39 my $name = blessed $role ? $role->name : $role;
40
41 return $self->{__immutable}{does_role}{$name};
42}
43
0fa70d03 441;
2dc27d6f 45
46__END__
47
48=pod
49
50=head1 NAME
51
52Moose::Meta::Class::Immutable::Trait - Implements immutability for metaclass objects
53
54=head1 DESCRIPTION
55
56This class makes some Moose-specific metaclass methods immutable. This
57is deep guts.
58
c5fc2c21 59=head1 BUGS
60
61See L<Moose/BUGS> for details on reporting bugs.
62
2dc27d6f 63=head1 AUTHOR
64
65Yuval Kogman E<lt>nothingmuch@cpan.orgE<gt>
66
67=head1 COPYRIGHT AND LICENSE
68
69Copyright 2009 by Infinity Interactive, Inc.
70
71L<http://www.iinteractive.com>
72
73This library is free software; you can redistribute it and/or modify
74it under the same terms as Perl itself.
75
76=cut
77