Perl::Critic::Policy::Documentation::ProhibitVerbatimMarkup - unexpanded CE<lt>E<gt> etc markup in POD verbatim paras


Perl-Critic-Pulp documentation Contained in the Perl-Critic-Pulp distribution.

Index


Code Index:

NAME

Top

Perl::Critic::Policy::Documentation::ProhibitVerbatimMarkup - unexpanded C<> etc markup in POD verbatim paras

DESCRIPTION

Top

This policy is part of the Perl::Critic::Pulp|Perl::Critic::Pulp addon. It reports POD verbatim paragraphs which contain markup like B<> or C<>. That markup will appear literally in the formatted output where you may have meant fontification.

    =head1 SOME THING

    Paragraph of text introducing an example,

        # call the C<foo> function      # bad
        &foo();

This is purely cosmetic so this policy is low priority and under the "cosmetic" theme (see POLICY THEMES in Perl::Critic). Normally it means one of two things,

Don't forget a verbatim paragraph extends to the next blank line and includes unindented lines until then (see Pod Definitions in perlpodspec). If you forget the blank the verbatimness continues

    =pod

        $some->sample;
        code();
    And this was I<meant> to be plain text.    # bad

Markup Forms

The check for markup is unsophisticated. Any of the POD specified "I<" "C<" etc is taken to be markup, plus "J<" of Pod::MultiLang.

    I<       # bad
    B<       # bad
    C<       # bad
    L<       # bad
    E<       # bad
    F<       # bad
    S<       # bad
    X<       # bad
    Z<       # bad
    J<       # bad, for Pod::MultiLang

It's possible a < might be something mathematical like "X<Y", but in practice spaces "X < Y" or lower case letters are more common and are ok.

Sample debugger output is exempted. It's uncommon, but not likely to have intended B<> bold.

    DB<123> dump b        # ok

Disabling

If a verbatim paragraph is showing how to write POD markup then you can add an =for to tell ProhibitVerbatimMarkup to allow it. This happens most often in documentation for modules which themselves operate on POD markup.

    =for ProhibitVerbatimMarkup allow next

        blah blah E<gt> etc

    =for ProhibitVerbatimMarkup allow next 2

        Two verbatims of C<code>

        or B<bold> etc

The usual no critic

    ## no critic (ProhibitVerbatimMarkup)

works too, but if the POD is after an __END__ token then Perl::Critic 1.112 is required, and the annotation must be before the __END__. An =for has the advantage of being with the exception.

As always if you don't care at all about this at all then disable ProhibitVerbatimMarkup from your .perlcriticrc in the usual way (see CONFIGURATION in Perl::Critic),

    [-Documentation::ProhibitVerbatimMarkup]

SEE ALSO

Top

Perl::Critic::Pulp, Perl::Critic, Perl::Critic::Policy::Documentation::ProhibitBadAproposMarkup, Perl::Critic::Policy::Documentation::RequireEndBeforeLastPod

HOME PAGE

Top

http://user42.tuxfamily.org/perl-critic-pulp/index.html

COPYRIGHT

Top


Perl-Critic-Pulp documentation Contained in the Perl-Critic-Pulp distribution.

# Copyright 2010, 2011 Kevin Ryde

# This file is part of Perl-Critic-Pulp.

# Perl-Critic-Pulp is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 3, or (at your option) any later
# version.
#
# Perl-Critic-Pulp is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
# for more details.
#
# You should have received a copy of the GNU General Public License along
# with Perl-Critic-Pulp.  If not, see <http://www.gnu.org/licenses/>.


# self:
# perlcritic -s ProhibitVerbatimMarkup ProhibitVerbatimMarkup.pm

package Perl::Critic::Policy::Documentation::ProhibitVerbatimMarkup;
use 5.006;
use strict;
use warnings;
use base 'Perl::Critic::Policy';
use Perl::Critic::Utils;

# uncomment this to run the ### lines
#use Smart::Comments;

our $VERSION = 61;

use constant supported_parameters => ();
use constant default_severity     => $Perl::Critic::Utils::SEVERITY_LOW;
use constant default_themes       => qw(pulp cosmetic);
use constant applies_to           => 'PPI::Document';

sub violates {
  my ($self, $elem, $document) = @_;
  ### ProhibitVerbatimMarkup on: $elem->content

  my $parser = Perl::Critic::PodParser::ProhibitVerbatimMarkup->new
    (policy => $self);
  $parser->parse_from_elem ($elem);
  return $parser->violations;
}

package Perl::Critic::PodParser::ProhibitVerbatimMarkup;
use strict;
use warnings;
use base 'Perl::Critic::Pulp::PodParser';

sub command {
  my $self = shift;
  my ($command, $text, $linenum, $paraobj) = @_;
  ### command: $command
  ### $text

  if ($command eq 'for'
      && $text =~ /^ProhibitVerbatimMarkup\b\s*(.*)/) {
    my $directive = $1;
    ### $directive
    if ($directive =~ /^allow next( (\d+))?/) {
      # numbered "allow next 5" means up to that many following verbatims
      # unnumbered "allow next" means one following verbatim
      $self->{'allow_next'} = (defined $2 ? $2 : 1);
    }
  }
  return '';
}

sub verbatim {
  my ($self, $text, $linenum, $paraobj) = @_;
  ### verbatim: $text

  if ($self->{'allow_next'}) {
    ### allow next: $self->{'allow_next'}
    $self->{'allow_next'}--;
    return '';
  }

  # I<> italic
  # B<> bold
  # C<> code
  # L<> link
  # E<> escape
  # F<> filename
  # S<> no break
  # X<> index
  # Z<> empty
  # J<> Pod::MultiLang
  #
  # DB<123> sample debugger output exempted
  #
  while ($text =~ /\bDB<\d+>|([IBCLEFSXZJ]<)/g) {
    next unless $1;
    my $markup = "$1>";

    $self->violation_at_linenum_and_textpos
      ("$markup markup in verbatim paragraph, is it meant to be so?",
       $linenum, $text, pos($text));
  }
  return '';
}

sub textblock {
  my ($self) = @_;
  $self->{'allow_next'} = 0;
  return '';
}

1;
__END__