| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Perl::Critic::Policy::Plicease::ProhibitLeadingZeros; |
|
2
|
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
1510670
|
use strict; |
|
|
3
|
|
|
|
|
29
|
|
|
|
3
|
|
|
|
|
102
|
|
|
4
|
3
|
|
|
3
|
|
16
|
use warnings; |
|
|
3
|
|
|
|
|
8
|
|
|
|
3
|
|
|
|
|
95
|
|
|
5
|
3
|
|
|
3
|
|
67
|
use 5.008001; |
|
|
3
|
|
|
|
|
12
|
|
|
6
|
3
|
|
|
3
|
|
18
|
use Perl::Critic::Utils; |
|
|
3
|
|
|
|
|
6
|
|
|
|
3
|
|
|
|
|
81
|
|
|
7
|
3
|
|
|
3
|
|
2882
|
use base qw( Perl::Critic::Policy ); |
|
|
3
|
|
|
|
|
8
|
|
|
|
3
|
|
|
|
|
1673
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
# ABSTRACT: Leading zeroes are okay as the first arg to chmod, and other such reasonableness |
|
10
|
|
|
|
|
|
|
our $VERSION = '0.04'; # VERSION |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
my $DESCRIPTION = q{Integer with leading zeros outside of chmod, mkpath}; |
|
14
|
|
|
|
|
|
|
my $EXPLANATION = "Only use leading zeros on numbers indicating file modes"; |
|
15
|
|
|
|
|
|
|
|
|
16
|
1
|
|
|
1
|
1
|
19
|
sub default_severity { $SEVERITY_MEDIUM } |
|
17
|
0
|
|
|
0
|
1
|
0
|
sub default_themes { () } |
|
18
|
12
|
|
|
12
|
1
|
120097
|
sub applies_to { 'PPI::Token::Number' } |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub violates |
|
21
|
|
|
|
|
|
|
{ |
|
22
|
16
|
|
|
16
|
1
|
309
|
my($self, $element, undef) = @_; |
|
23
|
|
|
|
|
|
|
|
|
24
|
16
|
100
|
|
|
|
46
|
return unless $element =~ m/\A [+-]? (?: 0+ _* )+ [1-9]/mx; |
|
25
|
8
|
100
|
|
|
|
100
|
return if $element->sprevious_sibling eq 'chmod'; |
|
26
|
7
|
100
|
100
|
|
|
345
|
return if (eval { $element->sprevious_sibling->sprevious_sibling->sprevious_sibling->sprevious_sibling->sprevious_sibling }||'') eq 'mkpath'; |
|
27
|
|
|
|
|
|
|
|
|
28
|
6
|
|
|
|
|
361
|
my $working = eval { $element->parent->parent }; |
|
|
6
|
|
|
|
|
25
|
|
|
29
|
6
|
100
|
|
|
|
55
|
if($element->parent->isa('PPI::Statement::Expression')) |
|
30
|
|
|
|
|
|
|
{ |
|
31
|
5
|
|
|
|
|
32
|
my $working = $element->parent->parent; |
|
32
|
5
|
|
|
|
|
28
|
while(eval { $working->isa('PPI::Structure::List') }) |
|
|
10
|
|
|
|
|
53
|
|
|
33
|
|
|
|
|
|
|
{ |
|
34
|
5
|
|
|
|
|
87
|
$working = $working->parent; |
|
35
|
|
|
|
|
|
|
} |
|
36
|
5
|
100
|
66
|
|
|
37
|
return if $working and ($working->children)[0] eq 'chmod'; |
|
37
|
3
|
50
|
33
|
|
|
71
|
return if $working and ($working->children)[-3] eq 'mkpath'; |
|
38
|
|
|
|
|
|
|
} |
|
39
|
|
|
|
|
|
|
|
|
40
|
1
|
|
|
|
|
16
|
return $self->violation($DESCRIPTION, $EXPLANATION, $element); |
|
41
|
|
|
|
|
|
|
} |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
1; |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
__END__ |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=pod |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=encoding UTF-8 |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=head1 NAME |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
Perl::Critic::Policy::Plicease::ProhibitLeadingZeros - Leading zeroes are okay as the first arg to chmod, and other such reasonableness |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=head1 VERSION |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
version 0.04 |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
This is a stupid mistake: |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
my $x = 1231; |
|
64
|
|
|
|
|
|
|
my $y = 2345; |
|
65
|
|
|
|
|
|
|
my $z = 0032; |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
This is not: |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
chmod 0700, "secret_file.txt"; |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
Neither is this: |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
use File::Path qw( mkpath ); |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
mkpath("/foo/bar/baz", 1, 0700); |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
Nor is this: |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
use Path::Class qw( dir ); |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
dir()->mkpath(1,0700); |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=head1 CAVEATS |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
Because C<mkpath> is not a built in (as C<chmod> is), this policy does not differentiate between the |
|
86
|
|
|
|
|
|
|
C<mkpath> function provided by L<File::Path> or the C<mkpath> method provided by L<Path::Class::Dir> |
|
87
|
|
|
|
|
|
|
and arbitrary C<mkpath> function or methods that you or someone else might define. Also, there is |
|
88
|
|
|
|
|
|
|
no way to really check if the object invocant of a C<mkpath> method is really an instance of |
|
89
|
|
|
|
|
|
|
L<Path::Class::Dir>. |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
This policy is based largely on the existing in-core policy, and one in the lax bundle, but adds a |
|
94
|
|
|
|
|
|
|
few exceptions that I find useful. |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=over 4 |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=item L<Perl::Critic::Policy::ValuesAndExpressions::ProhibitLeadingZeros> |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=item L<Perl::Critic::Policy::Lax::ProhibitLeadingZeros::ExceptChmod> |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=back |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=head1 AUTHOR |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
Author: Graham Ollis E<lt>plicease@cpan.orgE<gt> |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
Contributors: |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
Ville Skyttä (SCOP) |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
This software is copyright (c) 2019 by Graham Ollis. |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
|
117
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=cut |