« Policy/Documentation/ProhibitUnbalancedParens.pm
↑ Summary
Policy/CodeLayout/RequireFinalSemicolon.pm »
| 1 | # Copyright 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2019, 2021 Kevin Ryde | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | # This file is part of Perl-Critic-Pulp. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | # Perl-Critic-Pulp is free software; you can redistribute it and/or modify | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | # it under the terms of the GNU General Public License as published by the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | # Free Software Foundation; either version 3, or (at your option) any later | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | # version. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | # Perl-Critic-Pulp is distributed in the hope that it will be useful, but | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | # for more details. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | # You should have received a copy of the GNU General Public License along | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | # with Perl-Critic-Pulp. If not, see <http://www.gnu.org/licenses/>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | package Perl::Critic::Policy::Documentation::ProhibitAdjacentLinks; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 40 | ▶ | use 5.006; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 40 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 40 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 40 | ▶ | use base 'Perl::Critic::Policy'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 40 | ▶ | use Perl::Critic::Utils; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | # uncomment this to run the ### lines | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | #use Smart::Comments; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | # perlcritic -s ProhibitAdjacentLinks ProhibitAdjacentLinks.pm | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | # perlcritic -s ProhibitAdjacentLinks /usr/share/perl5/SVG.pm | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | # cf /usr/lib/perl5/Template/Context.pm | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | # L<Template> L<new()|Template#new()> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | # the "#" separator is wrong though | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | # cf /usr/share/perl5/DBIx/Class/Storage/DBI.pm | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | # L<DBI|DBI/ATTRIBUTES_COMMON_TO_ALL_HANDLES> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | # L<connection|DBI/Database_Handle_Attributes> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | # /usr/share/perl5/DhMakePerl/PodParser.pm | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | # L<Pod::Parser> L<command|Pod::Parser/command> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 40 | our $VERSION = 100; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 40 | ▶ | use constant supported_parameters => (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 40 | ▶ | use constant default_severity => $Perl::Critic::Utils::SEVERITY_LOWEST; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 40 | ▶ | use constant default_themes => qw(pulp cosmetic); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 40 | ▶ | use constant applies_to => 'PPI::Document'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 19 | ▶ | sub violates { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
violates: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 19 | my ($self, $elem, $document) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | ### ProhibitAdjacentLinks on: $elem->content | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 19 | my $parser = Perl::Critic::Policy::Documentation::ProhibitAdjacentLinks::Parser->new | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | (policy => $self); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 19 | $parser->parse_from_elem ($elem); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 19 | return $parser->violations; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | package Perl::Critic::Policy::Documentation::ProhibitAdjacentLinks::Parser; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 40 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 40 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 40 | ▶ | use Pod::ParseLink; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 40 | ▶ | use base 'Perl::Critic::Pulp::PodParser'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 40 | my %command_non_text = (for => 1, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | begin => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | end => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | cut => 1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 23 | ▶ | sub command { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
command: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 23 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 23 | my ($command, $text, $linenum, $paraobj) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 23 | $self->SUPER::command(@_); # maintain 'in_begin' | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 23 | ▶ | if ($command_non_text{$command}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | # skip directives | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 4 | return ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 19 | $self->textblock ($text, $linenum, $paraobj); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 19 | return ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 40 | ▶ | sub textblock { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
textblock: called CC=17 SCAR=28.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 40 | my ($self, $text, $linenum, $pod_para) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | ### textblock | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | ### $text | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | # process outside =begin, and inside =begin which is ":" markup | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 40 | ▶ | unless ($self->{'in_begin'} eq '' || $self->{'in_begin'} =~ /^:/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->{"in_begin"} eq "" or $self->{"in_begin"} =~ /^:/
MC/DC50%1/2
$self->{"in_begin"} eq "" or $self->{"in_begin"} =~ /^:/
$self->{"in_begin"} eq ""
$self->{"in_begin"} =~ /^:/
Truth table66%2/3
A or B
A= $self->{"in_begin"} eq ""B= $self->{"in_begin"} =~ /^:/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 1 | return ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 39 | my $expand = $self->interpolate ($text, $linenum); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | ### $expand | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 39 | my $ptree = $self->parse_text ($text, $linenum); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 39 | my @pending = reverse $ptree->children; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 39 | my $last_L = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 39 | my $last_L_name = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 39 | my $last_L_display; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 39 | my $last_L_linenum = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 39 | ▶ | while (@pending) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 74 | my $obj = pop @pending; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 74 | ▶ | if (! ref $obj) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | # plain text | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 36 | ▶ | if ($obj !~ /^\s*$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | # some text, not just whitespace | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 4 | $last_L = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | # a Pod::InteriorSequence | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 38 | my $cmd = $obj->cmd_name; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 38 | ▶ | if ($cmd eq 'L') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 37 | (undef, $linenum) = $obj->file_line; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | my $obj_text = join ('', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 37 | ▶ | map {ref $_ ? $_->raw_text : $_} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | $obj->parse_tree); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 37 | my ($display, $inferred, $name, $section, $type) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | = Pod::ParseLink::parselink ($obj_text); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | ### $obj_text | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | ### $display | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | ### $name | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 37 | ▶ | if (! defined $name) { $name = ''; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 37 | ▶ | if ($last_L | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%9/9
$last_L and not $name eq $last_L_name && (defined $display || defined $last_L_display)
$name eq $last_L_name && (defined $display || defined $last_L_display)
defined $display or defined $last_L_display
MC/DC100%4/4
$last_L and not $name eq $last_L_name && (defined $display || defined $last_L_display)
$last_L
$name eq $last_L_name
defined $display
defined $last_L_display
Truth table100%5/5
A and not(B && C or D)
A= $last_LB= $name eq $last_L_nameC= defined $displayD= defined $last_L_display
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | && ! ($name eq $last_L_name | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | && (defined $display || defined $last_L_display))) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 11 | $self->violation_at_linenum_and_textpos | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | ("Adjacent L<> sequences, perhaps a comma or words should be in between", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | $last_L_linenum, '', 0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 37 | $last_L = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 37 | $last_L_name = $name; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 37 | $last_L_display = $display; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 37 | $last_L_linenum = $linenum; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | ▶ | } elsif ($cmd eq 'X' || $cmd eq 'Z') { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$cmd eq "X" or $cmd eq "Z"
MC/DC0%0/2
$cmd eq "X" or $cmd eq "Z"
$cmd eq "X"
$cmd eq "Z"
Truth table33%1/3
A or B
A= $cmd eq "X"B= $cmd eq "Z"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | # ignore X<> index entries, maybe Z<> crunched already | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | # descend into other like C<> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 1 | ▶ | if (my $subtree = $obj->parse_tree) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 1 | push @pending, reverse $subtree->children; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 39 | ▶ | if ($text !~ /^\s.*$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 39 | $self->{'last'} = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | ### last now: $self->{'last'} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 39 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 40 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||