line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Perl::Critic::Policy::Moo::ProhibitMakeImmutable; |
2
|
1
|
|
|
1
|
|
371563
|
use 5.008001; |
|
1
|
|
|
|
|
4
|
|
3
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
22
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
39
|
|
5
|
|
|
|
|
|
|
our $VERSION = '0.06'; |
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
6
|
use Readonly; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
50
|
|
8
|
1
|
|
|
1
|
|
6
|
use Perl::Critic::Utils qw{ :severities :classification :ppi }; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
64
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
442
|
use base 'Perl::Critic::Policy'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
544
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
Readonly::Scalar my $DESC => q{Moo class should not call ->make_immutable}; |
13
|
|
|
|
|
|
|
Readonly::Scalar my $EXPL => q{When migrating from Moose to Moo it is easy to leave in __PACKAGE__->meta->make_immutable; statements which will cause Moose to be loaded and a metaclass created}; |
14
|
|
|
|
|
|
|
|
15
|
6
|
|
|
6
|
0
|
1182802
|
sub supported_parameters { return() } |
16
|
2
|
|
|
2
|
1
|
46
|
sub default_severity { return $SEVERITY_MEDIUM } |
17
|
0
|
|
|
0
|
1
|
0
|
sub default_themes { return qw( performance ) } |
18
|
6
|
|
|
6
|
1
|
1225884
|
sub applies_to { return 'PPI::Token::Word' } |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub violates { |
21
|
59
|
|
|
59
|
1
|
1102
|
my ($self, $start_word, $doc) = @_; |
22
|
|
|
|
|
|
|
|
23
|
59
|
100
|
|
|
|
140
|
return unless $start_word->content() eq '__PACKAGE__'; |
24
|
6
|
|
|
|
|
30
|
my $element = $start_word; |
25
|
|
|
|
|
|
|
|
26
|
6
|
|
|
|
|
30
|
$element = $element->snext_sibling(); |
27
|
6
|
50
|
33
|
|
|
218
|
return unless $element |
|
|
|
33
|
|
|
|
|
28
|
|
|
|
|
|
|
and $element->isa('PPI::Token::Operator') |
29
|
|
|
|
|
|
|
and $element->content() eq '->'; |
30
|
|
|
|
|
|
|
|
31
|
6
|
|
|
|
|
49
|
$element = $element->snext_sibling(); |
32
|
6
|
50
|
33
|
|
|
157
|
return unless $element |
|
|
|
33
|
|
|
|
|
33
|
|
|
|
|
|
|
and $element->isa('PPI::Token::Word') |
34
|
|
|
|
|
|
|
and $element->content() eq 'meta'; |
35
|
|
|
|
|
|
|
|
36
|
6
|
|
|
|
|
45
|
$element = $element->snext_sibling(); |
37
|
6
|
50
|
33
|
|
|
152
|
return unless $element |
|
|
|
33
|
|
|
|
|
38
|
|
|
|
|
|
|
and $element->isa('PPI::Token::Operator') |
39
|
|
|
|
|
|
|
and $element->content() eq '->'; |
40
|
|
|
|
|
|
|
|
41
|
6
|
|
|
|
|
45
|
$element = $element->snext_sibling(); |
42
|
6
|
50
|
33
|
|
|
151
|
return unless $element |
|
|
|
33
|
|
|
|
|
43
|
|
|
|
|
|
|
and $element->isa('PPI::Token::Word') |
44
|
|
|
|
|
|
|
and $element->content() eq 'make_immutable'; |
45
|
|
|
|
|
|
|
|
46
|
6
|
|
|
|
|
42
|
my $package = _find_package( $start_word ); |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
my $included = $doc->find_any(sub{ |
49
|
277
|
100
|
66
|
277
|
|
3834
|
$_[1]->isa('PPI::Statement::Include') |
|
|
|
100
|
|
|
|
|
|
|
|
66
|
|
|
|
|
50
|
|
|
|
|
|
|
and |
51
|
|
|
|
|
|
|
defined( $_[1]->module() ) |
52
|
|
|
|
|
|
|
and |
53
|
|
|
|
|
|
|
$_[1]->module() eq 'Moo' |
54
|
|
|
|
|
|
|
and |
55
|
|
|
|
|
|
|
$_[1]->type() eq 'use' |
56
|
|
|
|
|
|
|
and |
57
|
|
|
|
|
|
|
_find_package( $_[1] ) eq $package |
58
|
6
|
|
|
|
|
157
|
}); |
59
|
|
|
|
|
|
|
|
60
|
6
|
100
|
|
|
|
141
|
return if !$included; |
61
|
|
|
|
|
|
|
|
62
|
2
|
|
|
|
|
14
|
return $self->violation( $DESC, $EXPL, $start_word ); |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub _find_package { |
66
|
14
|
|
|
14
|
|
559
|
my ($element) = @_; |
67
|
|
|
|
|
|
|
|
68
|
14
|
|
|
|
|
34
|
my $original = $element; |
69
|
|
|
|
|
|
|
|
70
|
14
|
|
|
|
|
50
|
while ($element) { |
71
|
43
|
100
|
|
|
|
944
|
if ($element->isa('PPI::Statement::Package')) { |
72
|
|
|
|
|
|
|
# If this package statements is a block package, meaning: package { # stuff in package } |
73
|
|
|
|
|
|
|
# then if we're a descendant of it its our package. |
74
|
11
|
50
|
|
|
|
39
|
return $element->namespace() if $element->ancestor_of( $original ); |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
# If we've hit a non-block package then thats our package. |
77
|
11
|
|
|
|
|
184
|
my $blocks = $element->find_any('PPI::Structure::Block'); |
78
|
11
|
50
|
|
|
|
2880
|
return $element->namespace() if !$blocks; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
# Keep walking backwards until we match the above logic or we get to |
82
|
|
|
|
|
|
|
# the document root (main). |
83
|
32
|
|
100
|
|
|
131
|
$element = $element->sprevious_sibling() || $element->parent(); |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
3
|
|
|
|
|
38
|
return 'main'; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
1; |
90
|
|
|
|
|
|
|
__END__ |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=head1 NAME |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
Perl::Critic::Policy::Moo::ProhibitMakeImmutable - Makes sure that Moo classes |
95
|
|
|
|
|
|
|
do not contain calls to make_immutable. (DEPRECATED) |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=head1 DESCRIPTION |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
When migrating from L<Moose> to L<Moo> it can be a common issue to accidentally |
100
|
|
|
|
|
|
|
leave in: |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
This policy complains if this exists in a Moo class as it triggers Moose to be |
105
|
|
|
|
|
|
|
loaded and metaclass created, which defeats some of the benefits you get using |
106
|
|
|
|
|
|
|
Moo instead of Moose. |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=head1 DEPRECATED |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
This module has lost its usefulness as L<Moo>'s behavior is now clearly |
111
|
|
|
|
|
|
|
documented as NOT loading Moose when C<make_immutable> is called. |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
Read more about the L<Moo/meta> method for details of the current behavior. |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=head1 AUTHORS |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
Aran Clary Deltac <bluefeet@gmail.com> |
118
|
|
|
|
|
|
|
Kivanc Yazan <kyzn@users.noreply.github.com> |
119
|
|
|
|
|
|
|
Graham TerMarsch <graham@howlingfrog.com> |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
Thanks to L<ZipRecruiter|https://www.ziprecruiter.com/> |
124
|
|
|
|
|
|
|
for encouraging their employees to contribute back to the open |
125
|
|
|
|
|
|
|
source ecosystem. Without their dedication to quality software |
126
|
|
|
|
|
|
|
development this distribution would not exist. |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=head1 LICENSE |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
131
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=cut |
134
|
|
|
|
|
|
|
|