| 1 | package MooseX::App::Utils; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 17 | ▶ | use 5.010; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 17 | ▶ | use utf8; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 17 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 17 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | 17 | ▶ | use List::Util qw(max); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 17 | our $SCREEN_WIDTH = 78; | |||||||||||||||||||||||||||||||||||||||||
| 11 | 17 | our $INDENT = 4; | |||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | 17 | ▶ | use Moose::Util::TypeConstraints; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | 17 | subtype 'MooseX::App::Types::List' | |||||||||||||||||||||||||||||||||||||||||
| 16 | => as 'ArrayRef'; | ||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | coerce 'MooseX::App::Types::List' | ||||||||||||||||||||||||||||||||||||||||||
| 19 | => from 'Str' | ||||||||||||||||||||||||||||||||||||||||||
| 20 | 0 | ▶ | => via { [$_] }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | 17 | subtype 'MooseX::App::Types::CmdTypes' | |||||||||||||||||||||||||||||||||||||||||
| 23 | => as enum([qw(proto option parameter)]); | ||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||
| 25 | 17 | subtype 'MooseX::App::Types::MessageString' | |||||||||||||||||||||||||||||||||||||||||
| 26 | => as 'Str'; | ||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | coerce 'MooseX::App::Types::MessageString' | ||||||||||||||||||||||||||||||||||||||||||
| 29 | => from 'ArrayRef' | ||||||||||||||||||||||||||||||||||||||||||
| 30 | 0 | ▶ | => via { sprintf(@{$_}) }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=2.6
| |||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||
| 32 | subtype 'MooseX::App::Types::Env' | ||||||||||||||||||||||||||||||||||||||||||
| 33 | => as 'Str' | ||||||||||||||||||||||||||||||||||||||||||
| 34 | 13 | ▶ | => where { m/^[A-Z0-9_]+$/ }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||
| 36 | subtype 'MooseX::App::Types::Identifier' | ||||||||||||||||||||||||||||||||||||||||||
| 37 | => as 'Str' | ||||||||||||||||||||||||||||||||||||||||||
| 38 | 273 | ▶ | => where { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=12.0
| |||||||||||||||||||||||||||||||||||||||||||
| 39 | 273 | ▶ | $_ eq '?' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
$_ eq '?' || /^[A-Za-z0-9][A-Za-z0-9_-]*$/ && /[^-_]$/
/^[A-Za-z0-9][A-Za-z0-9_-]*$/ and /[^-_]$/
MC/DC0%0/3
$_ eq '?' || /^[A-Za-z0-9][A-Za-z0-9_-]*$/ && /[^-_]$/
$_ eq '?'
/^[A-Za-z0-9][A-Za-z0-9_-]*$/
/[^-_]$/
Truth table50%2/4
A || B and C
A= $_ eq '?'B= /^[A-Za-z0-9][A-Za-z0-9_-]*$/C= /[^-_]$/
| |||||||||||||||||||||||||||||||||||||||||||
| 40 | 17 | || (m/^[A-Za-z0-9][A-Za-z0-9_-]*$/ && m/[^-_]$/) }; | |||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | 17 | subtype 'MooseX::App::Types::IdentifierList' | |||||||||||||||||||||||||||||||||||||||||
| 43 | => as 'ArrayRef[MooseX::App::Types::Identifier]'; | ||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||
| 45 | coerce 'MooseX::App::Types::IdentifierList' | ||||||||||||||||||||||||||||||||||||||||||
| 46 | => from 'MooseX::App::Types::Identifier' | ||||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | ▶ | => via { [$_] }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||
| 49 | 17 | ▶ | no Moose::Util::TypeConstraints; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||
| 51 | # Default package name to command name translation function | ||||||||||||||||||||||||||||||||||||||||||
| 52 | 30 | ▶ | sub class_to_command { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
class_to_command: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 53 | 30 | my ($class) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||
| 55 | return | ||||||||||||||||||||||||||||||||||||||||||
| 56 | 30 | ▶ | unless defined $class; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||
| 58 | 30 | my @commands; | |||||||||||||||||||||||||||||||||||||||||
| 59 | 30 | foreach my $part (split /\s+/,$class) { | |||||||||||||||||||||||||||||||||||||||||
| 60 | 32 | my @parts = split( /_+|\b|(?<![A-Z])(?=[A-Z])|(?<=[A-Z])(?=[A-Z][a-z])/, $part ); | |||||||||||||||||||||||||||||||||||||||||
| 61 | 32 | push (@commands,join('_',@parts)); | |||||||||||||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||||||||||||
| 63 | 30 | return lc(join(" ",@commands)); | |||||||||||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||
| 66 | # Format output text for fixed screen width | ||||||||||||||||||||||||||||||||||||||||||
| 67 | 54 | ▶ | sub format_text { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
format_text: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 68 | 54 | my ($text) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||
| 70 | 54 | my @lines; | |||||||||||||||||||||||||||||||||||||||||
| 71 | 54 | foreach my $line (split(/\n/,$text)) { | |||||||||||||||||||||||||||||||||||||||||
| 72 | 162 | push(@lines,split_string($SCREEN_WIDTH-$INDENT,$line)); | |||||||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||
| 75 | return join( | ||||||||||||||||||||||||||||||||||||||||||
| 76 | "\n", | ||||||||||||||||||||||||||||||||||||||||||
| 77 | 54 | map { (' ' x $INDENT).$_ } | |||||||||||||||||||||||||||||||||||||||||
| 78 | @lines | ||||||||||||||||||||||||||||||||||||||||||
| 79 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||
| 82 | # Format bullet list for fixed screen width | ||||||||||||||||||||||||||||||||||||||||||
| 83 | 79 | ▶ | sub format_list { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
format_list: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 84 | 79 | my (@list) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||
| 86 | 79 | my $max_length = max(map { length($_->[0]) } @list); | |||||||||||||||||||||||||||||||||||||||||
| 87 | 79 | my $description_length = $SCREEN_WIDTH - $max_length - 7; | |||||||||||||||||||||||||||||||||||||||||
| 88 | 79 | my $prefix_length = $max_length + $INDENT + 2; | |||||||||||||||||||||||||||||||||||||||||
| 89 | 79 | my @return; | |||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||
| 91 | # Loop all items | ||||||||||||||||||||||||||||||||||||||||||
| 92 | 79 | foreach my $command (@list) { | |||||||||||||||||||||||||||||||||||||||||
| 93 | 258 | ▶ | my $description = $command->[1] // ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$command->[1] // ""
MC/DC100%1/1
$command->[1] // ""
$command->[1]
Truth table100%2/2
A
A= $command->[1]
| |||||||||||||||||||||||||||||||||||||||||||
| 94 | 258 | my @lines = split_string($description_length,$description); | |||||||||||||||||||||||||||||||||||||||||
| 95 | 258 | push (@return,(' 'x$INDENT).sprintf('%-*s %s',$max_length,$command->[0],shift(@lines))); | |||||||||||||||||||||||||||||||||||||||||
| 96 | 258 | ▶ | while (my $line = shift (@lines)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 97 | 16 | push(@return,' 'x $prefix_length.$line); | |||||||||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||||||||
| 100 | 79 | return join("\n",@return); | |||||||||||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||
| 103 | # Simple splitting of long sentences on whitespaces or punctuation | ||||||||||||||||||||||||||||||||||||||||||
| 104 | 420 | ▶ | sub split_string { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
split_string: called CC=11 SCAR=24.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 105 | 420 | my ($maxlength, $string) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||
| 107 | return | ||||||||||||||||||||||||||||||||||||||||||
| 108 | 420 | ▶ | unless defined $string; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||
| 110 | 420 | ▶ | return $string | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 111 | if length $string <= $maxlength; | ||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||
| 113 | 28 | my (@lines,$line); | |||||||||||||||||||||||||||||||||||||||||
| 114 | 28 | $line = ''; | |||||||||||||||||||||||||||||||||||||||||
| 115 | 28 | foreach my $word (split(m/(\p{IsPunct}|\p{IsSpace})/,$string)) { | |||||||||||||||||||||||||||||||||||||||||
| 116 | 864 | ▶ | if (length($line.$word) <= $maxlength) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 117 | 835 | $line .= $word; | |||||||||||||||||||||||||||||||||||||||||
| 118 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 119 | 29 | ▶ | push(@lines,$line) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 120 | if ($line ne ''); | ||||||||||||||||||||||||||||||||||||||||||
| 121 | 29 | $line = ''; | |||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||
| 123 | 29 | ▶ | if (length($word) > $maxlength) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 124 | 7 | my (@parts) = grep { $_ ne '' } split(/(.{$maxlength})/,$word); | |||||||||||||||||||||||||||||||||||||||||
| 125 | 7 | my $lastline = pop(@parts); | |||||||||||||||||||||||||||||||||||||||||
| 126 | 7 | push(@lines,@parts); | |||||||||||||||||||||||||||||||||||||||||
| 127 | 7 | ▶ | if (defined $lastline && $lastline ne '') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $lastline and $lastline ne ""
MC/DC0%0/2
defined $lastline and $lastline ne ""
defined $lastline
$lastline ne ""
Truth table33%1/3
A and B
A= defined $lastlineB= $lastline ne ""
| |||||||||||||||||||||||||||||||||||||||||||
| 128 | 7 | $line = $lastline; | |||||||||||||||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||||||||||||||
| 130 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 131 | 22 | $line = $word; | |||||||||||||||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||||||||||||
| 135 | 28 | ▶ | push(@lines,$line) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 136 | if ($line ne ''); | ||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||
| 138 | 28 | ▶ | @lines = map { m/^\s*(.+?)\s*$/ ? $1 : $_ } @lines; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||
| 140 | 28 | return @lines; | |||||||||||||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||
| 143 | # Try to get filename for a given package name | ||||||||||||||||||||||||||||||||||||||||||
| 144 | 24 | ▶ | sub package_to_filename { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
package_to_filename: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 145 | 24 | my ($package) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||
| 147 | # Package to filename | ||||||||||||||||||||||||||||||||||||||||||
| 148 | 24 | my $package_filename = $package; | |||||||||||||||||||||||||||||||||||||||||
| 149 | 24 | $package_filename =~ s/::/\//g; | |||||||||||||||||||||||||||||||||||||||||
| 150 | 24 | $package_filename .= '.pm'; | |||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||
| 153 | 24 | my $package_filepath; | |||||||||||||||||||||||||||||||||||||||||
| 154 | 24 | ▶ | if (defined $INC{$package_filename}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 155 | 24 | $package_filepath = $INC{$package_filename}; | |||||||||||||||||||||||||||||||||||||||||
| 156 | 24 | $package_filepath =~ s/\/{2,}/\//g; | |||||||||||||||||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||
| 159 | # No filename available | ||||||||||||||||||||||||||||||||||||||||||
| 160 | return | ||||||||||||||||||||||||||||||||||||||||||
| 161 | 24 | ▶ | unless defined $package_filepath | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $package_filepath and -e $package_filepath
MC/DC50%1/2
defined $package_filepath and -e $package_filepath
defined $package_filepath
-e $package_filepath
Truth table66%2/3
A and B
A= defined $package_filepathB= -e $package_filepath
| |||||||||||||||||||||||||||||||||||||||||||
| 162 | && -e $package_filepath; | ||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||
| 164 | 20 | return $package_filepath; | |||||||||||||||||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||
| 167 | # Parse pod | ||||||||||||||||||||||||||||||||||||||||||
| 168 | 24 | ▶ | sub parse_pod { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_pod: called CC=11 SCAR=24.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 169 | 24 | my ($package) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||||||
| 171 | 24 | my $package_filepath = package_to_filename($package); | |||||||||||||||||||||||||||||||||||||||||
| 172 | return | ||||||||||||||||||||||||||||||||||||||||||
| 173 | 24 | ▶ | unless $package_filepath; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||||||||
| 175 | # Parse pod | ||||||||||||||||||||||||||||||||||||||||||
| 176 | 20 | my $document = Pod::Elemental->read_file($package_filepath); | |||||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||||||
| 178 | 20 | Pod::Elemental::Transformer::Pod5->new->transform_node($document); | |||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||
| 180 | 20 | my $nester_head = Pod::Elemental::Transformer::Nester->new({ | |||||||||||||||||||||||||||||||||||||||||
| 181 | top_selector => Pod::Elemental::Selectors::s_command('head1'), | ||||||||||||||||||||||||||||||||||||||||||
| 182 | content_selectors => [ | ||||||||||||||||||||||||||||||||||||||||||
| 183 | Pod::Elemental::Selectors::s_command([ qw(head2 head3 head4 over back item) ]), | ||||||||||||||||||||||||||||||||||||||||||
| 184 | Pod::Elemental::Selectors::s_flat() | ||||||||||||||||||||||||||||||||||||||||||
| 185 | ], | ||||||||||||||||||||||||||||||||||||||||||
| 186 | }); | ||||||||||||||||||||||||||||||||||||||||||
| 187 | 20 | $document = $nester_head->transform_node($document); | |||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||
| 189 | # Process pod | ||||||||||||||||||||||||||||||||||||||||||
| 190 | 20 | my %pod; | |||||||||||||||||||||||||||||||||||||||||
| 191 | 20 | foreach my $element (@{$document->children}) { | |||||||||||||||||||||||||||||||||||||||||
| 192 | # Distzilla ABSTRACT tag | ||||||||||||||||||||||||||||||||||||||||||
| 193 | 35 | ▶ | if ($element->isa('Pod::Elemental::Element::Pod5::Nonpod')) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 194 | 20 | ▶ | if ($element->content =~ m/^\s*#+\s*ABSTRACT:\s*(.+)$/m) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 195 | 1 | ▶ | $pod{ABSTRACT} ||= $1; | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$pod{"ABSTRACT"} ||= $1
MC/DC0%0/2
$pod{"ABSTRACT"} ||= $1
$pod{"ABSTRACT"}
$1
Truth table33%1/3
A ||= B
A= $pod{"ABSTRACT"}B= $1
| |||||||||||||||||||||||||||||||||||||||||||
| 196 | } | ||||||||||||||||||||||||||||||||||||||||||
| 197 | # Pod head1 sections | ||||||||||||||||||||||||||||||||||||||||||
| 198 | ▶ | } elsif ($element->isa('Pod::Elemental::Element::Nested') | |||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$element->isa("Pod::Elemental::Element::Nested") and $element->command eq "head1"
MC/DC50%1/2
$element->isa("Pod::Elemental::Element::Nested") and $element->command eq "head1"
$element->isa("Pod::Elemental::Element::Nested")
$element->command eq "head1"
Truth table66%2/3
A and B
A= $element->isa("Pod::Elemental::Element::Nested")B= $element->command eq "head1"
| |||||||||||||||||||||||||||||||||||||||||||
| 199 | && $element->command eq 'head1') { | ||||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||
| 201 | 13 | ▶ | if ($element->content eq 'NAME') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 202 | 2 | my $content = _pod_node_to_text($element->children); | |||||||||||||||||||||||||||||||||||||||||
| 203 | 2 | ▶ | next unless defined $content; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 204 | 2 | $content =~ s/^$package(\s-)?\s//; | |||||||||||||||||||||||||||||||||||||||||
| 205 | 2 | chomp($content); | |||||||||||||||||||||||||||||||||||||||||
| 206 | 2 | $pod{NAME} = $content; | |||||||||||||||||||||||||||||||||||||||||
| 207 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 208 | 11 | my $content = _pod_node_to_text($element->children); | |||||||||||||||||||||||||||||||||||||||||
| 209 | 11 | ▶ | next unless defined $content; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 210 | 11 | chomp($content); | |||||||||||||||||||||||||||||||||||||||||
| 211 | 11 | $pod{uc($element->content)} = $content; | |||||||||||||||||||||||||||||||||||||||||
| 212 | } | ||||||||||||||||||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||||||||||||||||
| 214 | } | ||||||||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||||||||
| 216 | 20 | return %pod; | |||||||||||||||||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||||||||||
| 219 | # Transform POD to simple markup | ||||||||||||||||||||||||||||||||||||||||||
| 220 | 61 | ▶ | sub _pod_node_to_text { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_pod_node_to_text: called CC=13 SCAR=25.7
| |||||||||||||||||||||||||||||||||||||||||||
| 221 | 61 | my ($node,$indent) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||||||||||||
| 223 | 61 | ▶ | unless (defined $indent) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 224 | 13 | my $indent_init = 0; | |||||||||||||||||||||||||||||||||||||||||
| 225 | 13 | $indent = \$indent_init; | |||||||||||||||||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||||||||||
| 228 | 61 | my (@lines); | |||||||||||||||||||||||||||||||||||||||||
| 229 | 61 | ▶ | if (ref $node eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 230 | 13 | foreach my $element (@$node) { | |||||||||||||||||||||||||||||||||||||||||
| 231 | 48 | push (@lines,_pod_node_to_text($element,$indent)); | |||||||||||||||||||||||||||||||||||||||||
| 232 | } | ||||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||||
| 234 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 235 | 48 | my $class = ref($node); | |||||||||||||||||||||||||||||||||||||||||
| 236 | 48 | ▶ | if ($class eq 'Pod::Elemental::Element::Pod5::Ordinary') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 237 | 23 | my $content = $node->content; | |||||||||||||||||||||||||||||||||||||||||
| 238 | return | ||||||||||||||||||||||||||||||||||||||||||
| 239 | 23 | ▶ | if $content =~ m/^=cut/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 240 | 21 | $content =~ s/\n/ /g; | |||||||||||||||||||||||||||||||||||||||||
| 241 | 21 | $content =~ s/\s+/ /g; | |||||||||||||||||||||||||||||||||||||||||
| 242 | 21 | push (@lines,$content."\n"); | |||||||||||||||||||||||||||||||||||||||||
| 243 | } | ||||||||||||||||||||||||||||||||||||||||||
| 244 | elsif ($class eq 'Pod::Elemental::Element::Pod5::Verbatim') { | ||||||||||||||||||||||||||||||||||||||||||
| 245 | 2 | push (@lines,$node->content."\n"); | |||||||||||||||||||||||||||||||||||||||||
| 246 | } | ||||||||||||||||||||||||||||||||||||||||||
| 247 | elsif ($class eq 'Pod::Elemental::Element::Pod5::Command') { | ||||||||||||||||||||||||||||||||||||||||||
| 248 | 20 | my $command = $node->command; | |||||||||||||||||||||||||||||||||||||||||
| 249 | 20 | ▶ | if ($command eq 'over') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 250 | 4 | ${$indent}++; | |||||||||||||||||||||||||||||||||||||||||
| 251 | } | ||||||||||||||||||||||||||||||||||||||||||
| 252 | elsif ($command eq 'item') { | ||||||||||||||||||||||||||||||||||||||||||
| 253 | 8 | push (@lines,(' ' x ($$indent-1)) . $node->content); | |||||||||||||||||||||||||||||||||||||||||
| 254 | } | ||||||||||||||||||||||||||||||||||||||||||
| 255 | elsif ($command eq 'back') { | ||||||||||||||||||||||||||||||||||||||||||
| 256 | 4 | push (@lines,"\n"); | |||||||||||||||||||||||||||||||||||||||||
| 257 | 4 | ${$indent}--; | |||||||||||||||||||||||||||||||||||||||||
| 258 | } | ||||||||||||||||||||||||||||||||||||||||||
| 259 | elsif ($command =~ qr/head\d/) { | ||||||||||||||||||||||||||||||||||||||||||
| 260 | 4 | push (@lines,"\n",$node->content,"\n"); | |||||||||||||||||||||||||||||||||||||||||
| 261 | } | ||||||||||||||||||||||||||||||||||||||||||
| 262 | } | ||||||||||||||||||||||||||||||||||||||||||
| 263 | } | ||||||||||||||||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||||||||||||||||
| 265 | return | ||||||||||||||||||||||||||||||||||||||||||
| 266 | 59 | ▶ | unless scalar @lines; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||||||||||||
| 268 | # Convert text markup | ||||||||||||||||||||||||||||||||||||||||||
| 269 | 52 | my $return = join ("\n", grep { defined $_ } @lines); | |||||||||||||||||||||||||||||||||||||||||
| 270 | 52 | $return =~ s/\n\n\n+/\n\n/g; # Max one empty line | |||||||||||||||||||||||||||||||||||||||||
| 271 | 52 | $return =~ s/I<([^>]+)>/_$1_/g; | |||||||||||||||||||||||||||||||||||||||||
| 272 | 52 | $return =~ s/B<([^>]+)>/*$1*/g; | |||||||||||||||||||||||||||||||||||||||||
| 273 | 52 | $return =~ s/[LCBI]<([^>]+)>/$1/g; | |||||||||||||||||||||||||||||||||||||||||
| 274 | 52 | $return =~ s/[LCBI]<([^>]+)>/$1/g; | |||||||||||||||||||||||||||||||||||||||||
| 275 | 52 | return $return; | |||||||||||||||||||||||||||||||||||||||||
| 276 | } | ||||||||||||||||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||||||||||||
| 279 | 17 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||||||||||||
| 281 | =pod | ||||||||||||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||||||||||||
| 283 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||||||||||||||||
| 285 | MooseX::App::Utils - Utility functions | ||||||||||||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||||||||||||
| 287 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||||||||||||||||
| 289 | This package holds various utility functions used by MooseX-App internally. | ||||||||||||||||||||||||||||||||||||||||||
| 290 | Unless you develop plugins you will not need to interact with this class. | ||||||||||||||||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||||||||||||||||
| 292 | =head1 FUNCTIONS | ||||||||||||||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||||||||||||
| 294 | =head2 class_to_command | ||||||||||||||||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||||||||||||||||
| 296 | =head2 package_to_filename | ||||||||||||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||||||||||||
| 298 | Tries to determine the filename containing the given package name. | ||||||||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||||||||
| 300 | =head2 format_list | ||||||||||||||||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||||||||||||||||
| 302 | =head2 format_text | ||||||||||||||||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||||||||||||||||
| 304 | =head2 parse_pod | ||||||||||||||||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||||||||||||||||
| 306 | =head2 split_string | ||||||||||||||||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||||||||||||||||
| 310 | =head1 GLOBALS | ||||||||||||||||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||||||||||||||||
| 312 | =head2 $MooseX::App::Utils::SCREEN_WIDTH | ||||||||||||||||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||||||||||||||||
| 314 | Screen width for printing help and error messages | ||||||||||||||||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||||||||||||||||
| 316 | =head2 $MooseX::App::Utils::INDENT | ||||||||||||||||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||||||||||||||||
| 318 | Indent for printing help and error messages | ||||||||||||||||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||||||||||||||||
| 320 | =cut | ||||||||||||||||||||||||||||||||||||||||||