| 1 | package File::ANVL; | ||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||
| 3 | # XXXXXxxxx make adding a value policy-driven, eg, | ||||||||||||||||||||||||||||||||||||||||||||||
| 4 | # "add" could mean (a) replace, (b) push on end array, | ||||||||||||||||||||||||||||||||||||||||||||||
| 5 | # (c) push on start of array, (d) string concatenation, | ||||||||||||||||||||||||||||||||||||||||||||||
| 6 | # (d) error. | ||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 57 | ▶ | use 5.006; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 57 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 57 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 57 | ▶ | use constant NL => "\n"; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||
| 14 | # ANVL flavors | ||||||||||||||||||||||||||||||||||||||||||||||
| 15 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 57 | ▶ | use constant ANVL => 1; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 57 | ▶ | use constant ANVLR => 2; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 57 | ▶ | use constant ANVLS => 3; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 57 | our $VERSION; | |||||||||||||||||||||||||||||||||||||||||||||
| 21 | 57 | $VERSION = sprintf "%d.%02d", q$Name: Release-1-05 $ =~ /Release-(\d+)-(\d+)/; | |||||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 57 | require Exporter; | |||||||||||||||||||||||||||||||||||||||||||||
| 24 | 57 | our @ISA = qw(Exporter); | |||||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 57 | our @EXPORT = qw(); | |||||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 57 | our @EXPORT_OK = qw( | |||||||||||||||||||||||||||||||||||||||||||||
| 29 | anvl_recarray anvl_arrayhash | ||||||||||||||||||||||||||||||||||||||||||||||
| 30 | anvl_name_naturalize | ||||||||||||||||||||||||||||||||||||||||||||||
| 31 | anvl_rechash anvl_valsplit | ||||||||||||||||||||||||||||||||||||||||||||||
| 32 | erc_anvl_expand_array kernel_labels | ||||||||||||||||||||||||||||||||||||||||||||||
| 33 | xgetlines trimlines | ||||||||||||||||||||||||||||||||||||||||||||||
| 34 | make_get_anvl | ||||||||||||||||||||||||||||||||||||||||||||||
| 35 | anvl_opt_defaults anvl_decode anvl_om | ||||||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||||||
| 37 | anvl_encode anvl_recsplit | ||||||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||||||
| 39 | ANVL ANVLR ANVLS ANVLSH | ||||||||||||||||||||||||||||||||||||||||||||||
| 40 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 57 | our %EXPORT_TAGS = (all => [ @EXPORT_OK ]); | |||||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||||||
| 44 | # All these symbols must be listed also in EXPORT_OK (?) | ||||||||||||||||||||||||||||||||||||||||||||||
| 45 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 57 | our @EXPORT_FAIL = qw( | |||||||||||||||||||||||||||||||||||||||||||||
| 47 | ANVL ANVLR ANVLS ANVLSH | ||||||||||||||||||||||||||||||||||||||||||||||
| 48 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 57 | our $anvl_mode = 'ANVL'; # default mode | |||||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||||||
| 52 | # This is a magic routine that the Exporter calls for any unknown symbols. | ||||||||||||||||||||||||||||||||||||||||||||||
| 53 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 3 | ▶ | sub export_fail { my( $class, @symbols )=@_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
export_fail: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 3 | $anvl_mode = $_ for (@symbols); | |||||||||||||||||||||||||||||||||||||||||||||
| 57 | 3 | return (); | |||||||||||||||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||||||
| 60 | # Initialize or re-initialize options to factory defaults. | ||||||||||||||||||||||||||||||||||||||||||||||
| 61 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 59 | ▶ | sub anvl_opt_defaults { return { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
anvl_opt_defaults: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||||||
| 64 | # Input options | ||||||||||||||||||||||||||||||||||||||||||||||
| 65 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 59 | autoindent => 1, # yes, fix recoverably bad indention | |||||||||||||||||||||||||||||||||||||||||||||
| 67 | comments => 0, # no, don't parse comments | ||||||||||||||||||||||||||||||||||||||||||||||
| 68 | elemsproc => # to expand short form ERCs (if any) | ||||||||||||||||||||||||||||||||||||||||||||||
| 69 | \&File::ANVL::erc_anvl_expand_array, | ||||||||||||||||||||||||||||||||||||||||||||||
| 70 | elemsprocpat => # no call from anvl_om if no match | ||||||||||||||||||||||||||||||||||||||||||||||
| 71 | qr/^erc:/m, # in rec; no call if set and matches | ||||||||||||||||||||||||||||||||||||||||||||||
| 72 | }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||||||
| 75 | # xxx decide on good name for short form and long form ERC | ||||||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||||||
| 77 | # Returns a closure that calls an input reader with that's set to *ARGV | ||||||||||||||||||||||||||||||||||||||||||||||
| 78 | # by default. If $reader and $readee are defined, they are stored in the | ||||||||||||||||||||||||||||||||||||||||||||||
| 79 | # closure and all reads will be performed by calling &$reader($readee). | ||||||||||||||||||||||||||||||||||||||||||||||
| 80 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 81 | # The default reader collects text lines from a file and returns all the | ||||||||||||||||||||||||||||||||||||||||||||||
| 82 | # lines associated with the next "record", which is considered to start | ||||||||||||||||||||||||||||||||||||||||||||||
| 83 | # wherever the read pointer happens to be and continues to the first two | ||||||||||||||||||||||||||||||||||||||||||||||
| 84 | # blank lines encountered that occur after "substance" is detected. | ||||||||||||||||||||||||||||||||||||||||||||||
| 85 | # Substance is defined to be at least one non-whitespace character | ||||||||||||||||||||||||||||||||||||||||||||||
| 86 | # occurring on a non-comment line. Comment and blank lines that precede | ||||||||||||||||||||||||||||||||||||||||||||||
| 87 | # a record with substance are returned, but any such lines that follow | ||||||||||||||||||||||||||||||||||||||||||||||
| 88 | # that the final record are discarded. | ||||||||||||||||||||||||||||||||||||||||||||||
| 89 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 53 | ▶ | sub make_get_anvl { my( $reader, $readee ) = shift; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
make_get_anvl: called CC=3 SCAR=14.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 53 | ▶ | unless ($reader) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 53 | my $rec; # returned record | |||||||||||||||||||||||||||||||||||||||||||||
| 95 | my $s; # next increment of input | ||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 53 | my $substance; # boolean detecting substance | |||||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 173 | ▶ | return sub { my( $filehandle ) = shift; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=6 SCAR=18.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||||||
| 100 | # Returns a subroutine, call it get_anvl() | ||||||||||||||||||||||||||||||||||||||||||||||
| 101 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 102 | # Usage: $record = get_anvl( [$filehandle] ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 103 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 104 | # It reads ANVL input records as text lines from the | ||||||||||||||||||||||||||||||||||||||||||||||
| 105 | # file given by $filehandle (*ARGV by default, which can | ||||||||||||||||||||||||||||||||||||||||||||||
| 106 | # process multiple files via while loop magic). Usually, | ||||||||||||||||||||||||||||||||||||||||||||||
| 107 | # the closure holds enough state information, set up by | ||||||||||||||||||||||||||||||||||||||||||||||
| 108 | # make_get_anvl(), that get_anvl() can be called without | ||||||||||||||||||||||||||||||||||||||||||||||
| 109 | # arguments. get_anvl() returns the record read as a | ||||||||||||||||||||||||||||||||||||||||||||||
| 110 | # string, or returns undef on end of input or error. | ||||||||||||||||||||||||||||||||||||||||||||||
| 111 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 173 | ▶ | $filehandle ||= *ARGV; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$filehandle ||= *ARGV
MC/DC0%0/2
$filehandle ||= *ARGV
$filehandle
*ARGV
Truth table66%2/3
A ||= B
A= $filehandleB= *ARGV
| |||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 173 | local $/ = NL.NL; # a kind of "paragraph" input mode | |||||||||||||||||||||||||||||||||||||||||||||
| 114 | # $/ === $INPUT_RECORD_SEPARATOR | ||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 173 | $rec = ''; | |||||||||||||||||||||||||||||||||||||||||||||
| 116 | 173 | ▶ | 1 while ( | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
defined($s = readline $filehandle) and $rec .= $s, $substance = $s =~ /^[^#\s]/m || $s =~ /^[^#].*\S/m, !$substance
$s =~ /^[^#\s]/m || $s =~ /^[^#].*\S/m
MC/DC100%2/2
defined($s = readline $filehandle) and $rec .= $s, $substance = $s =~ /^[^#\s]/m || $s =~ /^[^#].*\S/m, !$substance
defined($s = readline $filehandle)
$rec .= $s, $substance = $s =~ /^[^#\s]/m || $s =~ /^[^#].*\S/m, !$substance
MC/DC50%1/2
$s =~ /^[^#\s]/m || $s =~ /^[^#].*\S/m
$s =~ /^[^#\s]/m
$s =~ /^[^#].*\S/m
Truth table100%3/3
A and B
A= defined($s = readline $filehandle)B= $rec .= $s, $substance = $s =~ /^[^#\s]/m || $s =~ /^[^#].*\S/m, !$substance
Truth table66%2/3
A || B
A= $s =~ /^[^#\s]/mB= $s =~ /^[^#].*\S/m
| |||||||||||||||||||||||||||||||||||||||||||||||
| 117 | defined($s = <$filehandle>) and # read to eof and | ||||||||||||||||||||||||||||||||||||||||||||||
| 118 | ($rec .= $s), # save everything, but stop | ||||||||||||||||||||||||||||||||||||||||||||||
| 119 | $substance = # when we detect substance, ie, | ||||||||||||||||||||||||||||||||||||||||||||||
| 120 | $s =~ /^[^#\s]/m || $s =~ /^[^#].*\S/m, | ||||||||||||||||||||||||||||||||||||||||||||||
| 121 | ! $substance # non-comment with non-space | ||||||||||||||||||||||||||||||||||||||||||||||
| 122 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 173 | ▶ | return $substance ? | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 124 | $rec : # return either collected record or undef | ||||||||||||||||||||||||||||||||||||||||||||||
| 125 | undef; # any final blank or comment lines are tossed | ||||||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||||||
| 127 | # yyy If more than one file, line numbers normally accumulate | ||||||||||||||||||||||||||||||||||||||||||||||
| 128 | # across files. Should we preserve line numbers within each | ||||||||||||||||||||||||||||||||||||||||||||||
| 129 | # files? (If so, use "close ARGV" (Perl idiom) to cause $. | ||||||||||||||||||||||||||||||||||||||||||||||
| 130 | # (linenum) to be reset between files. | ||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 53 | }; | |||||||||||||||||||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||||||
| 134 | # If we get here, $reader should reference an input method and | ||||||||||||||||||||||||||||||||||||||||||||||
| 135 | # $readee is assumed to be any value (eg, BDB handle) that may | ||||||||||||||||||||||||||||||||||||||||||||||
| 136 | # permit &reader to get the next record. Any other arguments | ||||||||||||||||||||||||||||||||||||||||||||||
| 137 | # passed to the get_anvl() function below will be passed along | ||||||||||||||||||||||||||||||||||||||||||||||
| 138 | # too, ie, $reader($readee, @_). | ||||||||||||||||||||||||||||||||||||||||||||||
| 139 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 0 | ▶ | ref($reader) eq "CODE" or return undef; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 0 | my $rec; # returned record | |||||||||||||||||||||||||||||||||||||||||||||
| 143 | my $s; # next increment of input | ||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | my $substance; # boolean detecting substance | |||||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 0 | ▶ | return sub { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 0 | $rec = ''; | |||||||||||||||||||||||||||||||||||||||||||||
| 148 | 0 | ▶ | 1 while ( | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
defined($s = &reader($readee, @_)) and $rec .= $s, $substance = $s =~ /^[^#\s]/m || $s =~ /^[^#].*\S/m, !$substance
$s =~ /^[^#\s]/m || $s =~ /^[^#].*\S/m
MC/DC0%0/2
defined($s = &reader($readee, @_)) and $rec .= $s, $substance = $s =~ /^[^#\s]/m || $s =~ /^[^#].*\S/m, !$substance
defined($s = &reader($readee, @_))
$rec .= $s, $substance = $s =~ /^[^#\s]/m || $s =~ /^[^#].*\S/m, !$substance
MC/DC0%0/2
$s =~ /^[^#\s]/m || $s =~ /^[^#].*\S/m
$s =~ /^[^#\s]/m
$s =~ /^[^#].*\S/m
Truth table0%0/3
A and B
A= defined($s = &reader($readee, @_))B= $rec .= $s, $substance = $s =~ /^[^#\s]/m || $s =~ /^[^#].*\S/m, !$substance
Truth table0%0/3
A || B
A= $s =~ /^[^#\s]/mB= $s =~ /^[^#].*\S/m
| |||||||||||||||||||||||||||||||||||||||||||||||
| 149 | # XXX should this accumulate in general??? or | ||||||||||||||||||||||||||||||||||||||||||||||
| 150 | # should we leave it to the definer of $reader? | ||||||||||||||||||||||||||||||||||||||||||||||
| 151 | defined($s = &reader($readee, @_)) and # read and | ||||||||||||||||||||||||||||||||||||||||||||||
| 152 | ($rec .= $s), # save everything, but stop | ||||||||||||||||||||||||||||||||||||||||||||||
| 153 | $substance = # when we detect substance, ie, | ||||||||||||||||||||||||||||||||||||||||||||||
| 154 | $s =~ /^[^#\s]/m || $s =~ /^[^#].*\S/m, | ||||||||||||||||||||||||||||||||||||||||||||||
| 155 | ! $substance # non-comment with non-space | ||||||||||||||||||||||||||||||||||||||||||||||
| 156 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 0 | ▶ | return $substance ? | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 158 | $rec : # return either collected record or undef | ||||||||||||||||||||||||||||||||||||||||||||||
| 159 | undef; # any final blank or comment lines are tossed | ||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||||||
| 163 | # XXX deprecated! see sub make_get_anvl | ||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 0 | ▶ | sub xgetlines { my( $filehandle )=@_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
xgetlines: not called CC=7 SCAR=40.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 0 | my $rec = ''; # returned record | |||||||||||||||||||||||||||||||||||||||||||||
| 167 | 0 | my $s; # next increment of input | |||||||||||||||||||||||||||||||||||||||||||||
| 168 | 0 | local $/ = NL.NL; # a kind of "paragraph" input mode | |||||||||||||||||||||||||||||||||||||||||||||
| 169 | # $/ === $INPUT_RECORD_SEPARATOR | ||||||||||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||||||||||
| 171 | # If $filehandle is specified, use the Perl <$filehandle> idiom to | ||||||||||||||||||||||||||||||||||||||||||||||
| 172 | # return next unit of input (normally a line, but here a para). | ||||||||||||||||||||||||||||||||||||||||||||||
| 173 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 0 | ▶ | $filehandle ||= *ARGV; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$filehandle ||= *ARGV
MC/DC0%0/2
$filehandle ||= *ARGV
$filehandle
*ARGV
Truth table0%0/3
A ||= B
A= $filehandleB= *ARGV
| |||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 0 | ▶ | 1 while ( defined( $s = <$filehandle> ) and # read up to two \n's | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
defined($s = readline $filehandle) and $rec .= $s, !($s =~ /^[^#\s]/m || $s =~ /^[^#].*\S/m)
$s =~ /^[^#\s]/m || $s =~ /^[^#].*\S/m
MC/DC0%0/2
defined($s = readline $filehandle) and $rec .= $s, !($s =~ /^[^#\s]/m || $s =~ /^[^#].*\S/m)
defined($s = readline $filehandle)
$rec .= $s, !($s =~ /^[^#\s]/m || $s =~ /^[^#].*\S/m)
MC/DC0%0/2
$s =~ /^[^#\s]/m || $s =~ /^[^#].*\S/m
$s =~ /^[^#\s]/m
$s =~ /^[^#].*\S/m
Truth table0%0/3
A and B
A= defined($s = readline $filehandle)B= $rec .= $s, !($s =~ /^[^#\s]/m || $s =~ /^[^#].*\S/m)
Truth table0%0/3
A || B
A= $s =~ /^[^#\s]/mB= $s =~ /^[^#].*\S/m
| |||||||||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||||||
| 177 | # If we get here, $s now contains a block to save. | ||||||||||||||||||||||||||||||||||||||||||||||
| 178 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 179 | $rec .= $s, | ||||||||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||||||
| 181 | # We continue reading only if there's no substance, | ||||||||||||||||||||||||||||||||||||||||||||||
| 182 | # ie, no line read starts with a non-comment and no | ||||||||||||||||||||||||||||||||||||||||||||||
| 183 | # non-comment line read contains non-whitespace | ||||||||||||||||||||||||||||||||||||||||||||||
| 184 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 185 | #$s !~ /^[^#\s]/m and # if no line read starts with | ||||||||||||||||||||||||||||||||||||||||||||||
| 186 | # $s !~ /^[^#].*\S/m # or contains substance | ||||||||||||||||||||||||||||||||||||||||||||||
| 187 | #(! ($s =~ /^[^#\s]/m || $s =~ /^[^#].*\S/m) and | ||||||||||||||||||||||||||||||||||||||||||||||
| 188 | # $rec .= "substance found in <$s>\n"), | ||||||||||||||||||||||||||||||||||||||||||||||
| 189 | ! ($s =~ /^[^#\s]/m || $s =~ /^[^#].*\S/m) | ||||||||||||||||||||||||||||||||||||||||||||||
| 190 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||||||
| 192 | #$s !~ /^\s*[^#\s]/m || # match no line of susbstance | ||||||||||||||||||||||||||||||||||||||||||||||
| 193 | #$rec .= $s | ||||||||||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||||||||||
| 195 | #($rec .= $s), # only "paragraphs"; save everything | ||||||||||||||||||||||||||||||||||||||||||||||
| 196 | #$s !~ /^\s*[^#\s]/m # but stop when substance seen | ||||||||||||||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||||||||||||||
| 198 | #$s !~ /^\s*[^#\s]/m # but stop when substance seen | ||||||||||||||||||||||||||||||||||||||||||||||
| 199 | # and while $s matches no line starting with ^# | ||||||||||||||||||||||||||||||||||||||||||||||
| 200 | # while every line in $s is either all whitespace | ||||||||||||||||||||||||||||||||||||||||||||||
| 201 | # or all comment (ie, first non-ws char is #) | ||||||||||||||||||||||||||||||||||||||||||||||
| 202 | #$s =~ /\S/ # but stop when we see substance | ||||||||||||||||||||||||||||||||||||||||||||||
| 203 | #$s !~ /\S/ # but stop when we see substance | ||||||||||||||||||||||||||||||||||||||||||||||
| 204 | # substance means \S on a non-comment line | ||||||||||||||||||||||||||||||||||||||||||||||
| 205 | # $s !~ /^\S|[^#].*\S/m | ||||||||||||||||||||||||||||||||||||||||||||||
| 206 | # ! ($s =~ /^[^#\s]/m || $s =~ /^[^#].*\S/m) | ||||||||||||||||||||||||||||||||||||||||||||||
| 207 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 208 | #); # /^\s*[^#\s]/m | ||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 0 | ▶ | defined($s) or | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$rec || undef
MC/DC0%0/1
$rec || undef
$rec
Truth table0%0/2
A
A= $rec
| |||||||||||||||||||||||||||||||||||||||||||||||
| 210 | return $rec || undef; # almost eof or real eof | ||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 0 | return $rec; | |||||||||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||||||||||
| 213 | # XXXX what happens when one file ends prematurely and | ||||||||||||||||||||||||||||||||||||||||||||||
| 214 | # another begins? does last record for first file get | ||||||||||||||||||||||||||||||||||||||||||||||
| 215 | # returned glued to beginning of first recond of 2nd file? | ||||||||||||||||||||||||||||||||||||||||||||||
| 216 | # If more than one file, line numbers normally just accumulate. | ||||||||||||||||||||||||||||||||||||||||||||||
| 217 | # We want to preserve line numbers within files, so we use this | ||||||||||||||||||||||||||||||||||||||||||||||
| 218 | # next Perl idiom to cause $. (linenum) to be reset between files. | ||||||||||||||||||||||||||||||||||||||||||||||
| 219 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 220 | #close ARGV if eof; # reset line numbers between files | ||||||||||||||||||||||||||||||||||||||||||||||
| 221 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||||||||||||||||
| 223 | # args: record, reference to whitespace lines, reference to real record lines | ||||||||||||||||||||||||||||||||||||||||||||||
| 224 | # xxx replace \n with NL throughout | ||||||||||||||||||||||||||||||||||||||||||||||
| 225 | # returns undef when $rec trims to nothing (EOF) | ||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 174 | ▶ | sub trimlines { my( $rec, $r_wslines, $r_rrlines )=@_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
trimlines: called CC=5 SCAR=16.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||||||||||||||
| 228 | # $rec might legitimately be undefined if called as | ||||||||||||||||||||||||||||||||||||||||||||||
| 229 | # trimlines(getlines(), ...) | ||||||||||||||||||||||||||||||||||||||||||||||
| 230 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 174 | ▶ | $rec ||= ''; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$rec ||= ""
MC/DC100%1/1
$rec ||= ""
$rec
Truth table100%2/2
A
A= $rec
| |||||||||||||||||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 174 | $rec =~ s/^(\s*)//; # '*' guarantees $1 will be defined | |||||||||||||||||||||||||||||||||||||||||||||
| 234 | 174 | my $blanksection = $1; | |||||||||||||||||||||||||||||||||||||||||||||
| 235 | 174 | my @newlines; | |||||||||||||||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 174 | ▶ | ref($r_wslines) eq 'SCALAR' and # if given, define it | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 238 | $$r_wslines = scalar(@newlines = $blanksection =~ /\n/g); | ||||||||||||||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 174 | ▶ | ref($r_rrlines) eq 'SCALAR' and # if given, define it | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 241 | $$r_rrlines = scalar(@newlines = $rec =~ /\n/g); | ||||||||||||||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||||||||||||
| 243 | #$$r_rrlines = scalar($rec =~ /$/gm); # xxx why doesn't this work? | ||||||||||||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||||||||||||
| 245 | # At this point $r_wslines and $r_rrlines (if supplied) are safely | ||||||||||||||||||||||||||||||||||||||||||||||
| 246 | # defined and ready for return. | ||||||||||||||||||||||||||||||||||||||||||||||
| 247 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 174 | ▶ | $rec or # empty record (but $r_wslines may be defined) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 249 | return undef; # signal eof-style return | ||||||||||||||||||||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||||||||||||||||||||
| 251 | #$rec =~ /\n\n$/ and # ok record ending -- this is | ||||||||||||||||||||||||||||||||||||||||||||||
| 252 | # return $rec; # the usual return | ||||||||||||||||||||||||||||||||||||||||||||||
| 253 | #$rec =~ s/\n*$/\n\n/; # normalize premature eof ending | ||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 120 | return $rec; | |||||||||||||||||||||||||||||||||||||||||||||
| 255 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||||||||||||||
| 257 | # returns empty string on success or string beginning "warning:..." | ||||||||||||||||||||||||||||||||||||||||||||||
| 258 | # third arg (0 or 1) optional | ||||||||||||||||||||||||||||||||||||||||||||||
| 259 | # elems is returned array of name value pairs | ||||||||||||||||||||||||||||||||||||||||||||||
| 260 | #DEPRECATED: | ||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 1 | ▶ | sub anvl_recsplit { my( $record, $r_elems, $strict )=@_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
anvl_recsplit: called CC=10 SCAR=25.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 1 | ▶ | ! defined($record) and | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 264 | return "needs an ANVL record"; | ||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 1 | ▶ | ref($r_elems) ne "ARRAY" and | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 266 | return "2nd arg must reference an array"; | ||||||||||||||||||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 1 | my $strict_default = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 269 | 1 | ▶ | ! defined($strict) and | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 270 | $strict = $strict_default; | ||||||||||||||||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 1 | local $_ = $record; | |||||||||||||||||||||||||||||||||||||||||||||
| 273 | 1 | s/^\s*//; s/\s*$//; # trim both ends | |||||||||||||||||||||||||||||||||||||||||||||
| 274 | 1 | ▶ | /\n$/ or s/$/\n/; # normalize end of record to \n | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 1 | ▶ | /\n\n/ and | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 277 | return "record should have no internal blank line(s)"; | ||||||||||||||||||||||||||||||||||||||||||||||
| 278 | # xxx adjust regexp for ANVLR | ||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 1 | ▶ | ! /^[^\s:][\w ]*:/ and # match against first element | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 280 | return "well-formed record begins with a label and colon"; | ||||||||||||||||||||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 1 | ▶ | $anvl_mode ne ANVLR and | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 283 | s/^#.*\n//gm; # remove comments plus final \n | ||||||||||||||||||||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||||||||||||||||||||
| 285 | # If we're not in strict parse mode, correct for common error | ||||||||||||||||||||||||||||||||||||||||||||||
| 286 | # where continued value is not indented. We can pretty safely | ||||||||||||||||||||||||||||||||||||||||||||||
| 287 | # assume a continued value if a line is flush left and contains | ||||||||||||||||||||||||||||||||||||||||||||||
| 288 | # no colon at all. | ||||||||||||||||||||||||||||||||||||||||||||||
| 289 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 290 | # This next substitution match needs to be multi-line to avoid | ||||||||||||||||||||||||||||||||||||||||||||||
| 291 | # more explicit looping. | ||||||||||||||||||||||||||||||||||||||||||||||
| 292 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 293 | # XXX there's probably a more efficient way to do this. | ||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 1 | my $msg = ""; | |||||||||||||||||||||||||||||||||||||||||||||
| 295 | 1 | my $indented = s/^([^\s:][^:]*)$/ $1/gm; | |||||||||||||||||||||||||||||||||||||||||||||
| 296 | 1 | ▶ | if ($indented) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 0 | ▶ | $strict and | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 298 | (@$r_elems = undef), | ||||||||||||||||||||||||||||||||||||||||||||||
| 299 | return "error: $indented unindented value line(s)"; | ||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 0 | $msg = "warning: indenting $indented value line(s)"; | |||||||||||||||||||||||||||||||||||||||||||||
| 301 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 302 | # if we get here, assume standard continuation lines, and join them | ||||||||||||||||||||||||||||||||||||||||||||||
| 303 | # (GRANVL style) | ||||||||||||||||||||||||||||||||||||||||||||||
| 304 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 305 | 1 | s/\n\s+/ /g; | |||||||||||||||||||||||||||||||||||||||||||||
| 306 | # XXX should have a newline-preserving form of parse? | ||||||||||||||||||||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||||||||||||||||||||
| 308 | # Split into array element pairs. Toss first "false" split. | ||||||||||||||||||||||||||||||||||||||||||||||
| 309 | # xxx buggy limited patterns, how not to match newline | ||||||||||||||||||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||||||||||||||||||
| 311 | # This is the critical splitting step. | ||||||||||||||||||||||||||||||||||||||||||||||
| 312 | # splits line beginning ..... xxx | ||||||||||||||||||||||||||||||||||||||||||||||
| 313 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 1 | s/\n$//; # strip final \n | |||||||||||||||||||||||||||||||||||||||||||||
| 315 | 1 | (undef, @$r_elems) = split /\n*^([^\s:][\w ]*):\s*/m; | |||||||||||||||||||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 1 | return $msg; | |||||||||||||||||||||||||||||||||||||||||||||
| 318 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||||||||||||||||||||
| 320 | # xxxxxxxx respond to 'comments' (def. off), 'autoindent' (def. on), | ||||||||||||||||||||||||||||||||||||||||||||||
| 321 | # 'anvlr' (def. off), 'granvl' ? | ||||||||||||||||||||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||||||||||||||||||||
| 323 | # This is the closest thing to a reference implementation of an ANVL | ||||||||||||||||||||||||||||||||||||||||||||||
| 324 | # record parser. | ||||||||||||||||||||||||||||||||||||||||||||||
| 325 | # It returns "" on success, or "error: ..." or "warning: ..." | ||||||||||||||||||||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 127 | ▶ | sub anvl_recarray { my( $record, $r_elems, $linenum, $o )=@_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
anvl_recarray: called CC=15 SCAR=27.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 127 | ▶ | ! defined($record) and | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 330 | return "error: no input record"; | ||||||||||||||||||||||||||||||||||||||||||||||
| 331 | 127 | ▶ | ref($r_elems) ne "ARRAY" and | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 332 | return "error: 2nd arg must reference an array"; | ||||||||||||||||||||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||||||||||||||||||||
| 334 | # Note: this input $linenum is pure digits, while $lineno on | ||||||||||||||||||||||||||||||||||||||||||||||
| 335 | # output is a combination of digits and type (':' or '#') | ||||||||||||||||||||||||||||||||||||||||||||||
| 336 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 337 | 126 | ▶ | defined($linenum) or $linenum = 1; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 338 | 126 | ▶ | $linenum =~ /\D/ and | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 339 | return "error: 3rd arg ($linenum) must be a positive integer"; | ||||||||||||||||||||||||||||||||||||||||||||||
| 340 | # XXX can't this be optimized a bit to keep defaults around? | ||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 126 | ▶ | $o ||= anvl_opt_defaults(); | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$o ||= anvl_opt_defaults()
MC/DC0%0/2
$o ||= anvl_opt_defaults()
$o
anvl_opt_defaults()
Truth table66%2/3
A ||= B
A= $oB= anvl_opt_defaults()
| |||||||||||||||||||||||||||||||||||||||||||||||
| 342 | 126 | ▶ | ref($o) ne "HASH" and | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 343 | return "error: 4th arg must reference a hash"; | ||||||||||||||||||||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||||||||||||||||||||
| 345 | 126 | local $_ = $record; # localizing $_ prevents modifying global $_ | |||||||||||||||||||||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||||||||||||||||||||
| 347 | 126 | s/^\s*//; s/\s*$//; # trim both ends | |||||||||||||||||||||||||||||||||||||||||||||
| 348 | 126 | ▶ | /\n$/ or s/$/\n/; # normalize end of record to \n | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 349 | #s/\n?$/\nEOR:/; # whether record ends in \n or not, normalize | ||||||||||||||||||||||||||||||||||||||||||||||
| 350 | # # end of record to \nEOR: (note no \n after \nEOR:) | ||||||||||||||||||||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||||||||||||||||||||
| 352 | # Reject some malformed cases. | ||||||||||||||||||||||||||||||||||||||||||||||
| 353 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 354 | #/\n\n/ and | ||||||||||||||||||||||||||||||||||||||||||||||
| 355 | # return "error: record should have no internal blank line(s)"; | ||||||||||||||||||||||||||||||||||||||||||||||
| 356 | # xxx adjust regexp for ANVLR | ||||||||||||||||||||||||||||||||||||||||||||||
| 357 | # XXX fix so record can consist of nothing but comments and/or whitespace; | ||||||||||||||||||||||||||||||||||||||||||||||
| 358 | # comments _may_ be recognized in regular records, but not in this kind | ||||||||||||||||||||||||||||||||||||||||||||||
| 359 | #/^[^\s:][\w ]*:/m or # match against first element | ||||||||||||||||||||||||||||||||||||||||||||||
| 360 | # return "error: record ($_) should begin with a label and colon"; | ||||||||||||||||||||||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||||||||||||||||||||
| 362 | # Any other unindented line not containing a colon will either | ||||||||||||||||||||||||||||||||||||||||||||||
| 363 | # cause an error or will be automatically indented. | ||||||||||||||||||||||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||||||||||||||||||||
| 365 | # xxx what about $anvl_mode ne ANVLR and?? | ||||||||||||||||||||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||||||||||||||||||||
| 367 | # Now we synthesize stuff (line numbers and pseudo-element names for | ||||||||||||||||||||||||||||||||||||||||||||||
| 368 | # any comments) in order to create a uniform structure on each line, | ||||||||||||||||||||||||||||||||||||||||||||||
| 369 | # so that we can finally call 'split' to bust apart that structure | ||||||||||||||||||||||||||||||||||||||||||||||
| 370 | # into a Perl array in which every 3-element group corresponds to | ||||||||||||||||||||||||||||||||||||||||||||||
| 371 | # 1. a line number, | ||||||||||||||||||||||||||||||||||||||||||||||
| 372 | # 2. a label, and | ||||||||||||||||||||||||||||||||||||||||||||||
| 373 | # 3. a value. | ||||||||||||||||||||||||||||||||||||||||||||||
| 374 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 375 | # First insert a line number and ":" in front of each line. | ||||||||||||||||||||||||||||||||||||||||||||||
| 376 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 377 | 126 | my $num = $linenum; | |||||||||||||||||||||||||||||||||||||||||||||
| 378 | 126 | s/^/ $num++ . ":" /gem; # put a line number on each line | |||||||||||||||||||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||||||||||||||||||||
| 380 | # Remove blank lines, now that line numbers have been preserved. | ||||||||||||||||||||||||||||||||||||||||||||||
| 381 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 382 | 126 | s/^\d+:[^\S\n]*\n//gm; | |||||||||||||||||||||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||||||||||||||||||||
| 384 | # Now, if we're not deleting comments, insert a pseudo-element | ||||||||||||||||||||||||||||||||||||||||||||||
| 385 | # name '#:' in front of each comment while also changing the ':' | ||||||||||||||||||||||||||||||||||||||||||||||
| 386 | # after the line numer to '#'. This means that all lines will | ||||||||||||||||||||||||||||||||||||||||||||||
| 387 | # begin with a line number followed by ':' for real elements or | ||||||||||||||||||||||||||||||||||||||||||||||
| 388 | # by '#' for comment elements. Eg, '# foo' on line 3 becomes | ||||||||||||||||||||||||||||||||||||||||||||||
| 389 | # '3##:# foo', which conforms to the eventual split pattern we | ||||||||||||||||||||||||||||||||||||||||||||||
| 390 | # rely on (at end). | ||||||||||||||||||||||||||||||||||||||||||||||
| 391 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 392 | # xxx problem with line #K:value, which becomes, eg, 4##:K:value | ||||||||||||||||||||||||||||||||||||||||||||||
| 393 | $$o{comments} and # if we're keeping comments | ||||||||||||||||||||||||||||||||||||||||||||||
| 394 | 126 | ▶ | s/^(\d+):#/$1##:/gm, 1 | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$o->{"comments"} and s/^(\d+):#/$1##:/gm, 1
MC/DC50%1/2
$o->{"comments"} and s/^(\d+):#/$1##:/gm, 1
$o->{"comments"}
s/^(\d+):#/$1##:/gm, 1
Truth table66%2/3
A and B
A= $o->{"comments"}B= s/^(\d+):#/$1##:/gm, 1
| |||||||||||||||||||||||||||||||||||||||||||||||
| 395 | # ^^^ | ||||||||||||||||||||||||||||||||||||||||||||||
| 396 | # 123 | ||||||||||||||||||||||||||||||||||||||||||||||
| 397 | # 1=separator, 2=pseudo-name, | ||||||||||||||||||||||||||||||||||||||||||||||
| 398 | # 3=original value minus '#' starts after : | ||||||||||||||||||||||||||||||||||||||||||||||
| 399 | |||||||||||||||||||||||||||||||||||||||||||||||
| 400 | or # else completely delete comments | ||||||||||||||||||||||||||||||||||||||||||||||
| 401 | s/^\d+:#.*\n//gm # up to and including final \n | ||||||||||||||||||||||||||||||||||||||||||||||
| 402 | ; | ||||||||||||||||||||||||||||||||||||||||||||||
| 403 | |||||||||||||||||||||||||||||||||||||||||||||||
| 404 | # Return if nothing's left after deleting blank lines and comments. | ||||||||||||||||||||||||||||||||||||||||||||||
| 405 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 406 | 126 | ▶ | /^\s*$/s and | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 407 | return "warning: record at line $linenum has no content"; | ||||||||||||||||||||||||||||||||||||||||||||||
| 408 | |||||||||||||||||||||||||||||||||||||||||||||||
| 409 | 126 | my $msg = ""; # default return message | |||||||||||||||||||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||||||||||||||||||||
| 411 | # If we're not in strict parse mode, correct for common error | ||||||||||||||||||||||||||||||||||||||||||||||
| 412 | # where continued value is not indented. We can pretty safely | ||||||||||||||||||||||||||||||||||||||||||||||
| 413 | # assume a continued value if a line is flush left and contains | ||||||||||||||||||||||||||||||||||||||||||||||
| 414 | # no colon at all. | ||||||||||||||||||||||||||||||||||||||||||||||
| 415 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 416 | # This next substitution match is multi-line to avoid explicit | ||||||||||||||||||||||||||||||||||||||||||||||
| 417 | # looping (yyy is this an efficient way to do it?). It indents | ||||||||||||||||||||||||||||||||||||||||||||||
| 418 | # by one space any line starting without a space or colon and | ||||||||||||||||||||||||||||||||||||||||||||||
| 419 | # that has no instance of a colon until end of line. | ||||||||||||||||||||||||||||||||||||||||||||||
| 420 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 421 | 126 | my $indented = s/^(\d+:)([^\s:][^:]*)$/$1 $2/gm; | |||||||||||||||||||||||||||||||||||||||||||||
| 422 | 126 | ▶ | if ($indented) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 423 | 34 | ▶ | unless ($$o{autoindent}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 424 | 1 | @$r_elems = undef; # XXXXX isn't this too much? | |||||||||||||||||||||||||||||||||||||||||||||
| 425 | 1 | return "error: $indented unindented value line(s)"; | |||||||||||||||||||||||||||||||||||||||||||||
| 426 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 427 | 33 | $msg = "warning: indenting $indented value line(s)"; | |||||||||||||||||||||||||||||||||||||||||||||
| 428 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 429 | |||||||||||||||||||||||||||||||||||||||||||||||
| 430 | # Now we join the (normalized) continuation lines (GRANVL style) | ||||||||||||||||||||||||||||||||||||||||||||||
| 431 | # so each element-value pair is on one line. The + in [ \t]+ is | ||||||||||||||||||||||||||||||||||||||||||||||
| 432 | # very important; we can't use \s+ here because \s matches a \n. | ||||||||||||||||||||||||||||||||||||||||||||||
| 433 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 434 | 125 | s/\n\d+:[ \t]+/ /g; | |||||||||||||||||||||||||||||||||||||||||||||
| 435 | #s/\n\d+:\s+/ /g; | ||||||||||||||||||||||||||||||||||||||||||||||
| 436 | # XXX should we have a newline-preserving form of parse? | ||||||||||||||||||||||||||||||||||||||||||||||
| 437 | |||||||||||||||||||||||||||||||||||||||||||||||
| 438 | # Get rid of initial whitespace from all non-comment GRANVL values. | ||||||||||||||||||||||||||||||||||||||||||||||
| 439 | 125 | s/^(\d+:[^\s:][^:]*:)[ \t]+/$1/gm; | |||||||||||||||||||||||||||||||||||||||||||||
| 440 | # xxx problem with line #K:value, which becomes, eg, 4##:K:value | ||||||||||||||||||||||||||||||||||||||||||||||
| 441 | |||||||||||||||||||||||||||||||||||||||||||||||
| 442 | # Split into array of element pairs. Toss first "false" split. | ||||||||||||||||||||||||||||||||||||||||||||||
| 443 | # xxx buggy limited patterns, how not to match newline | ||||||||||||||||||||||||||||||||||||||||||||||
| 444 | |||||||||||||||||||||||||||||||||||||||||||||||
| 445 | # This is the critical splitting step. | ||||||||||||||||||||||||||||||||||||||||||||||
| 446 | # splits line beginning ..... xxx | ||||||||||||||||||||||||||||||||||||||||||||||
| 447 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 448 | 125 | s/\n$//; # strip final \n | |||||||||||||||||||||||||||||||||||||||||||||
| 449 | 125 | @$r_elems = ('', 'ANVL', # 3rd elem of 1st triple is | |||||||||||||||||||||||||||||||||||||||||||||
| 450 | # provided by first element resulting from the split | ||||||||||||||||||||||||||||||||||||||||||||||
| 451 | |||||||||||||||||||||||||||||||||||||||||||||||
| 452 | split /\n*^(\d+[:#])([^\s:][^:]*):/m | ||||||||||||||||||||||||||||||||||||||||||||||
| 453 | |||||||||||||||||||||||||||||||||||||||||||||||
| 454 | # xxx problem with line #K:value, which becomes, eg, 4##:K:value | ||||||||||||||||||||||||||||||||||||||||||||||
| 455 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 456 | |||||||||||||||||||||||||||||||||||||||||||||||
| 457 | 125 | ▶ | defined($$r_elems[2]) or | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 458 | return "error: split failed ($_) on '$record', " . | ||||||||||||||||||||||||||||||||||||||||||||||
| 459 | "record at line $linenum"; | ||||||||||||||||||||||||||||||||||||||||||||||
| 460 | |||||||||||||||||||||||||||||||||||||||||||||||
| 461 | # If there was a value with no label at the start of the record, | ||||||||||||||||||||||||||||||||||||||||||||||
| 462 | # we deem that interesting enough to keep even though it's not | ||||||||||||||||||||||||||||||||||||||||||||||
| 463 | # ANVL-compliant; the caller can prevent this by turning off | ||||||||||||||||||||||||||||||||||||||||||||||
| 464 | # 'autoindent', the processing for which will either flag this as | ||||||||||||||||||||||||||||||||||||||||||||||
| 465 | # an error or will have inserted one space in front of the value. | ||||||||||||||||||||||||||||||||||||||||||||||
| 466 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 467 | 125 | ▶ | $$r_elems[2] =~ /^(\d+): (.*)/ and | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 468 | ($$r_elems[0], $$r_elems[2]) = ($1, $2); | ||||||||||||||||||||||||||||||||||||||||||||||
| 469 | |||||||||||||||||||||||||||||||||||||||||||||||
| 470 | #(undef, @$r_elems) = split /\n*^([^\s:][\w ]*):\s*/m; | ||||||||||||||||||||||||||||||||||||||||||||||
| 471 | # yyy an approach once considered but not used | ||||||||||||||||||||||||||||||||||||||||||||||
| 472 | # $num = $.; # linenum | ||||||||||||||||||||||||||||||||||||||||||||||
| 473 | # s/^/ $num++ . ":" /e while (/\n/g); | ||||||||||||||||||||||||||||||||||||||||||||||
| 474 | # /\G ($N\#.*\n)+ (?=$N[^\#]) /gx # comment block | ||||||||||||||||||||||||||||||||||||||||||||||
| 475 | # /\G ($N\S.*\n)+ (?=$N[^\S]) /gx # element on one or more lines | ||||||||||||||||||||||||||||||||||||||||||||||
| 476 | # /\G (#.*\n)+(?=[^#])/g | ||||||||||||||||||||||||||||||||||||||||||||||
| 477 | # /^#.*?\n[^#]/s # (?=lookahead) | ||||||||||||||||||||||||||||||||||||||||||||||
| 478 | #return "_=$_\n" . join(", ", @$r_elems); # to check results | ||||||||||||||||||||||||||||||||||||||||||||||
| 479 | |||||||||||||||||||||||||||||||||||||||||||||||
| 480 | 125 | return $msg; | |||||||||||||||||||||||||||||||||||||||||||||
| 481 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 482 | |||||||||||||||||||||||||||||||||||||||||||||||
| 483 | # XXXXXX for consolidating a:b and a:c into a:b;c, MAJOR constraint | ||||||||||||||||||||||||||||||||||||||||||||||
| 484 | # is that b and c CANNOT contain '|' or we refuse... | ||||||||||||||||||||||||||||||||||||||||||||||
| 485 | |||||||||||||||||||||||||||||||||||||||||||||||
| 486 | 45 | ▶ | sub anvl_arrayhash { my( $r_elems, $r_hash, $first_only )=@_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
anvl_arrayhash: called CC=12 SCAR=25.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 487 | |||||||||||||||||||||||||||||||||||||||||||||||
| 488 | 45 | ▶ | ref($r_elems) ne "ARRAY" and | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 489 | return "error: 1st arg must reference an array"; | ||||||||||||||||||||||||||||||||||||||||||||||
| 490 | 44 | ▶ | ref($r_hash) ne "HASH" and | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 491 | return "error: 2nd arg must reference a hash"; | ||||||||||||||||||||||||||||||||||||||||||||||
| 492 | 43 | ▶ | defined($first_only) or $first_only = 0; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 493 | |||||||||||||||||||||||||||||||||||||||||||||||
| 494 | 43 | my $num_elems = scalar @$r_elems; | |||||||||||||||||||||||||||||||||||||||||||||
| 495 | 43 | ▶ | $num_elems % 3 != 0 and | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 496 | return "error: input array length must be a multiple of 3"; | ||||||||||||||||||||||||||||||||||||||||||||||
| 497 | |||||||||||||||||||||||||||||||||||||||||||||||
| 498 | 43 | ▶ | $num_elems < 1 and return ""; # no elements, we're done | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 499 | |||||||||||||||||||||||||||||||||||||||||||||||
| 500 | 43 | my $msg = ''; # xxx needed? | |||||||||||||||||||||||||||||||||||||||||||||
| 501 | 43 | my ($name, $value, $n, $v); | |||||||||||||||||||||||||||||||||||||||||||||
| 502 | |||||||||||||||||||||||||||||||||||||||||||||||
| 503 | # We know there must be at least 3 elements, so it's safe to check | ||||||||||||||||||||||||||||||||||||||||||||||
| 504 | # the special first triple (index 2 is the only one we look at now) | ||||||||||||||||||||||||||||||||||||||||||||||
| 505 | # for an initial unlabeled record element (non-standard ANVL). | ||||||||||||||||||||||||||||||||||||||||||||||
| 506 | # If we find something, we make up the name, '_'. | ||||||||||||||||||||||||||||||||||||||||||||||
| 507 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 508 | 43 | ▶ | if ($$r_elems[2]) { # first triple is special | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 509 | 27 | $name = '_'; | |||||||||||||||||||||||||||||||||||||||||||||
| 510 | ! defined $$r_hash{$name} and | ||||||||||||||||||||||||||||||||||||||||||||||
| 511 | $$r_hash{$name} = [ 0 ] # initialize array | ||||||||||||||||||||||||||||||||||||||||||||||
| 512 | or | ||||||||||||||||||||||||||||||||||||||||||||||
| 513 | 0 | ▶ | push @{ $$r_hash{$name} }, 0 # add to array | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
not defined $r_hash->{$name} and $r_hash->{$name} = [0]
MC/DC0%0/1
not defined $r_hash->{$name} and $r_hash->{$name} = [0]
not defined $r_hash->{$name}
Truth table50%1/2
not(A)
A= not defined $r_hash->{$name}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 514 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 515 | |||||||||||||||||||||||||||||||||||||||||||||||
| 516 | 43 | ▶ | for ($n = 3; $n < $num_elems; $n += 3) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 517 | |||||||||||||||||||||||||||||||||||||||||||||||
| 518 | 175 | $name = $$r_elems[$n + 1]; | |||||||||||||||||||||||||||||||||||||||||||||
| 519 | ! defined $$r_hash{$name} and | ||||||||||||||||||||||||||||||||||||||||||||||
| 520 | $$r_hash{$name} = [ $n ] # initialize array | ||||||||||||||||||||||||||||||||||||||||||||||
| 521 | or | ||||||||||||||||||||||||||||||||||||||||||||||
| 522 | 175 | ▶ | push @{ $$r_hash{$name} }, $n # add to array | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
not defined $r_hash->{$name} and $r_hash->{$name} = [$n]
MC/DC100%1/1
not defined $r_hash->{$name} and $r_hash->{$name} = [$n]
not defined $r_hash->{$name}
Truth table100%2/2
not(A)
A= not defined $r_hash->{$name}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 523 | ; | ||||||||||||||||||||||||||||||||||||||||||||||
| 524 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 525 | 43 | return $msg; | |||||||||||||||||||||||||||||||||||||||||||||
| 526 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 527 | |||||||||||||||||||||||||||||||||||||||||||||||
| 528 | # ANVL value split | ||||||||||||||||||||||||||||||||||||||||||||||
| 529 | # xxx rename to anvl_valarray? | ||||||||||||||||||||||||||||||||||||||||||||||
| 530 | # returns empty string on success or string beginning "warning:..." | ||||||||||||||||||||||||||||||||||||||||||||||
| 531 | # r_svals is reference to an array that will be filled upon return | ||||||||||||||||||||||||||||||||||||||||||||||
| 532 | 19 | ▶ | sub anvl_valsplit { my( $value, $r_svals )=@_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
anvl_valsplit: called CC=5 SCAR=16.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 533 | |||||||||||||||||||||||||||||||||||||||||||||||
| 534 | 19 | ▶ | ! defined($value) and | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 535 | return "needs an ANVL value"; | ||||||||||||||||||||||||||||||||||||||||||||||
| 536 | 19 | ▶ | ref($r_svals) ne "ARRAY" and | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 537 | return "2nd arg must reference an array"; | ||||||||||||||||||||||||||||||||||||||||||||||
| 538 | 18 | local $_; | |||||||||||||||||||||||||||||||||||||||||||||
| 539 | |||||||||||||||||||||||||||||||||||||||||||||||
| 540 | #xxx print "r_svals=$r_svals\n"; | ||||||||||||||||||||||||||||||||||||||||||||||
| 541 | #xxx print "value=$value\n"; | ||||||||||||||||||||||||||||||||||||||||||||||
| 542 | 18 | my $warning = ""; # xxx used? | |||||||||||||||||||||||||||||||||||||||||||||
| 543 | #my $ret_subvalues = \$_[1]; | ||||||||||||||||||||||||||||||||||||||||||||||
| 544 | |||||||||||||||||||||||||||||||||||||||||||||||
| 545 | # Assume value is all on one line and split it. | ||||||||||||||||||||||||||||||||||||||||||||||
| 546 | #my @svals = split /\|/, $value; | ||||||||||||||||||||||||||||||||||||||||||||||
| 547 | 18 | @$r_svals = split /\|/, $value; | |||||||||||||||||||||||||||||||||||||||||||||
| 548 | #$_[1] = \@svals; | ||||||||||||||||||||||||||||||||||||||||||||||
| 549 | $_ = [ split(/;/, $_) ] # create array of arrays | ||||||||||||||||||||||||||||||||||||||||||||||
| 550 | 18 | for (@$r_svals); | |||||||||||||||||||||||||||||||||||||||||||||
| 551 | #xxxprint("svals=", join(", ", @$_), "\n") for (@$r_svals); | ||||||||||||||||||||||||||||||||||||||||||||||
| 552 | |||||||||||||||||||||||||||||||||||||||||||||||
| 553 | # xxxx need to look for all 3 levels: (change spec) | ||||||||||||||||||||||||||||||||||||||||||||||
| 554 | # XXXXXXX value ::= one or more svals (sval1 | sval2 | ...) | ||||||||||||||||||||||||||||||||||||||||||||||
| 555 | # XXXXXXX sval ::= one or more rvals (rval1 ; rval2 ; ...) | ||||||||||||||||||||||||||||||||||||||||||||||
| 556 | # XXXXXXX rval ::= one or more qvals (qval1 (=) qval2 (=) ...) | ||||||||||||||||||||||||||||||||||||||||||||||
| 557 | # where s=sub, r=repeated, q=equivalent | ||||||||||||||||||||||||||||||||||||||||||||||
| 558 | # XXXXXXX or ?? rval ::= one or more avals (aval1 (=) aval2 (=) ...) | ||||||||||||||||||||||||||||||||||||||||||||||
| 559 | 18 | ▶ | return $warning ? "warning: $warning" : ""; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 560 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 561 | |||||||||||||||||||||||||||||||||||||||||||||||
| 562 | # Create record hash, elem is key, value is value | ||||||||||||||||||||||||||||||||||||||||||||||
| 563 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 564 | 2 | ▶ | sub anvl_rechash { my( $record, $r_hash, $strict )=@_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
anvl_rechash: called CC=8 SCAR=23.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 565 | |||||||||||||||||||||||||||||||||||||||||||||||
| 566 | 2 | ▶ | ! defined($record) and | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 567 | return "needs an ANVL record"; | ||||||||||||||||||||||||||||||||||||||||||||||
| 568 | 2 | ▶ | ref($r_hash) ne "HASH" and | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 569 | return "2nd arg must reference a hash"; | ||||||||||||||||||||||||||||||||||||||||||||||
| 570 | |||||||||||||||||||||||||||||||||||||||||||||||
| 571 | 1 | my $msg = ""; | |||||||||||||||||||||||||||||||||||||||||||||
| 572 | 1 | my @elems; | |||||||||||||||||||||||||||||||||||||||||||||
| 573 | 1 | ▶ | ($msg = anvl_recsplit($record, \@elems, $strict)) and | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 574 | return "anvl_recsplit: $msg"; | ||||||||||||||||||||||||||||||||||||||||||||||
| 575 | |||||||||||||||||||||||||||||||||||||||||||||||
| 576 | 1 | my ($name, $value); | |||||||||||||||||||||||||||||||||||||||||||||
| 577 | 1 | while (1) { | |||||||||||||||||||||||||||||||||||||||||||||
| 578 | 2 | $name = shift @elems; | |||||||||||||||||||||||||||||||||||||||||||||
| 579 | 2 | ▶ | last unless defined $name; # nothing left | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 580 | 1 | $value = shift @elems; | |||||||||||||||||||||||||||||||||||||||||||||
| 581 | 1 | ▶ | if (! defined $$r_hash{$name}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 582 | # Nothing there, so store scalar and continue. | ||||||||||||||||||||||||||||||||||||||||||||||
| 583 | 1 | $$r_hash{$name} = $value; # 1st value (non-array) | |||||||||||||||||||||||||||||||||||||||||||||
| 584 | 1 | next; | |||||||||||||||||||||||||||||||||||||||||||||
| 585 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 586 | # If we get here there's something's already there. | ||||||||||||||||||||||||||||||||||||||||||||||
| 587 | # Don't overwrite if we're in $strict mode. | ||||||||||||||||||||||||||||||||||||||||||||||
| 588 | # xxx document this | ||||||||||||||||||||||||||||||||||||||||||||||
| 589 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 590 | 0 | ▶ | $strict and next; # don't overwrite | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 591 | |||||||||||||||||||||||||||||||||||||||||||||||
| 592 | # XXXXXxxxx make adding a value policy-driven, eg, | ||||||||||||||||||||||||||||||||||||||||||||||
| 593 | # "add" could mean (a) replace, (b) push on end array, | ||||||||||||||||||||||||||||||||||||||||||||||
| 594 | # (c) push on start of array, (d) string concatenation, | ||||||||||||||||||||||||||||||||||||||||||||||
| 595 | # (d) error. | ||||||||||||||||||||||||||||||||||||||||||||||
| 596 | # xxx should anvl_rechash save line numbers? | ||||||||||||||||||||||||||||||||||||||||||||||
| 597 | # xxx should anvl_recsplit save line numbers? | ||||||||||||||||||||||||||||||||||||||||||||||
| 598 | |||||||||||||||||||||||||||||||||||||||||||||||
| 599 | # Whatever is there could be a scalar or an array reference. | ||||||||||||||||||||||||||||||||||||||||||||||
| 600 | # If not a reference, create an anonymous array, put a | ||||||||||||||||||||||||||||||||||||||||||||||
| 601 | # scalar into it, and refer to the array. | ||||||||||||||||||||||||||||||||||||||||||||||
| 602 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 603 | 0 | my $v = $$r_hash{$name}; # add to current | |||||||||||||||||||||||||||||||||||||||||||||
| 604 | 0 | ▶ | $v = [ $v ] # make an array if currently | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 605 | unless ref $v; # there's only one value | ||||||||||||||||||||||||||||||||||||||||||||||
| 606 | |||||||||||||||||||||||||||||||||||||||||||||||
| 607 | # If we get here, we have a reference to an array, | ||||||||||||||||||||||||||||||||||||||||||||||
| 608 | # possibly empty. Either way, we can push onto it. | ||||||||||||||||||||||||||||||||||||||||||||||
| 609 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 610 | 0 | push @$v, $value; | |||||||||||||||||||||||||||||||||||||||||||||
| 611 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 612 | 1 | return $msg; | |||||||||||||||||||||||||||||||||||||||||||||
| 613 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 614 | |||||||||||||||||||||||||||||||||||||||||||||||
| 615 | # [ !"#\$%&'\(\)\*\+,/:;<=>\?@\[\\\]\|\0] | ||||||||||||||||||||||||||||||||||||||||||||||
| 616 | 57 | our %anvl_decoding = ( | |||||||||||||||||||||||||||||||||||||||||||||
| 617 | |||||||||||||||||||||||||||||||||||||||||||||||
| 618 | 'sp' => ' ', # decodes to space (0x20) | ||||||||||||||||||||||||||||||||||||||||||||||
| 619 | 'ex' => '!', # decodes to ! (0x21) | ||||||||||||||||||||||||||||||||||||||||||||||
| 620 | 'dq' => '"', # decodes to " (0x22) | ||||||||||||||||||||||||||||||||||||||||||||||
| 621 | 'ns' => '#', # decodes to # (0x23) | ||||||||||||||||||||||||||||||||||||||||||||||
| 622 | 'do' => '$', # decodes to $ (0x24) | ||||||||||||||||||||||||||||||||||||||||||||||
| 623 | 'pe' => '%', # decodes to % (0x25) | ||||||||||||||||||||||||||||||||||||||||||||||
| 624 | 'am' => '&', # decodes to & (0x26) | ||||||||||||||||||||||||||||||||||||||||||||||
| 625 | 'sq' => "'", # decodes to ' (0x27) | ||||||||||||||||||||||||||||||||||||||||||||||
| 626 | 'op' => '(', # decodes to ( (0x28) | ||||||||||||||||||||||||||||||||||||||||||||||
| 627 | 'cp' => ')', # decodes to ) (0x29) | ||||||||||||||||||||||||||||||||||||||||||||||
| 628 | 'as' => '*', # decodes to * (0x2a) | ||||||||||||||||||||||||||||||||||||||||||||||
| 629 | 'pl' => '+', # decodes to + (0x2b) | ||||||||||||||||||||||||||||||||||||||||||||||
| 630 | 'co' => ',', # decodes to , (0x2c) | ||||||||||||||||||||||||||||||||||||||||||||||
| 631 | 'sl' => '/', # decodes to / (0x2f) | ||||||||||||||||||||||||||||||||||||||||||||||
| 632 | 'cn' => ':', # decodes to : (0x3a) | ||||||||||||||||||||||||||||||||||||||||||||||
| 633 | 'sc' => ';', # decodes to ; (0x3b) | ||||||||||||||||||||||||||||||||||||||||||||||
| 634 | 'lt' => '<', # decodes to < (0x3c) | ||||||||||||||||||||||||||||||||||||||||||||||
| 635 | 'eq' => '=', # decodes to = (0x3d) | ||||||||||||||||||||||||||||||||||||||||||||||
| 636 | 'gt' => '>', # decodes to > (0x3e) | ||||||||||||||||||||||||||||||||||||||||||||||
| 637 | 'qu' => '?', # decodes to ? (0x3f) | ||||||||||||||||||||||||||||||||||||||||||||||
| 638 | 'at' => '@', # decodes to @ (0x40) | ||||||||||||||||||||||||||||||||||||||||||||||
| 639 | 'ox' => '[', # decodes to [ (0x5b) | ||||||||||||||||||||||||||||||||||||||||||||||
| 640 | 'ls' => '\\', # decodes to \ (0x5c) | ||||||||||||||||||||||||||||||||||||||||||||||
| 641 | 'cx' => ']', # decodes to ] (0x5d) | ||||||||||||||||||||||||||||||||||||||||||||||
| 642 | 'vb' => '|', # decodes to | (0x7c) | ||||||||||||||||||||||||||||||||||||||||||||||
| 643 | 'nu' => "\0", # decodes to null (0x00) | ||||||||||||||||||||||||||||||||||||||||||||||
| 644 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 645 | # XXXXXXX need way to encode newlines (using '\n' in interim) | ||||||||||||||||||||||||||||||||||||||||||||||
| 646 | |||||||||||||||||||||||||||||||||||||||||||||||
| 647 | 57 | our %anvl_encoding; | |||||||||||||||||||||||||||||||||||||||||||||
| 648 | |||||||||||||||||||||||||||||||||||||||||||||||
| 649 | #%cn : | ||||||||||||||||||||||||||||||||||||||||||||||
| 650 | #%sc ; | ||||||||||||||||||||||||||||||||||||||||||||||
| 651 | |||||||||||||||||||||||||||||||||||||||||||||||
| 652 | # xxxxx handle these separately | ||||||||||||||||||||||||||||||||||||||||||||||
| 653 | # # XXXX remove %% from erc/anvlspec? | ||||||||||||||||||||||||||||||||||||||||||||||
| 654 | # '%' => '%pe', # decodes to % (0x25) xxxx do this first? | ||||||||||||||||||||||||||||||||||||||||||||||
| 655 | # '_' => '', # a non-character used as a syntax shim | ||||||||||||||||||||||||||||||||||||||||||||||
| 656 | # '{' => '', # a non-character that begins an expansion block | ||||||||||||||||||||||||||||||||||||||||||||||
| 657 | # '}' => '', # a non-character that ends an expansion block | ||||||||||||||||||||||||||||||||||||||||||||||
| 658 | |||||||||||||||||||||||||||||||||||||||||||||||
| 659 | # Takes a single arg. | ||||||||||||||||||||||||||||||||||||||||||||||
| 660 | 5 | ▶ | sub anvl_decode { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
anvl_decode: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 661 | |||||||||||||||||||||||||||||||||||||||||||||||
| 662 | 5 | ▶ | local $_ = shift(@_) || ''; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
shift @_ || ''
MC/DC0%0/1
shift @_ || ''
shift @_
Truth table50%1/2
A
A= shift @_
| |||||||||||||||||||||||||||||||||||||||||||||||
| 663 | |||||||||||||||||||||||||||||||||||||||||||||||
| 664 | 5 | pos() = 0; # reset \G for $_ just to be safe | |||||||||||||||||||||||||||||||||||||||||||||
| 665 | 5 | ▶ | while (/(?=\%\{)/g) { # lookahead; \G matches just before | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 666 | 7 | my $p = pos(); # note \G position before it changes | |||||||||||||||||||||||||||||||||||||||||||||
| 667 | 7 | ▶ | s/\G \%\{ (.*?) \%\}//xs # 's' modifier makes . match \n | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 668 | or last; # if no closing brace, skip match | ||||||||||||||||||||||||||||||||||||||||||||||
| 669 | 6 | my $exp_block = $1; # save removed expansion block | |||||||||||||||||||||||||||||||||||||||||||||
| 670 | 6 | $exp_block =~ s/\s+//g; # strip it of all whitespace | |||||||||||||||||||||||||||||||||||||||||||||
| 671 | 6 | pos() = $p; # revert \G to where we started and | |||||||||||||||||||||||||||||||||||||||||||||
| 672 | 6 | s/\G/$exp_block/; # re-insert changed expansion block | |||||||||||||||||||||||||||||||||||||||||||||
| 673 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 674 | 5 | s/\%[}{]//g; # remove any remaining unmatched | |||||||||||||||||||||||||||||||||||||||||||||
| 675 | 5 | s/\%_//g; # xxx %_ -> '' | |||||||||||||||||||||||||||||||||||||||||||||
| 676 | 5 | s/\%\%/\%pe/g; # xxx ??? xxxx??? | |||||||||||||||||||||||||||||||||||||||||||||
| 677 | # decode %XY where XY together don't form a valid pair of hex digits | ||||||||||||||||||||||||||||||||||||||||||||||
| 678 | 5 | s/\%([g-z][a-z]|[a-z][g-z])/$anvl_decoding{$1}/g; | |||||||||||||||||||||||||||||||||||||||||||||
| 679 | 5 | return $_; | |||||||||||||||||||||||||||||||||||||||||||||
| 680 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 681 | |||||||||||||||||||||||||||||||||||||||||||||||
| 682 | # xxx encoding should be context-sensitive, eg, name, value | ||||||||||||||||||||||||||||||||||||||||||||||
| 683 | 1 | ▶ | sub anvl_encode { my( $s )=@_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
anvl_encode: called CC=3 SCAR=11.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 684 | |||||||||||||||||||||||||||||||||||||||||||||||
| 685 | # XXXX just define this in the module?? | ||||||||||||||||||||||||||||||||||||||||||||||
| 686 | 1 | ▶ | unless (%anvl_encoding) { # one-time definition | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 687 | # This just defines an inverse mapping so we can encode. | ||||||||||||||||||||||||||||||||||||||||||||||
| 688 | $anvl_encoding{$anvl_decoding{$_}} = $_ | ||||||||||||||||||||||||||||||||||||||||||||||
| 689 | 1 | for (keys %anvl_decoding); | |||||||||||||||||||||||||||||||||||||||||||||
| 690 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 691 | $s =~ | ||||||||||||||||||||||||||||||||||||||||||||||
| 692 | 1 | s/([ !\"#\$\%&'\(\)\*\+,\/:;<=>\?@\[\\\]\|\0])/\%$anvl_encoding{$1}/g; | |||||||||||||||||||||||||||||||||||||||||||||
| 693 | 1 | return $s; | |||||||||||||||||||||||||||||||||||||||||||||
| 694 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 695 | |||||||||||||||||||||||||||||||||||||||||||||||
| 696 | # return $name in natural word order, using ANVL inversion points | ||||||||||||||||||||||||||||||||||||||||||||||
| 697 | # repeat for each final comma present | ||||||||||||||||||||||||||||||||||||||||||||||
| 698 | 9 | ▶ | sub anvl_name_naturalize { my( $name )=@_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
anvl_name_naturalize: called CC=5 SCAR=16.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 699 | |||||||||||||||||||||||||||||||||||||||||||||||
| 700 | 9 | ▶ | $name ||= ''; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$name ||= ""
MC/DC0%0/1
$name ||= ""
$name
Truth table50%1/2
A
A= $name
| |||||||||||||||||||||||||||||||||||||||||||||||
| 701 | 9 | ▶ | $name =~ /^\s*$/ and return $name; # empty | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 702 | |||||||||||||||||||||||||||||||||||||||||||||||
| 703 | # "McCartney, Paul, Sir,," | ||||||||||||||||||||||||||||||||||||||||||||||
| 704 | # a, b, c, d, e,,, -> e d c a, b | ||||||||||||||||||||||||||||||||||||||||||||||
| 705 | 9 | my $prefix = ''; | |||||||||||||||||||||||||||||||||||||||||||||
| 706 | 9 | ▶ | while ($name =~ s/,\s*$//) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 707 | 14 | ▶ | $name =~ s/^(.*),\s*([^,]+)(,*$)/$1$3/ and | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 708 | $prefix .= $2 . ' '; | ||||||||||||||||||||||||||||||||||||||||||||||
| 709 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 710 | 9 | return $prefix . $name; | |||||||||||||||||||||||||||||||||||||||||||||
| 711 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 712 | |||||||||||||||||||||||||||||||||||||||||||||||
| 713 | 0 | ▶ | sub anvl_summarize { my( @nodes )=@_; } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
anvl_summarize: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 714 | |||||||||||||||||||||||||||||||||||||||||||||||
| 715 | # XXXXX doesn't this really belong in an ERC.pm module? | ||||||||||||||||||||||||||||||||||||||||||||||
| 716 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 717 | # ordered list of kernel element names | ||||||||||||||||||||||||||||||||||||||||||||||
| 718 | 57 | our @kernel_labels = qw( | |||||||||||||||||||||||||||||||||||||||||||||
| 719 | who | ||||||||||||||||||||||||||||||||||||||||||||||
| 720 | what | ||||||||||||||||||||||||||||||||||||||||||||||
| 721 | when | ||||||||||||||||||||||||||||||||||||||||||||||
| 722 | where | ||||||||||||||||||||||||||||||||||||||||||||||
| 723 | how | ||||||||||||||||||||||||||||||||||||||||||||||
| 724 | why | ||||||||||||||||||||||||||||||||||||||||||||||
| 725 | huh | ||||||||||||||||||||||||||||||||||||||||||||||
| 726 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 727 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 728 | # This routine inspects and possibly modifies in place the kind of element | ||||||||||||||||||||||||||||||||||||||||||||||
| 729 | # array resulting from a call to anvl_recarray(), which splits and ANVL | ||||||||||||||||||||||||||||||||||||||||||||||
| 730 | # record. It is useful for transforming short form ERC elements into full | ||||||||||||||||||||||||||||||||||||||||||||||
| 731 | # form elements, for example, to expand "erc:a|b|c|d" into the equivalent, | ||||||||||||||||||||||||||||||||||||||||||||||
| 732 | # "erc:\nwho:a\nwhat:b\nwhen:c\nwhere:d". | ||||||||||||||||||||||||||||||||||||||||||||||
| 733 | # It returns the empty string on success, otherwise an error message. | ||||||||||||||||||||||||||||||||||||||||||||||
| 734 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 735 | 14 | ▶ | sub erc_anvl_expand_array { my( $r_elems )=@_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
erc_anvl_expand_array: called CC=9 SCAR=22.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 736 | |||||||||||||||||||||||||||||||||||||||||||||||
| 737 | 57 | ▶ | use File::ANVL; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 738 | 14 | my ($lineno, $name, $value, $msg, @svals, $sval); | |||||||||||||||||||||||||||||||||||||||||||||
| 739 | 14 | my $me = 'erc_anvl_expand_array'; | |||||||||||||||||||||||||||||||||||||||||||||
| 740 | 14 | my $i = 3; # skip first 3 elems (anvl array preamble) | |||||||||||||||||||||||||||||||||||||||||||||
| 741 | 14 | while (1) { | |||||||||||||||||||||||||||||||||||||||||||||
| 742 | 145 | $lineno = $$r_elems[$i++]; | |||||||||||||||||||||||||||||||||||||||||||||
| 743 | 145 | ▶ | $name = $$r_elems[$i++] || ''; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$$r_elems[$i++] || ''
MC/DC100%1/1
$$r_elems[$i++] || ''
$$r_elems[$i++]
Truth table100%2/2
A
A= $$r_elems[$i++]
| |||||||||||||||||||||||||||||||||||||||||||||||
| 744 | 145 | ▶ | $value = $$r_elems[$i++] || ''; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$$r_elems[$i++] || ''
MC/DC100%1/1
$$r_elems[$i++] || ''
$$r_elems[$i++]
Truth table100%2/2
A
A= $$r_elems[$i++]
| |||||||||||||||||||||||||||||||||||||||||||||||
| 745 | 145 | ▶ | last unless defined $lineno; # end of record | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 746 | next # skip unless we have erc-type thing | ||||||||||||||||||||||||||||||||||||||||||||||
| 747 | 131 | ▶ | if ($name ne 'erc' || $value =~ /^\s*$/); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$name ne "erc" or $value =~ /^\s*$/
MC/DC100%2/2
$name ne "erc" or $value =~ /^\s*$/
$name ne "erc"
$value =~ /^\s*$/
Truth table100%3/3
A or B
A= $name ne "erc"B= $value =~ /^\s*$/
| |||||||||||||||||||||||||||||||||||||||||||||||
| 748 | #if ($name !~ /^erc\b/ || $value =~ /^\s*$/); | ||||||||||||||||||||||||||||||||||||||||||||||
| 749 | # xxx should do this for full generality | ||||||||||||||||||||||||||||||||||||||||||||||
| 750 | |||||||||||||||||||||||||||||||||||||||||||||||
| 751 | # If here, we have an erc-type thing with a non-empty value. | ||||||||||||||||||||||||||||||||||||||||||||||
| 752 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 753 | 16 | ▶ | ($msg = anvl_valsplit($value, \@svals)) and | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 754 | return "error: $me: anvl_valsplit: $msg"; | ||||||||||||||||||||||||||||||||||||||||||||||
| 755 | |||||||||||||||||||||||||||||||||||||||||||||||
| 756 | # XXXX only doing straight "erc" (eg, not erc-about) | ||||||||||||||||||||||||||||||||||||||||||||||
| 757 | 16 | my $j = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 758 | 16 | my @extras = (); | |||||||||||||||||||||||||||||||||||||||||||||
| 759 | # If we exceed known labels, we'll re-use last known label. | ||||||||||||||||||||||||||||||||||||||||||||||
| 760 | 16 | my $unknown = $kernel_labels[$#kernel_labels]; | |||||||||||||||||||||||||||||||||||||||||||||
| 761 | 16 | foreach $sval (@svals) { | |||||||||||||||||||||||||||||||||||||||||||||
| 762 | |||||||||||||||||||||||||||||||||||||||||||||||
| 763 | # xxx not (yet) tranferring subvalue structure | ||||||||||||||||||||||||||||||||||||||||||||||
| 764 | # to anvl_om or other conversion | ||||||||||||||||||||||||||||||||||||||||||||||
| 765 | # Recall that each $sval is itself a reference to | ||||||||||||||||||||||||||||||||||||||||||||||
| 766 | # an array of subvalues (often just one element). | ||||||||||||||||||||||||||||||||||||||||||||||
| 767 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 768 | 92 | ▶ | push @extras, # trust kernel_labels order | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$File::ANVL::kernel_labels[$j++] || $unknown
MC/DC0%0/2
$File::ANVL::kernel_labels[$j++] || $unknown
$File::ANVL::kernel_labels[$j++]
$unknown
Truth table66%2/3
A || B
A= $File::ANVL::kernel_labels[$j++]B= $unknown
| |||||||||||||||||||||||||||||||||||||||||||||||
| 769 | $lineno, | ||||||||||||||||||||||||||||||||||||||||||||||
| 770 | $kernel_labels[$j++] || $unknown, | ||||||||||||||||||||||||||||||||||||||||||||||
| 771 | join('; ', # trim ends of subvalues | ||||||||||||||||||||||||||||||||||||||||||||||
| 772 | map(m/^\s*(.*?)\s*$/, @$sval) | ||||||||||||||||||||||||||||||||||||||||||||||
| 773 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 774 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 775 | # Finally, replace our $value element with '' and append | ||||||||||||||||||||||||||||||||||||||||||||||
| 776 | # the new extra values we've just expanded. | ||||||||||||||||||||||||||||||||||||||||||||||
| 777 | 16 | splice @$r_elems, $i-1, 1, | |||||||||||||||||||||||||||||||||||||||||||||
| 778 | '', # replaces $value we just used up | ||||||||||||||||||||||||||||||||||||||||||||||
| 779 | @extras; # adds new elements from $value | ||||||||||||||||||||||||||||||||||||||||||||||
| 780 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 781 | 14 | return ''; # success | |||||||||||||||||||||||||||||||||||||||||||||
| 782 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 783 | |||||||||||||||||||||||||||||||||||||||||||||||
| 784 | # XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX============= | ||||||||||||||||||||||||||||||||||||||||||||||
| 785 | # xxx checkm _in_ <repo> obj1 obj2 ... --> returns noids | ||||||||||||||||||||||||||||||||||||||||||||||
| 786 | # xxx checkm _out_ <repo> id1 id2 ... --> returns objects | ||||||||||||||||||||||||||||||||||||||||||||||
| 787 | |||||||||||||||||||||||||||||||||||||||||||||||
| 788 | # XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX============= | ||||||||||||||||||||||||||||||||||||||||||||||
| 789 | # xxx do metadata scan of object before ingest and confirm with user that | ||||||||||||||||||||||||||||||||||||||||||||||
| 790 | # the object is correctly identified. This could even be done remotely. | ||||||||||||||||||||||||||||||||||||||||||||||
| 791 | # Start with informal staff service for depositing objects, returning a | ||||||||||||||||||||||||||||||||||||||||||||||
| 792 | # short url to a stable object, and not clogging up allstaff inboxes with | ||||||||||||||||||||||||||||||||||||||||||||||
| 793 | # huge attachments. Also applies to any number of draft docs for review | ||||||||||||||||||||||||||||||||||||||||||||||
| 794 | # but in temporary storage (but stable). | ||||||||||||||||||||||||||||||||||||||||||||||
| 795 | |||||||||||||||||||||||||||||||||||||||||||||||
| 796 | # XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX============= | ||||||||||||||||||||||||||||||||||||||||||||||
| 797 | # xxx do id generator service with 'expiring' ids. To mint, you tell us | ||||||||||||||||||||||||||||||||||||||||||||||
| 798 | # who you are first. To get a perm. id, you agree to use your minted id | ||||||||||||||||||||||||||||||||||||||||||||||
| 799 | # and bind it within N months. We track, and warn you several times | ||||||||||||||||||||||||||||||||||||||||||||||
| 800 | # until N months as elapsed and then reclaim/recycle the id. | ||||||||||||||||||||||||||||||||||||||||||||||
| 801 | |||||||||||||||||||||||||||||||||||||||||||||||
| 802 | ############################################ | ||||||||||||||||||||||||||||||||||||||||||||||
| 803 | # Output Multiplexer routines | ||||||||||||||||||||||||||||||||||||||||||||||
| 804 | ############################################ | ||||||||||||||||||||||||||||||||||||||||||||||
| 805 | |||||||||||||||||||||||||||||||||||||||||||||||
| 806 | # #$erc = "erc: Smith, J.|The Whole Truth|2004|http://example.com/foo/bar"; | ||||||||||||||||||||||||||||||||||||||||||||||
| 807 | # $errmsg = File::ERC::erc_anvl2erc_turtle ($erc, $rec); | ||||||||||||||||||||||||||||||||||||||||||||||
| 808 | # $errmsg and | ||||||||||||||||||||||||||||||||||||||||||||||
| 809 | # print("$errmsg\n") | ||||||||||||||||||||||||||||||||||||||||||||||
| 810 | # or | ||||||||||||||||||||||||||||||||||||||||||||||
| 811 | # print("turtle record:\n$rec\n") | ||||||||||||||||||||||||||||||||||||||||||||||
| 812 | # ; | ||||||||||||||||||||||||||||||||||||||||||||||
| 813 | |||||||||||||||||||||||||||||||||||||||||||||||
| 814 | # xxx anvl_fmt not consistent with om_anvl! | ||||||||||||||||||||||||||||||||||||||||||||||
| 815 | |||||||||||||||||||||||||||||||||||||||||||||||
| 816 | # Input file(s) from ARGV. | ||||||||||||||||||||||||||||||||||||||||||||||
| 817 | |||||||||||||||||||||||||||||||||||||||||||||||
| 818 | 52 | ▶ | sub anvl_om { my( $om, $o, $get_anvl ) = (shift, shift, shift); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
anvl_om: called CC=45 SCAR=42.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 819 | |||||||||||||||||||||||||||||||||||||||||||||||
| 820 | 52 | ▶ | return "anvl_om: 1st arg not an OM object" | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 821 | if ref($om) !~ /^File::OM::/; | ||||||||||||||||||||||||||||||||||||||||||||||
| 822 | 52 | my $p = $om->{outhandle}; # whether 'print' status or small | |||||||||||||||||||||||||||||||||||||||||||||
| 823 | 52 | ▶ | $o ||= anvl_opt_defaults(); | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$o ||= anvl_opt_defaults()
MC/DC0%0/2
$o ||= anvl_opt_defaults()
$o
anvl_opt_defaults()
Truth table33%1/3
A ||= B
A= $oB= anvl_opt_defaults()
| |||||||||||||||||||||||||||||||||||||||||||||||
| 824 | 52 | ▶ | $get_anvl ||= File::ANVL::make_get_anvl(); # xxx set input here? | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$get_anvl ||= make_get_anvl()
MC/DC0%0/2
$get_anvl ||= make_get_anvl()
$get_anvl
make_get_anvl()
Truth table33%1/3
A ||= B
A= $get_anvlB= make_get_anvl()
| |||||||||||||||||||||||||||||||||||||||||||||||
| 825 | # XXX test return value! | ||||||||||||||||||||||||||||||||||||||||||||||
| 826 | |||||||||||||||||||||||||||||||||||||||||||||||
| 827 | 52 | my $s = ''; # output strings are returned to $s | |||||||||||||||||||||||||||||||||||||||||||||
| 828 | 52 | ▶ | my $st = $p ? 1 : ''; # returns (stati or strings) accumulate | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 829 | 52 | my ($msg, $allmsgs, $anvlrec, $lineno, $name, $value, $pat, $n, $nmax); | |||||||||||||||||||||||||||||||||||||||||||||
| 830 | 52 | my (%rechash, $ne, $nemax, $elem_name); # for alt. element ordering | |||||||||||||||||||||||||||||||||||||||||||||
| 831 | 52 | my $r_elem_order = $$o{elem_order}; | |||||||||||||||||||||||||||||||||||||||||||||
| 832 | |||||||||||||||||||||||||||||||||||||||||||||||
| 833 | 52 | $s = $om->ostream(); # open stream | |||||||||||||||||||||||||||||||||||||||||||||
| 834 | |||||||||||||||||||||||||||||||||||||||||||||||
| 835 | # This next line is a fast and compact (if cryptic) way to | ||||||||||||||||||||||||||||||||||||||||||||||
| 836 | # accumulate $om->method calls. Used after each method call, it | ||||||||||||||||||||||||||||||||||||||||||||||
| 837 | # concatenates strings or ANDs up print statuses, depending on the | ||||||||||||||||||||||||||||||||||||||||||||||
| 838 | # outhandle setting. It makes several appearances in this routine. | ||||||||||||||||||||||||||||||||||||||||||||||
| 839 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 840 | 52 | ▶ | $p and ($st &&= $s), 1 or ($st .= $s); # accumulate method returns | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$p and $st &&= $s, 1
$st &&= $s
MC/DC0%0/2
$p and $st &&= $s, 1
$p
$st &&= $s, 1
MC/DC0%0/2
$st &&= $s
$st
$s
Truth table33%1/3
A and B
A= $pB= $st &&= $s, 1
Truth table33%1/3
A &&= B
A= $stB= $s
| |||||||||||||||||||||||||||||||||||||||||||||||
| 841 | |||||||||||||||||||||||||||||||||||||||||||||||
| 842 | # Numbers: record, element in record, and start line | ||||||||||||||||||||||||||||||||||||||||||||||
| 843 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 844 | 52 | my ($startline, $recnum, $elemnum) = (1, 0, 0); | |||||||||||||||||||||||||||||||||||||||||||||
| 845 | 52 | my ($wslines, $rrlines); | |||||||||||||||||||||||||||||||||||||||||||||
| 846 | 52 | my $r_elems = $om->{elemsref}; # abbreviation | |||||||||||||||||||||||||||||||||||||||||||||
| 847 | # xxx is that reference kosher? | ||||||||||||||||||||||||||||||||||||||||||||||
| 848 | |||||||||||||||||||||||||||||||||||||||||||||||
| 849 | 52 | while (1) { | |||||||||||||||||||||||||||||||||||||||||||||
| 850 | |||||||||||||||||||||||||||||||||||||||||||||||
| 851 | # Get an ANVL record and count lines therein. ANVL | ||||||||||||||||||||||||||||||||||||||||||||||
| 852 | # records can come from anywhere, but typically from | ||||||||||||||||||||||||||||||||||||||||||||||
| 853 | # a file (read in "paragraph" mode) or a BDB database. | ||||||||||||||||||||||||||||||||||||||||||||||
| 854 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 855 | 169 | $anvlrec = trimlines(&$get_anvl(), \$wslines, \$rrlines); | |||||||||||||||||||||||||||||||||||||||||||||
| 856 | 169 | $startline += $wslines; | |||||||||||||||||||||||||||||||||||||||||||||
| 857 | 169 | ▶ | last unless $anvlrec; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 858 | |||||||||||||||||||||||||||||||||||||||||||||||
| 859 | 117 | $recnum++; # increment record counter | |||||||||||||||||||||||||||||||||||||||||||||
| 860 | =for later | ||||||||||||||||||||||||||||||||||||||||||||||
| 861 | # XXX anvl_recarray is expensive, do we _need_ to do it if the output is | ||||||||||||||||||||||||||||||||||||||||||||||
| 862 | # also in anvl? Maybe call modified [2] here so "find" can work? | ||||||||||||||||||||||||||||||||||||||||||||||
| 863 | if (ref($om) eq 'File::OM::ANVL' and ! $r_elem_order) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 864 | # xxx do quick expand (short->long erc) here? | ||||||||||||||||||||||||||||||||||||||||||||||
| 865 | # xxx _will_ disturb input line numbering | ||||||||||||||||||||||||||||||||||||||||||||||
| 866 | $$o{find} and ($anvlrec !~ /$$o{find}/m) and | ||||||||||||||||||||||||||||||||||||||||||||||
| 867 | next; # no output has occurred | ||||||||||||||||||||||||||||||||||||||||||||||
| 868 | # xxx do quick check for 'show' and next | ||||||||||||||||||||||||||||||||||||||||||||||
| 869 | # XXXXXXXX must define lineno for verbose case | ||||||||||||||||||||||||||||||||||||||||||||||
| 870 | $s = $om->anvl_rec($anvlrec, $startline, $rrlines); | ||||||||||||||||||||||||||||||||||||||||||||||
| 871 | $p and ($st &&= $s), 1 or ($st .= $s); | ||||||||||||||||||||||||||||||||||||||||||||||
| 872 | next; | ||||||||||||||||||||||||||||||||||||||||||||||
| 873 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 874 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||
| 875 | 117 | $msg = anvl_recarray($anvlrec, $r_elems, $startline, $o); | |||||||||||||||||||||||||||||||||||||||||||||
| 876 | 117 | ▶ | $msg =~ /^error/ and return "anvl_recarray: $msg"; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 877 | 117 | ▶ | $msg eq "" or | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 878 | #print $msg, "\n"; | ||||||||||||||||||||||||||||||||||||||||||||||
| 879 | #$o->{verbose} && print $msg, "\n"; | ||||||||||||||||||||||||||||||||||||||||||||||
| 880 | $allmsgs .= $msg . "\n"; # save other message | ||||||||||||||||||||||||||||||||||||||||||||||
| 881 | |||||||||||||||||||||||||||||||||||||||||||||||
| 882 | # NB: apply 'find' here before possible expansion, which | ||||||||||||||||||||||||||||||||||||||||||||||
| 883 | # means that a pattern like "who:\s*smith" won't work on | ||||||||||||||||||||||||||||||||||||||||||||||
| 884 | # on a short form ANVL record. | ||||||||||||||||||||||||||||||||||||||||||||||
| 885 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 886 | 117 | ▶ | $$o{find} and ($anvlrec !~ /$$o{find}/m) and | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$o->{"find"} and not $anvlrec =~ /$o->{"find"}/m
MC/DC100%2/2
$o->{"find"} and not $anvlrec =~ /$o->{"find"}/m
$o->{"find"}
not $anvlrec =~ /$o->{"find"}/m
Truth table100%3/3
A and not(B)
A= $o->{"find"}B= not $anvlrec =~ /$o->{"find"}/m
| |||||||||||||||||||||||||||||||||||||||||||||||
| 887 | next; # no output has occurred | ||||||||||||||||||||||||||||||||||||||||||||||
| 888 | |||||||||||||||||||||||||||||||||||||||||||||||
| 889 | # If caller has set $$o{elemsproc} to a code reference, | ||||||||||||||||||||||||||||||||||||||||||||||
| 890 | # it is called to process the element array just returned | ||||||||||||||||||||||||||||||||||||||||||||||
| 891 | # from anvl_recarray. Typically this is used to convert | ||||||||||||||||||||||||||||||||||||||||||||||
| 892 | # (with erc_anvl_expand_array) short form ERCs to long | ||||||||||||||||||||||||||||||||||||||||||||||
| 893 | # form ERCs. As an optimization, the code is not called | ||||||||||||||||||||||||||||||||||||||||||||||
| 894 | # if $$o{elemsprocpat} (typically, "erc") is set and | ||||||||||||||||||||||||||||||||||||||||||||||
| 895 | # doesn't match the raw record string. | ||||||||||||||||||||||||||||||||||||||||||||||
| 896 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 897 | 111 | ▶ | if (ref($$o{elemsproc}) eq "CODE" and # if code and either | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
ref $o->{"elemsproc"} eq "CODE" and !($pat = $o->{"elemsprocpat"}) || $anvlrec =~ /$pat/
not $pat = $o->{"elemsprocpat"} or $anvlrec =~ /$pat/
MC/DC33%1/3
ref $o->{"elemsproc"} eq "CODE" and !($pat = $o->{"elemsprocpat"}) || $anvlrec =~ /$pat/
ref $o->{"elemsproc"} eq "CODE"
not $pat = $o->{"elemsprocpat"}
$anvlrec =~ /$pat/
Truth table50%2/4
A and not(B) or C
A= ref $o->{"elemsproc"} eq "CODE"B= not $pat = $o->{"elemsprocpat"}C= $anvlrec =~ /$pat/
| |||||||||||||||||||||||||||||||||||||||||||||||
| 898 | (! ($pat = $$o{elemsprocpat})) # no pattern or | ||||||||||||||||||||||||||||||||||||||||||||||
| 899 | || $anvlrec =~ $pat) { # the pattern matches | ||||||||||||||||||||||||||||||||||||||||||||||
| 900 | |||||||||||||||||||||||||||||||||||||||||||||||
| 901 | # [2] XXX can we call elemsproc directly on the $anvlrec? so we don't need | ||||||||||||||||||||||||||||||||||||||||||||||
| 902 | # to call expensive anvl_recarray first? | ||||||||||||||||||||||||||||||||||||||||||||||
| 903 | 10 | ▶ | ($msg = &{$$o{elemsproc}}($r_elems)) and | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 904 | return "File::ANVL::elemsproc: $msg"; | ||||||||||||||||||||||||||||||||||||||||||||||
| 905 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 906 | 111 | ▶ | ref($om) eq 'File::OM::Turtle' and | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 907 | turtle_set_subject($om, $anvlrec); | ||||||||||||||||||||||||||||||||||||||||||||||
| 908 | |||||||||||||||||||||||||||||||||||||||||||||||
| 909 | # The orec method is given first crack at a new record. | ||||||||||||||||||||||||||||||||||||||||||||||
| 910 | # It sets and/or clears a number of values for keys (eg, | ||||||||||||||||||||||||||||||||||||||||||||||
| 911 | # for turtle, $$o{subject}). $recnum is useful for | ||||||||||||||||||||||||||||||||||||||||||||||
| 912 | # outputting json separators (eg, no comma if $recnum eq 1) | ||||||||||||||||||||||||||||||||||||||||||||||
| 913 | # or record numbers in comments (eg, if $$o{verbose}). | ||||||||||||||||||||||||||||||||||||||||||||||
| 914 | # $startline is useful for parser diagnostics (eg, "error | ||||||||||||||||||||||||||||||||||||||||||||||
| 915 | # on line 5"). $r_elems and $r_elem_order are needed for | ||||||||||||||||||||||||||||||||||||||||||||||
| 916 | # discovering what elements will populate CSV/PSV records. | ||||||||||||||||||||||||||||||||||||||||||||||
| 917 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 918 | # XXX this next isn't needed if output is anvl ?! (assuming final NL is | ||||||||||||||||||||||||||||||||||||||||||||||
| 919 | # written when closing the record | ||||||||||||||||||||||||||||||||||||||||||||||
| 920 | 111 | $s = $om->orec($recnum, $startline, $r_elems, $r_elem_order); | |||||||||||||||||||||||||||||||||||||||||||||
| 921 | 111 | ▶ | $p and ($st &&= $s), 1 or ($st .= $s); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$p and $st &&= $s, 1
$st &&= $s
MC/DC0%0/2
$p and $st &&= $s, 1
$p
$st &&= $s, 1
MC/DC0%0/2
$st &&= $s
$st
$s
Truth table33%1/3
A and B
A= $pB= $st &&= $s, 1
Truth table33%1/3
A &&= B
A= $stB= $s
| |||||||||||||||||||||||||||||||||||||||||||||||
| 922 | |||||||||||||||||||||||||||||||||||||||||||||||
| 923 | 111 | ▶ | if ($r_elem_order) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 924 | 42 | undef %rechash; # don't want prior indices | |||||||||||||||||||||||||||||||||||||||||||||
| 925 | 42 | ▶ | ($msg = anvl_arrayhash($r_elems, \%rechash)) and | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 926 | return "anvl_arrayhash: $msg"; | ||||||||||||||||||||||||||||||||||||||||||||||
| 927 | 42 | $ne = -1; # index into $$r_elem_order | |||||||||||||||||||||||||||||||||||||||||||||
| 928 | 42 | $nemax = scalar @$r_elem_order; | |||||||||||||||||||||||||||||||||||||||||||||
| 929 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 930 | 69 | ▶ | $n = # index into $$r_elems | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 931 | # XXX don't reference r_elems if we haven't called anvl_recarray | ||||||||||||||||||||||||||||||||||||||||||||||
| 932 | $$r_elems[2] # if a no-label value starts | ||||||||||||||||||||||||||||||||||||||||||||||
| 933 | ? -3 # rec, make sure to output it, | ||||||||||||||||||||||||||||||||||||||||||||||
| 934 | : 0; # else skip it (normal) | ||||||||||||||||||||||||||||||||||||||||||||||
| 935 | 69 | $nmax = scalar @$r_elems; | |||||||||||||||||||||||||||||||||||||||||||||
| 936 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 937 | |||||||||||||||||||||||||||||||||||||||||||||||
| 938 | # XXX if output is to anvl, can we not skip the entire loop below? but | ||||||||||||||||||||||||||||||||||||||||||||||
| 939 | # not if it's possible to output anvl _and_ to care about element order | ||||||||||||||||||||||||||||||||||||||||||||||
| 940 | # XXX but still perform $show check and skip not-shown elems | ||||||||||||||||||||||||||||||||||||||||||||||
| 941 | # XXX and still perform value inversion if {invert} options | ||||||||||||||||||||||||||||||||||||||||||||||
| 942 | 111 | $elemnum = 0; # true elements, not comments | |||||||||||||||||||||||||||||||||||||||||||||
| 943 | 111 | undef $name; | |||||||||||||||||||||||||||||||||||||||||||||
| 944 | 111 | while (1) { | |||||||||||||||||||||||||||||||||||||||||||||
| 945 | |||||||||||||||||||||||||||||||||||||||||||||||
| 946 | # Select next candidate element. If we need to | ||||||||||||||||||||||||||||||||||||||||||||||
| 947 | # output elements in a certain order, consult the | ||||||||||||||||||||||||||||||||||||||||||||||
| 948 | # hash; otherwise, just use "found" order. | ||||||||||||||||||||||||||||||||||||||||||||||
| 949 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 950 | 501 | ▶ | if ($r_elem_order) { # use specified order | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 951 | |||||||||||||||||||||||||||||||||||||||||||||||
| 952 | 163 | $ne++; | |||||||||||||||||||||||||||||||||||||||||||||
| 953 | 163 | ▶ | $ne >= $nemax and last; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 954 | |||||||||||||||||||||||||||||||||||||||||||||||
| 955 | # For CSV and PSV, the element name at this | ||||||||||||||||||||||||||||||||||||||||||||||
| 956 | # position may be deliberately undefined, or | ||||||||||||||||||||||||||||||||||||||||||||||
| 957 | # may correspond to a named element missing | ||||||||||||||||||||||||||||||||||||||||||||||
| 958 | # in this record, in which case we skip it. | ||||||||||||||||||||||||||||||||||||||||||||||
| 959 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 960 | 121 | $elem_name = $r_elem_order->[$ne]; | |||||||||||||||||||||||||||||||||||||||||||||
| 961 | ! defined($elem_name) || ! defined( | ||||||||||||||||||||||||||||||||||||||||||||||
| 962 | #XXX ignore multiple instances for now | ||||||||||||||||||||||||||||||||||||||||||||||
| 963 | 121 | ▶ | $n = $rechash{$elem_name}->[0] | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $elem_name and defined($n = $rechash{$elem_name}[0])
MC/DC50%1/2
defined $elem_name and defined($n = $rechash{$elem_name}[0])
defined $elem_name
defined($n = $rechash{$elem_name}[0])
Truth table66%2/3
A and B
A= defined $elem_nameB= defined($n = $rechash{$elem_name}[0])
| |||||||||||||||||||||||||||||||||||||||||||||||
| 964 | ) and | ||||||||||||||||||||||||||||||||||||||||||||||
| 965 | # for CSV/PSV, output an empty element | ||||||||||||||||||||||||||||||||||||||||||||||
| 966 | next; | ||||||||||||||||||||||||||||||||||||||||||||||
| 967 | |||||||||||||||||||||||||||||||||||||||||||||||
| 968 | } else { # use natural array order | ||||||||||||||||||||||||||||||||||||||||||||||
| 969 | 338 | $n += 3; | |||||||||||||||||||||||||||||||||||||||||||||
| 970 | 338 | ▶ | $n >= $nmax and last; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 971 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 972 | # If we get here, $n is defined. | ||||||||||||||||||||||||||||||||||||||||||||||
| 973 | |||||||||||||||||||||||||||||||||||||||||||||||
| 974 | 380 | $lineno = $$r_elems[$n]; | |||||||||||||||||||||||||||||||||||||||||||||
| 975 | 380 | ▶ | $name = $n < 3 # for special first triple | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 976 | ? '_' # use synthesized name '_' | ||||||||||||||||||||||||||||||||||||||||||||||
| 977 | : $$r_elems[$n + 1]; # else real name | ||||||||||||||||||||||||||||||||||||||||||||||
| 978 | 380 | ▶ | $value = $$r_elems[$n + 2] || ""; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$$r_elems[$n + 2] || ''
MC/DC100%1/1
$$r_elems[$n + 2] || ''
$$r_elems[$n + 2]
Truth table100%2/2
A
A= $$r_elems[$n + 2]
| |||||||||||||||||||||||||||||||||||||||||||||||
| 979 | |||||||||||||||||||||||||||||||||||||||||||||||
| 980 | 380 | ▶ | $elemnum++ unless $name eq '#'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 981 | |||||||||||||||||||||||||||||||||||||||||||||||
| 982 | # Skip if 'show' given and not requested. | ||||||||||||||||||||||||||||||||||||||||||||||
| 983 | 380 | ▶ | $$o{show} and ("$name: $value" !~ /$$o{show}/m) and | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$o->{"show"} and not +("${name}: $value") =~ /$o->{"show"}/m
MC/DC100%2/2
$o->{"show"} and not +("${name}: $value") =~ /$o->{"show"}/m
$o->{"show"}
not +("${name}: $value") =~ /$o->{"show"}/m
Truth table100%3/3
A and not(B)
A= $o->{"show"}B= not +("${name}: $value") =~ /$o->{"show"}/m
| |||||||||||||||||||||||||||||||||||||||||||||||
| 984 | (undef $name), # cause elem to be skipped | ||||||||||||||||||||||||||||||||||||||||||||||
| 985 | next; | ||||||||||||||||||||||||||||||||||||||||||||||
| 986 | |||||||||||||||||||||||||||||||||||||||||||||||
| 987 | # Instead of $om->oelem, $om->celem, $om->contelem, | ||||||||||||||||||||||||||||||||||||||||||||||
| 988 | # combine open and close into one, but first | ||||||||||||||||||||||||||||||||||||||||||||||
| 989 | # naturalize values if called upon. | ||||||||||||||||||||||||||||||||||||||||||||||
| 990 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 991 | 361 | ▶ | $$o{invert} and $value =~ /,\s*$/ and | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$o->{"invert"} and $value =~ /,\s*$/
MC/DC50%1/2
$o->{"invert"} and $value =~ /,\s*$/
$o->{"invert"}
$value =~ /,\s*$/
Truth table66%2/3
A and B
A= $o->{"invert"}B= $value =~ /,\s*$/
| |||||||||||||||||||||||||||||||||||||||||||||||
| 992 | $value = anvl_name_naturalize($value); | ||||||||||||||||||||||||||||||||||||||||||||||
| 993 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 994 | continue { | ||||||||||||||||||||||||||||||||||||||||||||||
| 995 | 390 | $s = $om->elem($name, $value, $lineno); | |||||||||||||||||||||||||||||||||||||||||||||
| 996 | 390 | ▶ | $p and ($st &&= $s), 1 or ($st .= $s); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$p and $st &&= $s, 1
$st &&= $s
MC/DC0%0/2
$p and $st &&= $s, 1
$p
$st &&= $s, 1
MC/DC0%0/2
$st &&= $s
$st
$s
Truth table33%1/3
A and B
A= $pB= $st &&= $s, 1
Truth table33%1/3
A &&= B
A= $stB= $s
| |||||||||||||||||||||||||||||||||||||||||||||||
| 997 | 390 | undef $name; # clean the slate | |||||||||||||||||||||||||||||||||||||||||||||
| 998 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 999 | 111 | $s = $om->crec($recnum); | |||||||||||||||||||||||||||||||||||||||||||||
| 1000 | 111 | ▶ | $p and ($st &&= $s), 1 or ($st .= $s); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$p and $st &&= $s, 1
$st &&= $s
MC/DC0%0/2
$p and $st &&= $s, 1
$p
$st &&= $s, 1
MC/DC0%0/2
$st &&= $s
$st
$s
Truth table33%1/3
A and B
A= $pB= $st &&= $s, 1
Truth table33%1/3
A &&= B
A= $stB= $s
| |||||||||||||||||||||||||||||||||||||||||||||||
| 1001 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 1002 | continue { | ||||||||||||||||||||||||||||||||||||||||||||||
| 1003 | 117 | $startline += $rrlines; | |||||||||||||||||||||||||||||||||||||||||||||
| 1004 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 1005 | # XXX currently doing nothing with $allmsgs warnings! | ||||||||||||||||||||||||||||||||||||||||||||||
| 1006 | # should probably print if verbose mode on | ||||||||||||||||||||||||||||||||||||||||||||||
| 1007 | 52 | $s = $om->cstream(); | |||||||||||||||||||||||||||||||||||||||||||||
| 1008 | 52 | ▶ | $p and ($st &&= $s), 1 or ($st .= $s); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$p and $st &&= $s, 1
$st &&= $s
MC/DC0%0/2
$p and $st &&= $s, 1
$p
$st &&= $s, 1
MC/DC0%0/2
$st &&= $s
$st
$s
Truth table33%1/3
A and B
A= $pB= $st &&= $s, 1
Truth table33%1/3
A &&= B
A= $stB= $s
| |||||||||||||||||||||||||||||||||||||||||||||||
| 1009 | |||||||||||||||||||||||||||||||||||||||||||||||
| 1010 | 52 | return $st; | |||||||||||||||||||||||||||||||||||||||||||||
| 1011 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 1012 | |||||||||||||||||||||||||||||||||||||||||||||||
| 1013 | # xxx document all om options | ||||||||||||||||||||||||||||||||||||||||||||||
| 1014 | # xxx should om also have a recstring slot (for anvlrec)? | ||||||||||||||||||||||||||||||||||||||||||||||
| 1015 | # xxx pass in turtle_nosubject (default)? | ||||||||||||||||||||||||||||||||||||||||||||||
| 1016 | 12 | ▶ | sub turtle_set_subject { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
turtle_set_subject: called CC=10 SCAR=24.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 1017 | |||||||||||||||||||||||||||||||||||||||||||||||
| 1018 | 12 | my ($om, $anvlrec) = (shift, shift); | |||||||||||||||||||||||||||||||||||||||||||||
| 1019 | 12 | my $r_elems = $om->{elemsref}; | |||||||||||||||||||||||||||||||||||||||||||||
| 1020 | |||||||||||||||||||||||||||||||||||||||||||||||
| 1021 | # In order to find the subject element for Turtle/RDF | ||||||||||||||||||||||||||||||||||||||||||||||
| 1022 | # assertions, we need an element name pattern. If one is | ||||||||||||||||||||||||||||||||||||||||||||||
| 1023 | # defined in $om->{turtle_subjelpat}, use it. If it's undefined, | ||||||||||||||||||||||||||||||||||||||||||||||
| 1024 | # per-record code will use 'where' if it thinks the record | ||||||||||||||||||||||||||||||||||||||||||||||
| 1025 | # is an ERC, or use 'identifier|subject' as a last resort. | ||||||||||||||||||||||||||||||||||||||||||||||
| 1026 | # If no element matching subjelpat is found, $om->{subject} | ||||||||||||||||||||||||||||||||||||||||||||||
| 1027 | # will default to $om->{turtle_nosubject}. | ||||||||||||||||||||||||||||||||||||||||||||||
| 1028 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 1029 | my $subjpat = $om->{turtle_subjelpat} || | ||||||||||||||||||||||||||||||||||||||||||||||
| 1030 | 12 | ▶ | ($anvlrec =~ /^erc\s*:/m | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition66%2/3
$om->{'turtle_subjelpat'} || ($anvlrec =~ /^erc\s*:/m ? '^where$' : ($anvlrec =~ /^(identifier|subject)\s*:/m ? "^$1\$" : ($anvlrec =~ /^(.+)\s*:\s*(\n\s+)*\w/ ? "^$1\$" : '')))
MC/DC0%0/2
$om->{'turtle_subjelpat'} || ($anvlrec =~ /^erc\s*:/m ? '^where$' : ($anvlrec =~ /^(identifier|subject)\s*:/m ? "^$1\$" : ($anvlrec =~ /^(.+)\s*:\s*(\n\s+)*\w/ ? "^$1\$" : '')))
$om->{'turtle_subjelpat'}
($anvlrec =~ /^erc\s*:/m ? '^where$' : ($anvlrec =~ /^(identifier|subject)\s*:/m ? "^$1\$" : ($anvlrec =~ /^(.+)\s*:\s*(\n\s+)*\w/ ? "^$1\$" : '')))
Truth table66%2/3
A || B
A= $om->{'turtle_subjelpat'}B= ($anvlrec =~ /^erc\s*:/m ? '^where$' : ($anvlrec =~ /^(identifier|subject)\s*:/m ? "^$1\$" : ($anvlrec =~ /^(.+)\s*:\s*(\n\s+)*\w/ ? "^$1\$" : '')))
| |||||||||||||||||||||||||||||||||||||||||||||||
| 1031 | ? "^where\$" : # 1st where in an 'erc', or | ||||||||||||||||||||||||||||||||||||||||||||||
| 1032 | ($anvlrec =~ /^(identifier|subject)\s*:/m | ||||||||||||||||||||||||||||||||||||||||||||||
| 1033 | ? "^$1\$" : # 1st identifier or subject, | ||||||||||||||||||||||||||||||||||||||||||||||
| 1034 | ($anvlrec =~ /^(.+)\s*:\s*(\n\s+)*\w/ | ||||||||||||||||||||||||||||||||||||||||||||||
| 1035 | ? "^$1\$" : # or 1st non-empty element | ||||||||||||||||||||||||||||||||||||||||||||||
| 1036 | ''))); # or nothing (always matches) | ||||||||||||||||||||||||||||||||||||||||||||||
| 1037 | |||||||||||||||||||||||||||||||||||||||||||||||
| 1038 | # Now find a 'subject' for our Turtle/RDF assertions. | ||||||||||||||||||||||||||||||||||||||||||||||
| 1039 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 1040 | 12 | my $j = 1; # element names in positions 1, 4, 7, ... | |||||||||||||||||||||||||||||||||||||||||||||
| 1041 | 12 | ▶ | 1 while ($j < $#$r_elems and # quickly find it | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
$j < $r_elems->$#* and not @$r_elems[$j] =~ /$subjpat/ and $j += 3
$j < $r_elems->$#* and not @$r_elems[$j] =~ /$subjpat/
MC/DC33%1/3
$j < $r_elems->$#* and not @$r_elems[$j] =~ /$subjpat/ and $j += 3
$j < $r_elems->$#*
not @$r_elems[$j] =~ /$subjpat/
$j += 3
Truth table50%2/4
A and not(B) and C
A= $j < $r_elems->$#*B= not @$r_elems[$j] =~ /$subjpat/C= $j += 3
| |||||||||||||||||||||||||||||||||||||||||||||||
| 1042 | @$r_elems[$j] !~ $subjpat and ($j += 3)); | ||||||||||||||||||||||||||||||||||||||||||||||
| 1043 | $om->{subject} = $j < $#$r_elems && $subjpat ? # if found, | ||||||||||||||||||||||||||||||||||||||||||||||
| 1044 | @$r_elems[$j + 1] : # use associated value | ||||||||||||||||||||||||||||||||||||||||||||||
| 1045 | 12 | ▶ | $om->{turtle_nosubject}; # else use default | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$j < $r_elems->$#* and $subjpat
MC/DC0%0/2
$j < $r_elems->$#* and $subjpat
$j < $r_elems->$#*
$subjpat
Truth table33%1/3
A and B
A= $j < $r_elems->$#*B= $subjpat
| |||||||||||||||||||||||||||||||||||||||||||||||
| 1046 | 12 | return $om->{subject}; | |||||||||||||||||||||||||||||||||||||||||||||
| 1047 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 1048 | |||||||||||||||||||||||||||||||||||||||||||||||
| 1049 | 57 | 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 1050 | |||||||||||||||||||||||||||||||||||||||||||||||
| 1051 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||