| 1 | #!perl | ||||||||||||||||||||||||||||||||||||||||||
| 2 | # PODNAME: RT::Client::REST::Forms | ||||||||||||||||||||||||||||||||||||||||||
| 3 | # ABSTRACT: This package provides functions from RT::Interface::REST, because we don't want to depend on rt being installed. Derived from rt 3.4.5. | ||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||
| 5 | 28 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 28 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | package RT::Client::REST::Forms; | ||||||||||||||||||||||||||||||||||||||||||
| 9 | 28 | $RT::Client::REST::Forms::VERSION = '0.73'; | |||||||||||||||||||||||||||||||||||||||||
| 10 | 28 | ▶ | use Exporter; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | 28 | ▶ | use vars qw(@EXPORT @ISA); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | 28 | @ISA = qw(Exporter); | |||||||||||||||||||||||||||||||||||||||||
| 15 | 28 | @EXPORT = qw(expand_list form_parse form_compose vpush vsplit); | |||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | 28 | my $CF_name = q%[#\s\w:()?/-]+%; | |||||||||||||||||||||||||||||||||||||||||
| 18 | 28 | my $field = qr/[a-z][\w-]*|C(?:ustom)?F(?:ield)?-$CF_name|CF\.\{$CF_name}/i; | |||||||||||||||||||||||||||||||||||||||||
| 19 | # always 9 https://rt-wiki.bestpractical.com/wiki/REST#Ticket_Attachments | ||||||||||||||||||||||||||||||||||||||||||
| 20 | 28 | my $spaces = ' ' x 9; | |||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | 0 | ▶ | sub expand_list { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
expand_list: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | 0 | my ($list) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 25 | 0 | my (@elts, %elts); | |||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||
| 27 | 0 | for my $elt (split /,/, $list) { | |||||||||||||||||||||||||||||||||||||||||
| 28 | 0 | ▶ | if ($elt =~ m/^(\d+)-(\d+)$/) { push @elts, ($1..$2) } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 29 | 0 | else { push @elts, $elt } | |||||||||||||||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||
| 32 | 0 | @elts{@elts}=(); | |||||||||||||||||||||||||||||||||||||||||
| 33 | 0 | my @return = sort {$a<=>$b} keys %elts; | |||||||||||||||||||||||||||||||||||||||||
| 34 | return @return | ||||||||||||||||||||||||||||||||||||||||||
| 35 | 0 | } | |||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||
| 38 | 9 | ▶ | sub form_parse { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
form_parse: called CC=29 SCAR=46.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 39 | 9 | my @lines = split /(?<=\n)/, shift; | |||||||||||||||||||||||||||||||||||||||||
| 40 | 9 | my $state = 0; | |||||||||||||||||||||||||||||||||||||||||
| 41 | 9 | my @forms = (); | |||||||||||||||||||||||||||||||||||||||||
| 42 | 9 | my ($c, $o, $k, $e) = ('', [], {}, ''); | |||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | LINE: | ||||||||||||||||||||||||||||||||||||||||||
| 45 | 9 | ▶ | while (@lines) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | 121 | my $line = shift @lines; | |||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||
| 48 | 121 | ▶ | next LINE if $line eq "\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||
| 50 | 119 | ▶ | if ($line eq "--\n") { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 51 | # We reached the end of one form. We'll ignore it if it was | ||||||||||||||||||||||||||||||||||||||||||
| 52 | # empty, and store it otherwise, errors and all. | ||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | ▶ | if ($e || $c || @$o) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$e or $c or @$o
$e or $c
MC/DC0%0/3
$e or $c or @$o
$e
$c
@$o
Truth table0%0/4
A or B or C
A= $eB= $cC= @$o
| |||||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | push @forms, [ $c, $o, $k, $e ]; | |||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | $c = ''; $o = []; $k = {}; $e = ''; | |||||||||||||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | $state = 0; | |||||||||||||||||||||||||||||||||||||||||
| 58 | next LINE | ||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | } | |||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||
| 61 | 119 | ▶ | if ($state != -1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||
| 63 | 119 | ▶ | if ($state == 0 && $line =~ m/^#/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$state == 0 and $line =~ /^#/
MC/DC0%0/2
$state == 0 and $line =~ /^#/
$state == 0
$line =~ /^#/
Truth table66%2/3
A and B
A= $state == 0B= $line =~ /^#/
| |||||||||||||||||||||||||||||||||||||||||||
| 64 | # Read an optional block of comments (only) at the start | ||||||||||||||||||||||||||||||||||||||||||
| 65 | # of the form. | ||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | $state = 1; | |||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | $c = $line; | |||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | ▶ | while (@lines && $lines[0] =~ m/^#/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
@lines and $lines[0] =~ /^#/
MC/DC0%0/2
@lines and $lines[0] =~ /^#/
@lines
$lines[0] =~ /^#/
Truth table0%0/3
A and B
A= @linesB= $lines[0] =~ /^#/
| |||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | $c .= shift @lines; | |||||||||||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||||||||||||
| 71 | next LINE | ||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | } | |||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||
| 74 | 119 | ▶ | if ($state <= 1 && $line =~ m/^($field:) ?$/s) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$state <= 1 and $line =~ /^($field:) ?$/s
MC/DC50%1/2
$state <= 1 and $line =~ /^($field:) ?$/s
$state <= 1
$line =~ /^($field:) ?$/s
Truth table66%2/3
A and B
A= $state <= 1B= $line =~ /^($field:) ?$/s
| |||||||||||||||||||||||||||||||||||||||||||
| 75 | # Empty field | ||||||||||||||||||||||||||||||||||||||||||
| 76 | 15 | my $f = $1; | |||||||||||||||||||||||||||||||||||||||||
| 77 | 15 | $f =~ s/:?$//; | |||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||
| 79 | 15 | ▶ | push(@$o, $f) unless exists $k->{$f}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 80 | 15 | vpush($k, $f, undef); | |||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||
| 82 | 15 | $state = 1; | |||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||
| 84 | next LINE | ||||||||||||||||||||||||||||||||||||||||||
| 85 | 15 | } | |||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||
| 87 | 104 | ▶ | if ($state <= 1 && $line =~ m/^($field:) (.*)?$/s) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$state <= 1 and $line =~ /^($field:) (.*)?$/s
MC/DC0%0/2
$state <= 1 and $line =~ /^($field:) (.*)?$/s
$state <= 1
$line =~ /^($field:) (.*)?$/s
Truth table33%1/3
A and B
A= $state <= 1B= $line =~ /^($field:) (.*)?$/s
| |||||||||||||||||||||||||||||||||||||||||||
| 88 | # Read a field: value specification. | ||||||||||||||||||||||||||||||||||||||||||
| 89 | 104 | my $f = $1; | |||||||||||||||||||||||||||||||||||||||||
| 90 | 104 | my $value = $2; | |||||||||||||||||||||||||||||||||||||||||
| 91 | 104 | $f =~ s/:?$//; | |||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||
| 93 | # Read continuation lines, if any. | ||||||||||||||||||||||||||||||||||||||||||
| 94 | 104 | ▶ | while (@lines && ($lines[0] eq "\n" || $lines[0] =~ m/^ +/)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
@lines and $lines[0] eq "\n" || $lines[0] =~ /^ +/
$lines[0] eq "\n" or $lines[0] =~ /^ +/
MC/DC100%3/3
@lines and $lines[0] eq "\n" || $lines[0] =~ /^ +/
@lines
$lines[0] eq "\n"
$lines[0] =~ /^ +/
Truth table100%4/4
A and B or C
A= @linesB= $lines[0] eq "\n"C= $lines[0] =~ /^ +/
| |||||||||||||||||||||||||||||||||||||||||||
| 95 | 216 | my $l = shift @lines; | |||||||||||||||||||||||||||||||||||||||||
| 96 | 216 | $l =~ s/^$spaces//; | |||||||||||||||||||||||||||||||||||||||||
| 97 | 216 | $value .= $l | |||||||||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||
| 100 | # `Content` is always supposed to be followed by three new lines | ||||||||||||||||||||||||||||||||||||||||||
| 101 | # ... but this doesnt behave as documented | ||||||||||||||||||||||||||||||||||||||||||
| 102 | # https://rt-wiki.bestpractical.com/wiki/REST#Ticket_Attachments | ||||||||||||||||||||||||||||||||||||||||||
| 103 | 104 | ▶ | if ($f eq 'Content') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 104 | 8 | $value =~ s/\n\n\n?$//g | |||||||||||||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||||||||||||
| 106 | # Chomp everything else | ||||||||||||||||||||||||||||||||||||||||||
| 107 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 108 | 96 | chomp $value | |||||||||||||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||
| 111 | 104 | ▶ | push(@$o, $f) unless exists $k->{$f}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 112 | 104 | vpush($k, $f, $value); | |||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||
| 114 | 104 | $state = 1; | |||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||
| 116 | next LINE | ||||||||||||||||||||||||||||||||||||||||||
| 117 | 104 | } | |||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | ▶ | if ($line !~ m/^#/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 120 | # We've found a syntax error, so we'll reconstruct the | ||||||||||||||||||||||||||||||||||||||||||
| 121 | # form parsed thus far, and add an error marker. (>>) | ||||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | $state = -1; | |||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | $e = form_compose([[ '', $o, $k, '' ]]); | |||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | ▶ | $e.= $line =~ m/^>>/ ? "$line\n" : ">> $line\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 125 | next LINE | ||||||||||||||||||||||||||||||||||||||||||
| 126 | 0 | } | |||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||
| 128 | # line will be ignored | ||||||||||||||||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||||||||||||||
| 130 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 131 | # We saw a syntax error earlier, so we'll accumulate the | ||||||||||||||||||||||||||||||||||||||||||
| 132 | # contents of this form until the end. | ||||||||||||||||||||||||||||||||||||||||||
| 133 | 0 | $e .= "$line\n"; | |||||||||||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||||||||||||
| 136 | 9 | ▶ | push(@forms, [ $c, $o, $k, $e ]) if ($e || $c || @$o); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$e or $c or @$o
$e or $c
MC/DC0%0/3
$e or $c or @$o
$e
$c
@$o
Truth table25%1/4
A or B or C
A= $eB= $cC= @$o
| |||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||
| 138 | 9 | for my $l (keys %$k) { | |||||||||||||||||||||||||||||||||||||||||
| 139 | 119 | ▶ | $k->{$l} = vsplit($k->{$l}) if (ref $k->{$l} eq 'ARRAY'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||
| 142 | 9 | return \@forms; | |||||||||||||||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||
| 146 | 6 | ▶ | sub form_compose { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
form_compose: called CC=21 SCAR=45.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 147 | 6 | my ($forms) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 148 | 6 | my @text; | |||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||
| 150 | 6 | for my $form (@$forms) { | |||||||||||||||||||||||||||||||||||||||||
| 151 | 6 | my ($c, $o, $k, $e) = @$form; | |||||||||||||||||||||||||||||||||||||||||
| 152 | 6 | my $text = ''; | |||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||
| 154 | 6 | ▶ | if ($c) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 155 | 0 | $c =~ s/\n*$/\n/; | |||||||||||||||||||||||||||||||||||||||||
| 156 | 0 | $text = "$c\n"; | |||||||||||||||||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||||||||||||||||
| 158 | 6 | ▶ | if ($e) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 159 | 0 | $text .= $e; | |||||||||||||||||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||||||||||||||||
| 161 | elsif ($o) { | ||||||||||||||||||||||||||||||||||||||||||
| 162 | 6 | my @lines; | |||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||
| 164 | 6 | for my $key (@$o) { | |||||||||||||||||||||||||||||||||||||||||
| 165 | 10 | my ($line, $sp); | |||||||||||||||||||||||||||||||||||||||||
| 166 | my @values = (ref $k->{$key} eq 'ARRAY') ? | ||||||||||||||||||||||||||||||||||||||||||
| 167 | 0 | @{ $k->{$key} } : | |||||||||||||||||||||||||||||||||||||||||
| 168 | 10 | ▶ | $k->{$key}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||
| 170 | 10 | $sp = " "x(length("$key: ")); | |||||||||||||||||||||||||||||||||||||||||
| 171 | 10 | ▶ | $sp = " "x4 if length($sp) > 16; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||||
| 173 | 10 | for my $v (@values) { | |||||||||||||||||||||||||||||||||||||||||
| 174 | 10 | ▶ | if ($v =~ /\n/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 175 | 0 | $v =~ s/^/$sp/gm; | |||||||||||||||||||||||||||||||||||||||||
| 176 | 0 | $v =~ s/^$sp//; | |||||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||||||
| 178 | 0 | ▶ | if ($line) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 179 | 0 | push @lines, "$line\n\n"; | |||||||||||||||||||||||||||||||||||||||||
| 180 | 0 | $line = ''; | |||||||||||||||||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||||||||||||||||
| 182 | ▶ | elsif (@lines && $lines[-1] !~ m/\n\n$/) { | |||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
@lines and not $lines[-1] =~ /\n\n$/
MC/DC0%0/2
@lines and not $lines[-1] =~ /\n\n$/
@lines
not $lines[-1] =~ /\n\n$/
Truth table0%0/3
A and not(B)
A= @linesB= not $lines[-1] =~ /\n\n$/
| |||||||||||||||||||||||||||||||||||||||||||
| 183 | 0 | $lines[-1] .= "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||||||||||||||||
| 185 | 0 | push @lines, "$key: $v\n\n"; | |||||||||||||||||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||||||||||||||||
| 187 | ▶ | elsif ($line && | |||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$line and length($line) + length($v) - rindex($line, "\n") >= 70
MC/DC0%0/2
$line and length($line) + length($v) - rindex($line, "\n") >= 70
$line
length($line) + length($v) - rindex($line, "\n") >= 70
Truth table33%1/3
A and B
A= $lineB= length($line) + length($v) - rindex($line, "\n") >= 70
| |||||||||||||||||||||||||||||||||||||||||||
| 188 | length($line)+length($v)-rindex($line, "\n") >= 70) | ||||||||||||||||||||||||||||||||||||||||||
| 189 | { | ||||||||||||||||||||||||||||||||||||||||||
| 190 | 0 | $line .= ",\n$sp$v"; | |||||||||||||||||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||||||||||||||||
| 192 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 193 | 10 | ▶ | $line = $line ? "$line, $v" : "$key: $v"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||||||||
| 197 | 10 | ▶ | $line = "$key:" unless @values; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 198 | 10 | ▶ | if ($line) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 199 | 10 | ▶ | if ($line =~ m/\n/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 200 | 0 | ▶ | if (@lines && $lines[-1] !~ m/\n\n$/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
@lines and not $lines[-1] =~ /\n\n$/
MC/DC0%0/2
@lines and not $lines[-1] =~ /\n\n$/
@lines
not $lines[-1] =~ /\n\n$/
Truth table0%0/3
A and not(B)
A= @linesB= not $lines[-1] =~ /\n\n$/
| |||||||||||||||||||||||||||||||||||||||||||
| 201 | 0 | $lines[-1] .= "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||||||||||||||||
| 203 | 0 | $line .= "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||||||||||||||||
| 205 | 10 | push @lines, "$line\n"; | |||||||||||||||||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||||||
| 209 | 6 | $text .= join '', @lines; | |||||||||||||||||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||||||||||||||||
| 211 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 212 | 0 | chomp $text; | |||||||||||||||||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||||||||||||||||
| 214 | 6 | push @text, $text; | |||||||||||||||||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||||||
| 217 | 6 | return join "\n--\n\n", @text; | |||||||||||||||||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||||||||
| 221 | 119 | ▶ | sub vpush { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
vpush: called CC=5 SCAR=24.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 222 | 119 | my ($hash, $key, $val) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 223 | 119 | ▶ | my @val = ref $val eq 'ARRAY' ? @$val : $val; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||||||||||||||
| 225 | 119 | ▶ | if (exists $hash->{$key}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 226 | 0 | ▶ | unless (ref $hash->{$key} eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 227 | 0 | ▶ | my @v = $hash->{$key} ne '' ? $hash->{$key} : (); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 228 | 0 | $hash->{$key} = \@v; | |||||||||||||||||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||||||||||||||||
| 230 | 0 | push @{ $hash->{$key} }, @val; | |||||||||||||||||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||||||||||||||||
| 232 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 233 | 119 | $hash->{$key} = $val; | |||||||||||||||||||||||||||||||||||||||||
| 234 | } | ||||||||||||||||||||||||||||||||||||||||||
| 235 | } | ||||||||||||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||||||||||
| 238 | 0 | ▶ | sub vsplit { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
vsplit: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 239 | 0 | my ($val) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 240 | 0 | my (@words); | |||||||||||||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||||||||||||||
| 242 | 0 | ▶ | for my $line (map {split /\n/} (ref $val eq 'ARRAY') ? @$val : $val) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 243 | { | ||||||||||||||||||||||||||||||||||||||||||
| 244 | # XXX: This should become a real parser, à la Text::ParseWords. | ||||||||||||||||||||||||||||||||||||||||||
| 245 | 0 | $line =~ s/^\s+//; | |||||||||||||||||||||||||||||||||||||||||
| 246 | 0 | $line =~ s/\s+$//; | |||||||||||||||||||||||||||||||||||||||||
| 247 | 0 | push @words, split /\s*,\s*/, $line; | |||||||||||||||||||||||||||||||||||||||||
| 248 | } | ||||||||||||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||||||||||
| 250 | 0 | return \@words; | |||||||||||||||||||||||||||||||||||||||||
| 251 | } | ||||||||||||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||||||||||||
| 253 | __END__ | ||||||||||||||||||||||||||||||||||||||||||