Perl::Critic::Policy::Documentation::ProhibitBadAproposMarkup - don't use CE<lt>E<gt> markup in a NAME section


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

Index


Code Index:

NAME

Top

Perl::Critic::Policy::Documentation::ProhibitBadAproposMarkup - don't use C<> markup in a NAME section

DESCRIPTION

Top

This policy is part of the Perl::Critic::Pulp|Perl::Critic::Pulp addon. It asks you not to write C<> markup in the NAME section of the POD because it comes out badly in man's "apropos" database. For example,

    =head1 NAME

    foo - like the C<bar> program     # bad

pod2man formats "C<>" using nroff macros which "man-db"'s lexgrog program doesn't expand, resulting in unattractive description lines from apropos like

    foo - like the *(C`bar*(C' program

Man's actual formatted output is fine, and the desired text is in there, just surrounded by "*(C" bits. On that basis this policy is low priority and under the "cosmetic" theme (see POLICY THEMES in Perl::Critic).

The NAME section is everything from "=head1 NAME" to the next "=head1". Other markup like "B<>", "I<>" and "F<>" is allowed because pod2man uses builtin "\fB" etc directives for them, which lexgrog recognises.

Disabling

If want markup in the NAME line, perhaps if printed output is more important than apropos, then you can always disable from your .perlcriticrc in the usual way (see CONFIGURATION in Perl::Critic),

    [-Documentation::ProhibitBadAproposMarkup]

Or in an individual file with the usual ## no critic

    ## no critic (ProhibitBadAproposMarkup)

though if the NAME part is after an __END__ token then Perl::Critic 1.112 or higher is required (and the annotation must be before the __END__).

SEE ALSO

Top

Perl::Critic::Pulp, Perl::Critic, Perl::Critic::Policy::Documentation::RequirePackageMatchesPodName, Perl::Critic::Policy::Documentation::RequirePodSections, Perl::Critic::Policy::Documentation::ProhibitVerbatimMarkup

man(1), apropos(1), lexgrog(1)

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 2009, 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/>.


package Perl::Critic::Policy::Documentation::ProhibitBadAproposMarkup;
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) = @_;
  my $parser = Perl::Critic::Pulp::PodParser::ProhibitBadAproposMarkup->new
    (policy => $self);
  $parser->parse_from_elem ($elem);
  return $parser->violations;
}

package Perl::Critic::Pulp::PodParser::ProhibitBadAproposMarkup;
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 'head1') {
    $self->{'in_NAME'} = ($text =~ /^NAME\s*$/ ? 1 : 0);
  }
  ### in_NAME now: $self->{'in_NAME'}
  return '';
}

sub textblock {
  my ($self, $text, $linenum, $paraobj) = @_;
  ### textblock
  return $self->interpolate ($text, $linenum);
}

sub interior_sequence {
  my ($self, $command, $arg, $seq_obj) = @_;
  ### interior: $command
  ### $arg
  ### $seq_obj
  ### seq raw_text: $seq_obj->raw_text
  ### seq left_delimiter: $seq_obj->left_delimiter
  ### seq outer: do {my $outer=$seq_obj->nested; $outer&&$outer->cmd_name}

  if ($self->{'in_NAME'} && $command eq 'C') {
    my ($filename, $linenum) = $seq_obj->file_line;

    $self->violation_at_linenum
      ('C<> markup in NAME section is bad for "apropos".',
       $linenum);
  }
  return '';
}

1;
__END__