RequireMakeImmutable policy
[gitmo/Perl-Critic-Dynamic-Moose.git] / lib / Perl / Critic / Policy / DynamicMoose / RequireMakeImmutable.pm
CommitLineData
ad350a21 1package Perl::Critic::Policy::DynamicMoose::RequireMakeImmutable;
2use Moose;
3extends 'Perl::Critic::Policy::DynamicMoose';
4
5use Perl::Critic::Utils ':severities';
6use Perl::Critic::Utils::Moose 'meta_type';
7
8Readonly::Scalar my $EXPL => q{Moose can't optimize itself if classes remain mutable.};
9sub default_severity { $SEVERITY_HIGH }
10
11sub violates_metaclass {
12 my $self = shift;
13 my $meta = shift;
14
15 return if $meta->is_immutable;
16
17 my $desc = "The " . $meta->name . " " . meta_type($meta) . " was not made immutable.";
18
19 return $self->violation($desc, $EXPL);
20}
21
22no Moose;
23
241;
25
26__END__
27
28=head1 NAME
29
30Perl::Critic::Policy::DynamicMoose::RequireMakeImmutable
31
32=head1 DESCRIPTION
33
34
35=head1 WARNING
36
37B<VERY IMPORTANT:> Most L<Perl::Critic> Policies (including all the ones that
38ship with Perl::Critic> use pure static analysis -- they never compile nor
39execute any of the code that they analyze. However, this policy is very
40different. It actually attempts to compile your code and then compares the
41subroutines mentioned in your code to those found in the symbol table.
42Therefore you should B<not> use this Policy on any code that you do not trust,
43or may have undesirable side-effects at compile-time (such as connecting to the
44network or mutating files).
45
46For this Policy to work, all the modules included in your code must be
47installed locally, and must compile without error.
48
49=head1 AUTHOR
50
51Shawn M Moore, C<sartak@bestpractical.com>
52
53=cut
54