| 1 | ####################################################################### | ||||||||||||||||||||||||||||||||||||||||||
| 2 | # $URL: http://perlcritic.tigris.org/svn/perlcritic/trunk/distributions/Perl-Critic-More/lib/Perl/Critic/Policy/Editor/RequireEmacsFileVariables.pm $ | ||||||||||||||||||||||||||||||||||||||||||
| 3 | # $Date: 2013-10-29 09:39:11 -0700 (Tue, 29 Oct 2013) $ | ||||||||||||||||||||||||||||||||||||||||||
| 4 | # $Author: thaljef $ | ||||||||||||||||||||||||||||||||||||||||||
| 5 | # $Revision: 4222 $ | ||||||||||||||||||||||||||||||||||||||||||
| 6 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | package Perl::Critic::Policy::Editor::RequireEmacsFileVariables; | ||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 7 | ▶ | use 5.006001; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | 7 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 7 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | 7 | ▶ | use Readonly; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | 7 | ▶ | use Perl::Critic::Utils qw{ :severities }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | 7 | ▶ | use base 'Perl::Critic::Policy'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | 7 | our $VERSION = '1.003'; | |||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | # This constant is hard-coded in emacs file.el | ||||||||||||||||||||||||||||||||||||||||||
| 23 | 7 | Readonly::Scalar my $LOOK_BYTES_FROM_END => 3000; | |||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||
| 25 | #--------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||
| 27 | 7 | Readonly::Scalar my $DESC => | |||||||||||||||||||||||||||||||||||||||||
| 28 | 'Use Emacs file variables to declare coding style'; | ||||||||||||||||||||||||||||||||||||||||||
| 29 | 7 | Readonly::Scalar my $EXPL => 'Emacs can read per-file settings'; | |||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | #--------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||
| 33 | 6 | ▶ | sub default_severity { return $SEVERITY_LOW } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
default_severity: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 34 | 1 | ▶ | sub default_themes { return qw< more readability editor > } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
default_themes: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | 13 | ▶ | sub applies_to { return 'PPI::Document' } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
applies_to: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 36 | 14 | ▶ | sub supported_parameters { return () } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
supported_parameters: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||
| 38 | #--------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||
| 40 | 13 | ▶ | sub violates { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
violates: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 41 | 13 | my ( $self, $elem, $doc ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||
| 43 | 13 | my $code = $doc->serialize(); | |||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||
| 45 | ## Look for first line file vars. Example: | ||||||||||||||||||||||||||||||||||||||||||
| 46 | # #! /usr/bin/perl -w -*- cperl; cperl-indent-level: 4 -*- | ||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||
| 48 | 13 | my $one_line_local_var = qr/-[*]- .* -[*]-/xms; | |||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||
| 50 | # Note: If PPI changes away from native newlines, this may break | ||||||||||||||||||||||||||||||||||||||||||
| 51 | 13 | my ( $first_line, $second_line ) | |||||||||||||||||||||||||||||||||||||||||
| 52 | = $code =~ m/\A ([^\n]*) (?: \n ([^\n]*) )? /xms; | ||||||||||||||||||||||||||||||||||||||||||
| 53 | 13 | ▶ | return if $first_line =~ m/$one_line_local_var/xms; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 54 | return | ||||||||||||||||||||||||||||||||||||||||||
| 55 | 8 | ▶ | if ( $second_line | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$second_line and $first_line =~ /\A \#!/msx and $second_line =~ /$one_line_local_var/msx
$second_line and $first_line =~ /\A \#!/msx
MC/DC100%3/3
$second_line and $first_line =~ /\A \#!/msx and $second_line =~ /$one_line_local_var/msx
$second_line
$first_line =~ /\A \#!/msx
$second_line =~ /$one_line_local_var/msx
Truth table100%4/4
A and B and C
A= $second_lineB= $first_line =~ /\A \#!/msxC= $second_line =~ /$one_line_local_var/msx
| |||||||||||||||||||||||||||||||||||||||||||
| 56 | && $first_line =~ m/\A \#!/xms | ||||||||||||||||||||||||||||||||||||||||||
| 57 | && $second_line =~ m/$one_line_local_var/xms ); | ||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||
| 59 | ## Look for end of doc file vars Example: | ||||||||||||||||||||||||||||||||||||||||||
| 60 | # Local Variables: | ||||||||||||||||||||||||||||||||||||||||||
| 61 | # mode: cperl | ||||||||||||||||||||||||||||||||||||||||||
| 62 | # End: | ||||||||||||||||||||||||||||||||||||||||||
| 63 | 7 | my $last_page = substr $code, -$LOOK_BYTES_FROM_END; | |||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||
| 65 | # Remove anything not on the last page, as delimited by "^L", aka | ||||||||||||||||||||||||||||||||||||||||||
| 66 | # "\f", aka formfeed. | ||||||||||||||||||||||||||||||||||||||||||
| 67 | 7 | $last_page =~ s/ .* \f//xms; | |||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||
| 69 | # This regex is transliterated from emacs22 files.el | ||||||||||||||||||||||||||||||||||||||||||
| 70 | # Note that the [ \t]* before "End:" appears to be wrong, but is | ||||||||||||||||||||||||||||||||||||||||||
| 71 | # added for compatibility | ||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||
| 73 | ## Due to the backreferences, this is almost impossible to subdivide. | ||||||||||||||||||||||||||||||||||||||||||
| 74 | ## no critic (ProhibitComplexRegexes) | ||||||||||||||||||||||||||||||||||||||||||
| 75 | 7 | ▶ | return if $last_page =~ m< | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 76 | ^ ([^\n]*) Local [ ] Variables: [ \t]* ([^\n]*) $ | ||||||||||||||||||||||||||||||||||||||||||
| 77 | .*? | ||||||||||||||||||||||||||||||||||||||||||
| 78 | ^ \1 [ \t]* End: [ \t]* \2 $ | ||||||||||||||||||||||||||||||||||||||||||
| 79 | >ixms; | ||||||||||||||||||||||||||||||||||||||||||
| 80 | ## use critic | ||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||
| 82 | 5 | return $self->violation( $DESC, $EXPL, $doc ); | |||||||||||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||
| 85 | 7 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||
| 87 | __END__ | ||||||||||||||||||||||||||||||||||||||||||