| 1 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 2 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use utf8; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | package Pod::Weaver::Plugin::EnsureUniqueSections; | ||||||||||||||||||||||||||||
| 6 | 2 | $Pod::Weaver::Plugin::EnsureUniqueSections::VERSION = '0.163250'; | |||||||||||||||||||||||||||
| 7 | 2 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use MooseX::Has::Sugar; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use Moose::Autobox 0.10; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use Text::Trim; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 2 | ▶ | use Lingua::EN::Inflect::Number qw(to_S); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 2 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 2 | with 'Pod::Weaver::Role::Finalizer'; | |||||||||||||||||||||||||||
| 15 | 2 | with 'Pod::Weaver::Role::Preparer'; | |||||||||||||||||||||||||||
| 16 | # ABSTRACT: Ensure that POD has no duplicate section headers. | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | has strict => ( | ||||||||||||||||||||||||||||
| 20 | ro, lazy, | ||||||||||||||||||||||||||||
| 21 | isa => 'Bool', | ||||||||||||||||||||||||||||
| 22 | 1 | ▶ | default => sub { 0 }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 23 | 2 | ); | |||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 40 | ▶ | sub _header_key { | ||||||||||||||||||||||||||
|
Subroutine
_header_key: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 26 | 40 | my ($self, $text) = @_; | |||||||||||||||||||||||||||
| 27 | 40 | ▶ | if (!$self->strict) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 28 | # Replace all non-words with a single space | ||||||||||||||||||||||||||||
| 29 | 36 | $text =~ s{\W+}{ }xsmg; | |||||||||||||||||||||||||||
| 30 | # Trim leading and trailing whitespace | ||||||||||||||||||||||||||||
| 31 | 36 | $text = trim $text; | |||||||||||||||||||||||||||
| 32 | # All to uppercase | ||||||||||||||||||||||||||||
| 33 | 36 | $text = uc $text; | |||||||||||||||||||||||||||
| 34 | # Reorder "AND" lists and singularize nouns | ||||||||||||||||||||||||||||
| 35 | $text = $text | ||||||||||||||||||||||||||||
| 36 | ->split(qr{ AND }i) | ||||||||||||||||||||||||||||
| 37 | 43 | ▶ | ->map(sub { m{\W} ? $_ : to_S $_; }) | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 38 | 36 | ->sort->join(' AND '); | |||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||
| 40 | 40 | return $text; | |||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 6 | ▶ | sub prepare_input { | ||||||||||||||||||||||||||
|
Subroutine
prepare_input: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 45 | 6 | my $self = shift; | |||||||||||||||||||||||||||
| 46 | # Put EnsureUniqueSections plugins at the end | ||||||||||||||||||||||||||||
| 47 | 6 | my $plugins = $self->weaver->plugins; | |||||||||||||||||||||||||||
| 48 | 6 | @$plugins = ((grep { $_ != $self } @$plugins), $self); | |||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 6 | ▶ | sub finalize_document { | ||||||||||||||||||||||||||
|
Subroutine
finalize_document: called CC=5 SCAR=16.2
Pod
documented
| |||||||||||||||||||||||||||||
| 53 | 6 | my ($self, $document) = @_; | |||||||||||||||||||||||||||
| 54 | my $headers = $document->children | ||||||||||||||||||||||||||||
| 55 | 40 | ▶ | ->grep(sub{ $_->can( 'command' ) and $_->command eq 'head1' }) | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 56 | 6 | ▶ | ->map(sub{ $_->content }); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 57 | 6 | my %header_group; | |||||||||||||||||||||||||||
| 58 | 6 | for my $h (@$headers) { | |||||||||||||||||||||||||||
| 59 | 40 | push @{$header_group{$self->_header_key($h)}}, $h; | |||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | my $duplicate_headers = [ keys %header_group ] | ||||||||||||||||||||||||||||
| 63 | 36 | ▶ | ->map(sub{ @{$header_group{$_}} > 1 ? $header_group{$_}->head : () }) | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 64 | 6 | ->sort; | |||||||||||||||||||||||||||
| 65 | 6 | ▶ | if (@$duplicate_headers > 0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 66 | 4 | my $pod_string = ""; | |||||||||||||||||||||||||||
| 67 | 4 | for my $h (@$duplicate_headers) { | |||||||||||||||||||||||||||
| 68 | 4 | for my $node (@{ $document->children->grep( | |||||||||||||||||||||||||||
| 69 | 30 | ▶ | sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=14.2
| |||||||||||||||||||||||||||||
| 70 | 30 | ▶ | $_->can('command') && $_->command eq 'head1' && | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$_->can("command") and $_->command eq "head1"
MC/DC0%0/2
$_->can("command") and $_->command eq "head1"
$_->can("command")
$_->command eq "head1"
Truth table33%1/3
A and B
A= $_->can("command")B= $_->command eq "head1"
| |||||||||||||||||||||||||||||
| 71 | $_->content eq $h | ||||||||||||||||||||||||||||
| 72 | 4 | }) }) { | |||||||||||||||||||||||||||
| 73 | 7 | $pod_string .= $node->as_pod_string; | |||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | 4 | $self->log_debug(["POD of duplicated headers:\n\n%s", $pod_string]); | |||||||||||||||||||||||||||
| 77 | 4 | my $message = "Error: The following headers appear multiple times: '" . $duplicate_headers->join(q{', '}) . q{'}; | |||||||||||||||||||||||||||
| 78 | 4 | $self->log_fatal($message); | |||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 2 | 1; # Magic true value required at end of module | |||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | __END__ | ||||||||||||||||||||||||||||