| 1 | #!/usr/bin/perl -I/home/phil/perl/cpan/DataTableText/lib/ -I/home/phil/perl/cpan/DataEditXml/lib/ | ||||||||||||||||||||||||||||
| 2 | #------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 3 | # Lint xml files in parallel using xmllint and report the pass/failure rate. | ||||||||||||||||||||||||||||
| 4 | # Philip R Brenan at gmail dot com, Appa Apps Ltd Inc, 2016-2019 | ||||||||||||||||||||||||||||
| 5 | #------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 6 | # podDocumentation | ||||||||||||||||||||||||||||
| 7 | # Id definitions should be processed independently of labels | ||||||||||||||||||||||||||||
| 8 | # What sort of tag is on the end of the link? | ||||||||||||||||||||||||||||
| 9 | # Report resolved, unresolved, missing links - difficult because of forking | ||||||||||||||||||||||||||||
| 10 | # Check that the file actually has a lint section in read and do something about it if it does not | ||||||||||||||||||||||||||||
| 11 | # Separate reference fixup into a separate framework (like Dita::Conversion) | ||||||||||||||||||||||||||||
| 12 | # Show number of compressed errors on Lint summary line | ||||||||||||||||||||||||||||
| 13 | # Highlight error counts in bold using boldText() or perhaps enclosed alphanumerics | ||||||||||||||||||||||||||||
| 14 | # Relint load data in parallel | ||||||||||||||||||||||||||||
| 15 | # option to print xmllint command | ||||||||||||||||||||||||||||
| 16 | # inputFile=>name unicode seems to be failing | ||||||||||||||||||||||||||||
| 17 | # Lots more tests needed | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | package Data::Edit::Xml::Lint; | ||||||||||||||||||||||||||||
| 20 | 1 | our $VERSION = 20200108; | |||||||||||||||||||||||||||
| 21 | 1 | ▶ | use warnings FATAL => qw(all); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 22 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 23 | 1 | ▶ | use Carp qw(cluck confess); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 24 | 1 | ▶ | use Data::Dump qw(dump); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 25 | 1 | ▶ | use Data::Table::Text qw(:all); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 26 | 1 | ▶ | use Time::HiRes qw(time); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 27 | 1 | ▶ | use Encode; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 0 | ▶ | sub maxLintMsgLength {128} # Truncate xml lint messages longer then this | ||||||||||||||||||||||||||
|
Subroutine
maxLintMsgLength: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 30 | 0 | ▶ | sub maxExampleFiles {3} # Maximum number of example files | ||||||||||||||||||||||||||
|
Subroutine
maxExampleFiles: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | #D1 Constructor # Construct a new linter | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | sub new #S Create a new xml linter - call this method statically as in L<Data::Edit::Xml::Lint|/new> and then fill in the relevant L<Attributes>. | ||||||||||||||||||||||||||||
| 35 | 0 | ▶ | {bless {} # Create xml linter | ||||||||||||||||||||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | #D2 Attributes # Attributes describing a lint. | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 1 | genLValueScalarMethods(qw(author)); # Optional author of the xml - only needed if you want to generate an SDL file map. | |||||||||||||||||||||||||||
| 41 | 1 | genLValueScalarMethods(qw(catalog)); # Optional catalog file containing the locations of the DTDs used to validate the xml or use L<dtds|/dtds> to supply a B<DTD> instead. | |||||||||||||||||||||||||||
| 42 | 1 | genLValueScalarMethods(qw(compressedErrors)); # Number of compressed errors discovered. | |||||||||||||||||||||||||||
| 43 | 1 | genLValueScalarMethods(qw(compressedErrorText)); # Text of compressed errors. | |||||||||||||||||||||||||||
| 44 | 1 | genLValueScalarMethods(qw(ditaType)); # Optional Dita topic type(concept|task|troubleshooting|reference) of the xml - only needed if you want to generate an SDL file map. | |||||||||||||||||||||||||||
| 45 | 1 | genLValueScalarMethods(qw(docType)); # The second line: the document type extracted from the L<source|/source>. | |||||||||||||||||||||||||||
| 46 | 1 | genLValueScalarMethods(qw(dtds)); # Optional directory containing the DTDs used to validate the xml. | |||||||||||||||||||||||||||
| 47 | 1 | genLValueScalarMethods(qw(errors)); # Total number of uncompressed lint errors detected by xmllint over all files. | |||||||||||||||||||||||||||
| 48 | 1 | genLValueScalarMethods(qw(errorText)); # Text of uncompressed lint errors detected by xmllint over all files. | |||||||||||||||||||||||||||
| 49 | 1 | genLValueScalarMethods(qw(file)); # File that the xml should be written to or read from by L<lint|/lint>, L<read|/read> or L<relint|/relint>. | |||||||||||||||||||||||||||
| 50 | 1 | genLValueScalarMethods(qw(fileNumber)); # File number - assigned by the caller to help debugging transformations. | |||||||||||||||||||||||||||
| 51 | 1 | genLValueScalarMethods(qw(lineNumber)); # The file and line number of the caller so we can identify which request for lint gave rise to a particular file | |||||||||||||||||||||||||||
| 52 | 1 | genLValueScalarMethods(qw(guid)); # Guid or id of the outermost tag - if not supplied the first definition encountered in each file will be used on the basis that all Dita topics require an id. | |||||||||||||||||||||||||||
| 53 | 1 | genLValueScalarMethods(qw(header)); # The first line: the xml header extracted from L<source|/source>. | |||||||||||||||||||||||||||
| 54 | 1 | genLValueScalarMethods(qw(idDefs)); # {id} = count - the number of times this id is defined in the xml contained in this L<file|/file>. | |||||||||||||||||||||||||||
| 55 | 1 | genLValueScalarMethods(qw(inputFile)); # The file from which this xml was obtained. | |||||||||||||||||||||||||||
| 56 | 1 | genLValueScalarMethods(qw(labelDefs)); # {label or id} = id - the id of the node containing a L<label|Data::Edit::Xml/Labels> defined on the xml. | |||||||||||||||||||||||||||
| 57 | 1 | genLValueScalarMethods(qw(labels)); # Optional parse tree to supply L<labels|Data::Edit::Xml/Labels> for the current L<source|/source> as the labels are present in the parse tree not in the string representing the parse tree. | |||||||||||||||||||||||||||
| 58 | 1 | genLValueScalarMethods(qw(linted)); # Date the lint was performed by L<lint|/lint>. We avoid adding a time as well because this then induces much longer sync times with AWS S3. | |||||||||||||||||||||||||||
| 59 | 1 | genLValueScalarMethods(qw(preferredSource)); # Preferred representation of the xml source, used by L<relint|/relint> to supply a preferred representation for the source. | |||||||||||||||||||||||||||
| 60 | 1 | genLValueScalarMethods(qw(processes)); # Maximum number of xmllint processes to run in parallel - 8 by default if linting in parallel is being used. Linting in parallel is pointless if each file is already being converted in parallel. Conversely, linting in parallel is helpful if the xml files are being converted serially. | |||||||||||||||||||||||||||
| 61 | 1 | genLValueScalarMethods(qw(project)); # Optional L<project|/project> name to allow error counts to be aggregated by L<project|/project> and to allow L<id and labels|Data::Edit::Xml/Labels> to be scoped to the L<files|/file> contained in each L<project|/project>. | |||||||||||||||||||||||||||
| 62 | 1 | genLValueArrayMethods(qw(reusedInProject)); # List of projects in which this file is reused, which can be set via L<reuseFileInProject|/reuseFileInProject> every time you discover another project in which a file is reused. | |||||||||||||||||||||||||||
| 63 | 1 | genLValueScalarMethods(qw(source)); # The source Xml to be written to L<file|/file> and linted. | |||||||||||||||||||||||||||
| 64 | 1 | genLValueScalarMethods(qw(title)); # Optional title of the xml - only needed if you want to generate an SDL file map. | |||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | #D1 Lint # Lint xml L<files|/file> in parallel | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | sub lint($@) #P Lint a L<files|/file>, using xmllint and update the source file with the results in text format so as to be be easy to search with grep. | ||||||||||||||||||||||||||||
| 69 | 0 | ▶ | {my ($lint, %attributes) = @_; # Linter, attributes to be recorded as xml comments | ||||||||||||||||||||||||||
|
Subroutine
lint: not called CC=16 SCAR=56.1
Pod
documented
| |||||||||||||||||||||||||||||
| 70 | 0 | $lint->lineNumber = join ' ', caller; # Calling context | |||||||||||||||||||||||||||
| 71 | 0 | my $source = $lint->source; | |||||||||||||||||||||||||||
| 72 | 0 | ▶ | $source or confess "Use the source() method to provide the source xml"; # Check that we have some source | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 73 | 0 | ▶ | $lint->file or confess "Use the ->file method to provide the target file"; # Check that we have an output file | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 0 | $source =~ s/\s+\Z//gs; # Xml text to be written minus trailing blanks | |||||||||||||||||||||||||||
| 76 | 0 | my @lines = split /\n/, $source; # Split source into lines | |||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 0 | my $file = $lint->file; # File to be written to | |||||||||||||||||||||||||||
| 79 | 0 | ▶ | confess "File name contains a new line:\n$file\n" if $file =~ m/\n/s; # Complain if the source file contains a new line | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 0 | for(qw(author catalog ditaType dtds file fileNumber lineNumber), # Map parameters to attributes | |||||||||||||||||||||||||||
| 82 | qw(inputFile guid project title)) | ||||||||||||||||||||||||||||
| 83 | 0 | {my $a = $lint->$_; | |||||||||||||||||||||||||||
| 84 | 0 | ▶ | $attributes{$_} = $a if $a; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 0 | ▶ | if ($source =~ m(<!DOCTYPE)) # Source details | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 88 | 0 | {($attributes{docType}) = (grep {m(<!DOCTYPE)} @lines); | |||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | 0 | $attributes{header} = $lines[0]; | |||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | 0 | my $time = "<!--linted: ".dateTimeStamp." -->"; # Time stamp marks the start of the added comments | |||||||||||||||||||||||||||
| 93 | 0 | my $attr = &formatAttributes({%attributes}); # Attributes to be recorded with the xml | |||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | my $labels = sub # Process any labels in the parse tree | ||||||||||||||||||||||||||||
| 96 | 0 | ▶ | {return '' unless $lint->labels; # No supplied parse tree in which to finds ids and labels | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 97 | 0 | my $s = ''; # Labels as text | |||||||||||||||||||||||||||
| 98 | $lint->labels->by(sub # Search the supplied parse tree for any id or label definitions | ||||||||||||||||||||||||||||
| 99 | 0 | ▶ | {my ($o) = @_; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=8 SCAR=42.8
| |||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 0 | ▶ | if (my $i = $o->id) # Id for this node but no labels | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 102 | 0 | {$i =~ s(--) (\\-\\-)gs; # Escape any double hyphens as they are not allowed in XML comments | |||||||||||||||||||||||||||
| 103 | 0 | $s .= "<!--definition: $i -->\n"; # Id definition | |||||||||||||||||||||||||||
| 104 | 0 | ▶ | my $d = $lint->idDefs //= {}; # Id definitions for this file | ||||||||||||||||||||||||||
|
Condition0%0/2
$lint->idDefs //= {}
MC/DC0%0/1
$lint->idDefs //= {}
$lint->idDefs
Truth table0%0/2
A
A= $lint->idDefs
| |||||||||||||||||||||||||||||
| 105 | 0 | $d->{$i} = $i; # Record id definition | |||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | 0 | ▶ | if (my @labels = $o->getLabels) # Labels for this node | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 109 | 0 | {my $i = $o->id; # Id for this node | |||||||||||||||||||||||||||
| 110 | 0 | ▶ | $i or confess "No id for node with labels:\n".$o->prettyString; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | 0 | for(grep {m(\s)s} @labels) # Complain about any white space in any label as it cannot be stored in the current scheme | |||||||||||||||||||||||||||
| 113 | 0 | {lll qq(Data::Edit::Xml::Lint::lint White space in label: "$_"); | |||||||||||||||||||||||||||
| 114 | 0 | s(\s) ()gs # Remove white space | |||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | 0 | $s .= "<!--labels: $i ".join(' ', @labels)." -->\n"; | |||||||||||||||||||||||||||
| 118 | 0 | ▶ | my $l = $lint->labelDefs //= {}; # Labels for this file | ||||||||||||||||||||||||||
|
Condition0%0/2
$lint->labelDefs //= {}
MC/DC0%0/1
$lint->labelDefs //= {}
$lint->labelDefs
Truth table0%0/2
A
A= $lint->labelDefs
| |||||||||||||||||||||||||||||
| 119 | 0 | $l->{$_} = $i for @labels; # Link each label to its primary id | |||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||
| 121 | 0 | }); | |||||||||||||||||||||||||||
| 122 | 0 | $s | |||||||||||||||||||||||||||
| 123 | 0 | }->(); | |||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | my $reusedInProject = sub # Process any reused in project comments | ||||||||||||||||||||||||||||
| 126 | 0 | ▶ | {my $rip = $lint->reusedInProject; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 127 | 0 | ▶ | return '' unless $rip; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 128 | 0 | my $s = ''; | |||||||||||||||||||||||||||
| 129 | 0 | $s .= &reuseInProject($_) for @$rip; | |||||||||||||||||||||||||||
| 130 | 0 | $s | |||||||||||||||||||||||||||
| 131 | 0 | }->(); | |||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | 0 | $source .= "\n$time\n$attr\n$labels$reusedInProject"; # Xml plus comments | |||||||||||||||||||||||||||
| 134 | 0 | my $temp = writeFile(undef, $source); # Write xml to a temporary file | |||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | 0 | ▶ | if (my $v = qx(xmllint --version 2>&1)) # Check xmllint is present | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 137 | 0 | ▶ | {unless ($v =~ m(\Axmllint)is) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 138 | 0 | {confess "xmllint missing, install with:\nsudo apt-get install libxml2-utils"; | |||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||
| 141 | my $c = sub # Lint command | ||||||||||||||||||||||||||||
| 142 | 0 | ▶ | {my $p = " --noent --noout --valid"; # Suppress printed output and entity transformation, validate | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 143 | 0 | my $c = quoteFile($lint->catalog); # Catalog to use | |||||||||||||||||||||||||||
| 144 | 0 | my $r = qq(export XML_CATALOG_FILES=$c && xmllint $p - < $temp 2>&1); # Lint command | |||||||||||||||||||||||||||
| 145 | 0 | $r | |||||||||||||||||||||||||||
| 146 | 0 | }->(); | |||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | 0 | my $errors = qx($c); # Perform lint | |||||||||||||||||||||||||||
| 149 | 0 | ▶ | my @errors = $errors ? split(/\n/, $errors) : (); # Each error line | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | 0 | for my $m(@errors) # Reverse the expected and got message components as they are more useful that way around | |||||||||||||||||||||||||||
| 152 | 0 | {my @m = split /:/, $m; | |||||||||||||||||||||||||||
| 153 | 0 | ▶ | if (@m and $m[-1] =~ m(, got )s) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
@m and $m[-1] =~ /, got /s
MC/DC0%0/2
@m and $m[-1] =~ /, got /s
@m
$m[-1] =~ /, got /s
Truth table0%0/3
A and B
A= @mB= $m[-1] =~ /, got /s
| |||||||||||||||||||||||||||||
| 154 | 0 | {my $t = pop @m; | |||||||||||||||||||||||||||
| 155 | 0 | push @m, join ' ', reverse split /, got /, $t; | |||||||||||||||||||||||||||
| 156 | 0 | $m = join ':', @m; | |||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | 0 | ▶ | if (@errors and $errors !~ m(parser error : Document is empty)s) # Add errors as comments. | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
@errors and not $errors =~ /parser error : Document is empty/s
MC/DC0%0/2
@errors and not $errors =~ /parser error : Document is empty/s
@errors
not $errors =~ /parser error : Document is empty/s
Truth table0%0/3
A and not(B)
A= @errorsB= not $errors =~ /parser error : Document is empty/s
| |||||||||||||||||||||||||||||
| 161 | 0 | {my @e; # Wrap errors in comments | |||||||||||||||||||||||||||
| 162 | 0 | for my $e(@errors) # Each error | |||||||||||||||||||||||||||
| 163 | 0 | {$e =~ s(\-+) (-)gs; # Remove multiple hyphens which would prevent reparses | |||||||||||||||||||||||||||
| 164 | 0 | $e =~ s(\s*\Z) ()s; # Remove any trailing white space | |||||||||||||||||||||||||||
| 165 | 0 | $e =~ s(\n) ( )gs; # Replace in line new lines | |||||||||||||||||||||||||||
| 166 | 0 | push @e, "<!-- $e -->\n"; | |||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||
| 168 | 0 | my $e = join '', @e; # Error block | |||||||||||||||||||||||||||
| 169 | 0 | my $n = $lint->errors = int @errors / 3; # Three lines per error message | |||||||||||||||||||||||||||
| 170 | 0 | my $t = "<!--errors: $n -->"; # Number of errors | |||||||||||||||||||||||||||
| 171 | 0 | my $z = &compressErrors(@errors); # Compress the errors per Micaela | |||||||||||||||||||||||||||
| 172 | 0 | my $w = "$source\n$e\n$t$z"; # Text to write | |||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||
| 174 | 0 | overWriteFile($temp, $w); # Update xml file with errors | |||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||
| 176 | else # No errors detected | ||||||||||||||||||||||||||||
| 177 | 0 | {$lint->errors = 0; | |||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||
| 180 | 0 | makePath($file); # Create folder for file | |||||||||||||||||||||||||||
| 181 | 0 | rename $temp, $file; # Rename temporary file to obtain a more atomic rename | |||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||
| 183 | 0 | $lint | |||||||||||||||||||||||||||
| 184 | } # lint | ||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||
| 186 | sub squeezeDitaRef($) #S Squeeze a string so it can be safely stored inside blank separated list inside an xml comment. | ||||||||||||||||||||||||||||
| 187 | 0 | ▶ | {my ($ref) = @_; # String to squeeze | ||||||||||||||||||||||||||
|
Subroutine
squeezeDitaRef: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 188 | 0 | $ref =~ s((\s+|--)) (_)gsr; # Squeeze! | |||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||
| 191 | sub compressErrors(@) #PS Compress the errors so we count the ones that do not look similar. Errors typically occupy three lines with the last line containing ^ at the end to mark the location of the error. | ||||||||||||||||||||||||||||
| 192 | 0 | ▶ | {my (@errors) = @_; # Errors | ||||||||||||||||||||||||||
|
Subroutine
compressErrors: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||
| 193 | 0 | my @e; # Third lines | |||||||||||||||||||||||||||
| 194 | my %c; # Compressed errors | ||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||
| 196 | 0 | for(1..@errors) # Every third line | |||||||||||||||||||||||||||
| 197 | 0 | ▶ | {push @e, $errors[$_-1] if $_ % 3 == 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||
| 200 | # for(@e) # Reduce error line | ||||||||||||||||||||||||||||
| 201 | # {my $c = s(-:\d+?:) ()sr; # Remove line number | ||||||||||||||||||||||||||||
| 202 | # $c =~ s(\s+\^\Z) ()s; # Remove error pointer | ||||||||||||||||||||||||||||
| 203 | # $c =~ s(expect.*) ()s; # Remove expected | ||||||||||||||||||||||||||||
| 204 | # $c =~ s(\-\-+) (-)gs; # Remove multiple hyphens as they cause relint errors at 2019.05.07 03:52:28 | ||||||||||||||||||||||||||||
| 205 | # $c{$c}++; | ||||||||||||||||||||||||||||
| 206 | # } # Format compressed errors block | ||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||
| 208 | 0 | for my $e(@e) # Reduce error line | |||||||||||||||||||||||||||
| 209 | 0 | {my @c = split /:/, $e; | |||||||||||||||||||||||||||
| 210 | 0 | $c{$c[-1]}++; | |||||||||||||||||||||||||||
| 211 | } # Format compressed errors block | ||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||
| 213 | 0 | ▶ | if (my $n = scalar(keys %c)) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 214 | 0 | {my @t = (qq(<!--compressedErrors: $n -->)); # Number of errors | |||||||||||||||||||||||||||
| 215 | 0 | for my $e(sort keys %c) # Each unique reduced error line | |||||||||||||||||||||||||||
| 216 | 0 | {push @t, qq(<!--${e}-->); | |||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||
| 218 | 0 | my $t = join "\n", '', @t; | |||||||||||||||||||||||||||
| 219 | 0 | return $t; | |||||||||||||||||||||||||||
| 220 | } | ||||||||||||||||||||||||||||
| 221 | 0 | qq(<!--compressedErrors: 0 -->); # No errors | |||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||
| 224 | sub nolint($@) # Store just the attributes in a file so that they can be retrieved later to process non xml objects referenced in the xml - like images | ||||||||||||||||||||||||||||
| 225 | 0 | ▶ | {my ($lint, %attributes) = @_; # Linter, attributes to be recorded as xml comments | ||||||||||||||||||||||||||
|
Subroutine
nolint: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||
| 226 | 0 | ▶ | !$lint->source or confess "Source specified for nolint(), use lint()"; # Source not permitted for nolint() | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 227 | 0 | my $file = $lint->file; # File to be written to | |||||||||||||||||||||||||||
| 228 | 0 | ▶ | $file or confess "Use the ->file method to provide the target file"; # Check that we have an output file | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||
| 230 | # for(qw(author ditaType file guid project title)) # Map parameters to attributes | ||||||||||||||||||||||||||||
| 231 | 0 | for(qw(author catalog ditaType docType dtds errors file guid header idDefs), | |||||||||||||||||||||||||||
| 232 | qw(inputFile labelDefs labels linted processes project sha256), | ||||||||||||||||||||||||||||
| 233 | qw(source title)) | ||||||||||||||||||||||||||||
| 234 | 0 | {my $a = $lint->$_; | |||||||||||||||||||||||||||
| 235 | 0 | ▶ | $attributes{$_} = $a if $a; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||
| 238 | 0 | my $time = "<!--linted: ".dateStamp." -->\n"; # Time stamp marks the start of the added comments | |||||||||||||||||||||||||||
| 239 | 0 | my $attr = &formatAttributes({%attributes}); # Attributes to be recorded with the xml | |||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||
| 241 | 0 | ▶ | if (my $r = $lint->{reusedInProject}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 242 | 0 | {$attr .= &reuseInProject($_) for @$r; | |||||||||||||||||||||||||||
| 243 | } | ||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||
| 245 | 0 | writeFile($file, "\n$time\n$attr"); # Write attributes to file | |||||||||||||||||||||||||||
| 246 | } # nolint | ||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||
| 248 | sub formatAttributes(%) #P Format the attributes section of the output file | ||||||||||||||||||||||||||||
| 249 | 0 | ▶ | {my ($attributes) = @_; # Hash of attributes | ||||||||||||||||||||||||||
|
Subroutine
formatAttributes: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||
| 250 | 0 | my @s; | |||||||||||||||||||||||||||
| 251 | 0 | for(sort keys %$attributes) | |||||||||||||||||||||||||||
| 252 | 0 | {my $v = $attributes->{$_}; # Attribute value | |||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||
| 254 | 0 | ▶ | !defined($v) and m(docType) and confess "No doc type set for the xml to be linted"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not defined $v and /docType/
MC/DC0%0/2
not defined $v and /docType/
not defined $v
/docType/
Truth table0%0/3
not(A) and B
A= not defined $vB= /docType/
| |||||||||||||||||||||||||||||
| 255 | 0 | ▶ | defined($v) or confess "Attribute $_ has no value"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 256 | 0 | $v =~ s/--/\\-\\-/gs; # Replace -- with \-\- as -- will upset the use of xml comments to hold the data in a greppable form - but only for title - for files we need to see an error message | |||||||||||||||||||||||||||
| 257 | # $v =~ m/--/s and confess "Found -- in value of $_=>$v"; # Confess if -- present in attribute value as this will mess up the xml comments | ||||||||||||||||||||||||||||
| 258 | 0 | push @s, "<!--${_}: $v -->"; # Place attribute inside a comment | |||||||||||||||||||||||||||
| 259 | } | ||||||||||||||||||||||||||||
| 260 | 0 | join "\n", @s | |||||||||||||||||||||||||||
| 261 | } | ||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||
| 263 | sub read($) #S Reread a linted xml L<file|/file> and extract the L<attributes|/Attributes> associated with the L<lint|/lint> | ||||||||||||||||||||||||||||
| 264 | 0 | ▶ | {my ($file) = @_; # File containing xml | ||||||||||||||||||||||||||
|
Subroutine
read: not called CC=15 SCAR=54.8
Pod
documented
| |||||||||||||||||||||||||||||
| 265 | 0 | my $s = readFile($file); # Read xml from file | |||||||||||||||||||||||||||
| 266 | 0 | my %a = $s =~ m/<!--(\w+):\s+(.+?)\s+-->/igs; # Get attributes | |||||||||||||||||||||||||||
| 267 | 0 | my @a = split m/\n/, $s; # Split into lines | |||||||||||||||||||||||||||
| 268 | 0 | my $l = {}; # Reconstructed labels | |||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||
| 270 | 0 | for(@a) # Each source line | |||||||||||||||||||||||||||
| 271 | 0 | ▶ | {if (/<!--labels:\s+(.+?)\s+-->/gs) # Labels line | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 272 | 0 | {my ($w) = my @w = split /\s+/, $1; # Id, labels | |||||||||||||||||||||||||||
| 273 | 0 | $l->{$_} = $w for @w; # Associate each id and label with the id | |||||||||||||||||||||||||||
| 274 | } | ||||||||||||||||||||||||||||
| 275 | } | ||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||
| 277 | 0 | my $d = {}; # Id definitions | |||||||||||||||||||||||||||
| 278 | 0 | for(@a) # Each source line | |||||||||||||||||||||||||||
| 279 | 0 | ▶ | {if (/<!--definition:\s+(.+?)\s+-->/gs) # Definition | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 280 | 0 | {$d->{$1}++; # Record definition | |||||||||||||||||||||||||||
| 281 | 0 | $l->{$1} = $1; # An id also defines a label | |||||||||||||||||||||||||||
| 282 | } | ||||||||||||||||||||||||||||
| 283 | } | ||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||
| 285 | 0 | my $r = {}; # Reused in project | |||||||||||||||||||||||||||
| 286 | 0 | for(@a) # Each source line | |||||||||||||||||||||||||||
| 287 | 0 | ▶ | {if (/<!--reusedInProject:\s+(.+?)\s+-->/gs) # Definition | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 288 | 0 | {$r->{$1}++; # Record definition | |||||||||||||||||||||||||||
| 289 | } | ||||||||||||||||||||||||||||
| 290 | } | ||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||
| 292 | 0 | my ($S, @S) = split /(?=<!--linted:)/s, $s; # Split source on errors | |||||||||||||||||||||||||||
| 293 | 0 | ▶ | my ($U, $C) = split /(?=<!--compressedErrors:)/s, $S[-1]//''; # Split errors | ||||||||||||||||||||||||||
|
Condition0%0/2
$S[-1] // ""
MC/DC0%0/1
$S[-1] // ""
$S[-1]
Truth table0%0/2
A
A= $S[-1]
| |||||||||||||||||||||||||||||
| 294 | 0 | ▶ | my @U = $U ? split /\n+/, $U : (); # Split uncompressed errors | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 295 | 0 | ▶ | my @C = $C ? split /\n+/, $C : (); # Split compressed errors | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 296 | 0 | shift @C; # Remove the number of compressed errors | |||||||||||||||||||||||||||
| 297 | 0 | $_ = nws($_) for @C; # Normalize white space | |||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||
| 299 | 0 | my $lint = bless # Create a matching linter | |||||||||||||||||||||||||||
| 300 | {%a, # Directly loaded fields | ||||||||||||||||||||||||||||
| 301 | source => $S, # Computed fields | ||||||||||||||||||||||||||||
| 302 | # header => $a[0], # Available in end of file comments | ||||||||||||||||||||||||||||
| 303 | # docType => $a[1], | ||||||||||||||||||||||||||||
| 304 | file => $file, | ||||||||||||||||||||||||||||
| 305 | idDefs => $d, | ||||||||||||||||||||||||||||
| 306 | labels => undef, # 2019.03.16 01:42:37 property of the parse tree only | ||||||||||||||||||||||||||||
| 307 | labelDefs => $l, | ||||||||||||||||||||||||||||
| 308 | reusedInProject => [sort keys %$r], | ||||||||||||||||||||||||||||
| 309 | compressedErrorText => [@C], | ||||||||||||||||||||||||||||
| 310 | errorText => [@U], | ||||||||||||||||||||||||||||
| 311 | }; | ||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||
| 313 | 0 | ▶ | $lint->project //= q(); # Supply a default bank project | ||||||||||||||||||||||||||
|
Condition0%0/2
$lint->project //= ""
MC/DC0%0/1
$lint->project //= ""
$lint->project
Truth table0%0/2
A
A= $lint->project
| |||||||||||||||||||||||||||||
| 314 | 0 | ▶ | $lint->errors //= 0; | ||||||||||||||||||||||||||
|
Condition0%0/2
$lint->errors //= 0
MC/DC0%0/1
$lint->errors //= 0
$lint->errors
Truth table0%0/2
A
A= $lint->errors
| |||||||||||||||||||||||||||||
| 315 | 0 | ▶ | $lint->compressedErrors //= 0; | ||||||||||||||||||||||||||
|
Condition0%0/2
$lint->compressedErrors //= 0
MC/DC0%0/1
$lint->compressedErrors //= 0
$lint->compressedErrors
Truth table0%0/2
A
A= $lint->compressedErrors
| |||||||||||||||||||||||||||||
| 316 | 0 | $lint # Return a matching linter | |||||||||||||||||||||||||||
| 317 | } # read | ||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||
| 319 | sub reload($) # Reload a parse tree from a linted file restoring any labels and return the parse tree or B<undef> if the file is not a lint file. | ||||||||||||||||||||||||||||
| 320 | 0 | ▶ | {my ($file) = @_; # File to read | ||||||||||||||||||||||||||
|
Subroutine
reload: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||
| 322 | 0 | ▶ | return undef unless my $l = &read($file); # Read lint file or fail | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 323 | 0 | my %labels; # Labels for each id | |||||||||||||||||||||||||||
| 324 | 0 | my %labelDefs = %{$l->labelDefs}; # Label definitions | |||||||||||||||||||||||||||
| 325 | 0 | for my $label(sort keys %labelDefs) # Each label definition | |||||||||||||||||||||||||||
| 326 | 0 | {my $id = $labelDefs{$label}; # Id for label | |||||||||||||||||||||||||||
| 327 | 0 | ▶ | if ($id ne $label) # Ignore self definitions | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 328 | 0 | {push @{$labels{$id}}, $label; # Map id to labels | |||||||||||||||||||||||||||
| 329 | } | ||||||||||||||||||||||||||||
| 330 | } | ||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||
| 332 | 0 | my $x = Data::Edit::Xml::new($l->source); # Parse source which is assumed to be parseable as it has been linted | |||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||
| 334 | $x->by(sub # Restore labels at each id | ||||||||||||||||||||||||||||
| 335 | 0 | ▶ | {my ($o) = @_; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 336 | 0 | ▶ | if (my $i = $o->id) # Node has an id | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 337 | 0 | ▶ | {if (my $labels = $labels{$i}) # Id has labels | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 338 | 0 | {$o->addLabels(@$labels); # Restore labels for id | |||||||||||||||||||||||||||
| 339 | } | ||||||||||||||||||||||||||||
| 340 | } | ||||||||||||||||||||||||||||
| 341 | 0 | }); | |||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||
| 343 | 0 | $x # Return restored parse tree | |||||||||||||||||||||||||||
| 344 | } | ||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||
| 346 | sub lintAttributes($) #S Get all the attributes minus the source of all the linted files in the specified folder | ||||||||||||||||||||||||||||
| 347 | 0 | ▶ | {my ($folder) = @_; # Folder to search | ||||||||||||||||||||||||||
|
Subroutine
lintAttributes: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||
| 348 | 0 | my @l; | |||||||||||||||||||||||||||
| 349 | 0 | my @f = searchDirectoryTreesForMatchingFiles($folder); # All files | |||||||||||||||||||||||||||
| 350 | 0 | for my $file(@f) # Each file | |||||||||||||||||||||||||||
| 351 | 0 | ▶ | {next unless $file =~ m(\.(dita(map)?|xml)\Z)s; # Skip files that are not xml files | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 352 | 0 | ▶ | if (my $l = &read($file)) # Load lint details if possible | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 353 | 0 | {delete $$l{$_} for qw(errorText preferredSource source); # Remove attributes that take a lot of space | |||||||||||||||||||||||||||
| 354 | 0 | push @l, $l; | |||||||||||||||||||||||||||
| 355 | } | ||||||||||||||||||||||||||||
| 356 | } | ||||||||||||||||||||||||||||
| 357 | @l # Lint attributes array | ||||||||||||||||||||||||||||
| 358 | 0 | } | |||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||
| 360 | sub relint($$$@) #S Locate all the L<labels or id|Data::Edit::Xml/Labels> in the specified L<files|/file>, analyze the map of labels and ids with B<analysisSub> parse each L<file|/file>, process each parse with B<processSub>, then L<lint/lint> the reprocessed xml back to the original L<file|/file> - this allows you to reprocess the contents of each L<file|/file> with knowledge of where L<labels or id|Data::Edit::Xml/Labels> are located in the other L<files|/file> associated with a L<project|/project>. The B<analysisSub>(linkmap = {project}{labels or id>}=[file, id]) should return true if the processing of each file is to be performed subsequently. The B<processSub>(parse tree representation of a file, id and label mapping, reloaded linter) should return true if a L<lint|/lint> is required to save the results after each L<file|/file> has been processed else false. Optionally, the B<analysisSub> may set the L<preferredSource|/preferredSource> attribute to indicate the preferred representation of the xml. | ||||||||||||||||||||||||||||
| 361 | 0 | ▶ | {my ($processes, $analysisSub, $processSub, @foldersAndExtensions) = @_; # Maximum number of processes to use, analysis 𝘀𝘂𝗯, Process 𝘀𝘂𝗯, folders and extensions of files to process (recursively) | ||||||||||||||||||||||||||
|
Subroutine
relint: not called CC=13 SCAR=52.0
Pod
documented
| |||||||||||||||||||||||||||||
| 362 | 0 | my @files = searchDirectoryTreesForMatchingFiles(@foldersAndExtensions); # Search for files to relint | |||||||||||||||||||||||||||
| 363 | 0 | my $links; # {project}{label or id} = [file, label or id] : the file containing each label or id in each project | |||||||||||||||||||||||||||
| 364 | my $fileToGuid; # {file name} to guid | ||||||||||||||||||||||||||||
| 365 | 0 | my $files = @files; | |||||||||||||||||||||||||||
| 366 | 0 | for my $i(keys @files) # Reload each file to reprocess | |||||||||||||||||||||||||||
| 367 | 0 | {my $file = $files[$i]; | |||||||||||||||||||||||||||
| 368 | #lll " $i/$files Data::Edit::Xml::Lint::relint file: $file"; | ||||||||||||||||||||||||||||
| 369 | |||||||||||||||||||||||||||||
| 370 | 0 | my $lint = Data::Edit::Xml::Lint::read($file); # Reconstructed linter | |||||||||||||||||||||||||||
| 371 | |||||||||||||||||||||||||||||
| 372 | 0 | ▶ | next unless $lint->project; # File has the right format | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 373 | 0 | ▶ | if (my $g = $lint->guid) # Record file to guid mapping | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 374 | 0 | ▶ | {if (my $lintFile = $lint->file) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 375 | 0 | ▶ | {if (my $G = $fileToGuid->{$lintFile}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 376 | 0 | ▶ | {if ($g ne $G) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 377 | 0 | {confess "Guids $g and $G are both used for file $lintFile" | |||||||||||||||||||||||||||
| 378 | } | ||||||||||||||||||||||||||||
| 379 | } | ||||||||||||||||||||||||||||
| 380 | else | ||||||||||||||||||||||||||||
| 381 | 0 | {$fileToGuid->{$lintFile} = $g; | |||||||||||||||||||||||||||
| 382 | } | ||||||||||||||||||||||||||||
| 383 | } | ||||||||||||||||||||||||||||
| 384 | 0 | else {confess "No file name attribute in $file"} | |||||||||||||||||||||||||||
| 385 | } | ||||||||||||||||||||||||||||
| 386 | else # Get last id defined as topic id if no topic id has been explicitly set via guid | ||||||||||||||||||||||||||||
| 387 | 0 | {$fileToGuid->{$file} = $lint->{definition}; | |||||||||||||||||||||||||||
| 388 | } | ||||||||||||||||||||||||||||
| 389 | |||||||||||||||||||||||||||||
| 390 | 0 | ▶ | if (my $p = $lint->project) # Save location of labels and ids in all files by L<project|/project> | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 391 | 0 | ▶ | {if (my $l = $lint->labelDefs) # Labels and ids defined in this file | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 392 | 0 | {for my $label(keys %$l) # Each label or id defined in this file | |||||||||||||||||||||||||||
| 393 | 0 | {my $target = [$file, $l->{$label}]; # [File, leading label == id] for this label | |||||||||||||||||||||||||||
| 394 | 0 | push @{$links->{$p}{$label}}, $target; # Construct a hash of array refs which tell us the locations = [file, id] of every label and id over all the input files in the L<project|/project> | |||||||||||||||||||||||||||
| 395 | 0 | for my $r(@{$lint->reusedInProject}) # Each project that this link is reused in | |||||||||||||||||||||||||||
| 396 | 0 | {push @{$links->{$r}{$label}}, $target; # Copy targets into reused project | |||||||||||||||||||||||||||
| 397 | } | ||||||||||||||||||||||||||||
| 398 | } | ||||||||||||||||||||||||||||
| 399 | } | ||||||||||||||||||||||||||||
| 400 | } | ||||||||||||||||||||||||||||
| 401 | } | ||||||||||||||||||||||||||||
| 402 | |||||||||||||||||||||||||||||
| 403 | #lll "Data::Edit::Xml::Lint::relint: Linkmap completed"; # Progress | ||||||||||||||||||||||||||||
| 404 | |||||||||||||||||||||||||||||
| 405 | 0 | ▶ | if ($analysisSub->($links, $fileToGuid)) # Analyze links and guids | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 406 | 0 | {my $ps = newProcessStarter($processes); # Process starter | |||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||
| 408 | 0 | for my $i(keys @files) # Reload, reparse, process, lint each file | |||||||||||||||||||||||||||
| 409 | 0 | {my $file = $files[$i]; | |||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||
| 411 | $ps->start(sub # Process in parallel | ||||||||||||||||||||||||||||
| 412 | 0 | ▶ | {my $lint = Data::Edit::Xml::Lint::read($file); # Reconstructed linter | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=10 SCAR=47.0
| |||||||||||||||||||||||||||||
| 413 | 0 | ▶ | confess "Unable to read lint data for file: $file\n" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 414 | unless $lint;# and $lint->project; # Confirm that we read a file in the expected format | ||||||||||||||||||||||||||||
| 415 | 0 | ▶ | confess "No source for file: $file\n" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 416 | unless $lint->source; # Files without source are assumed to have been written to store some attributes | ||||||||||||||||||||||||||||
| 417 | |||||||||||||||||||||||||||||
| 418 | 0 | my $x = eval{Data::Edit::Xml::new($lint->source)}; # Reparse source trapping errors | |||||||||||||||||||||||||||
| 419 | 0 | ▶ | $@ and confess "$@\nFailed to parse file:\n$file\n"; # Xml file failed to parse | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 420 | 0 | ▶ | !$x and confess "Failed to parse file:\n$file\n"; # Xml file failed to parse | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 421 | |||||||||||||||||||||||||||||
| 422 | 0 | ▶ | if (my $links = $lint->labelDefs) # Reload labels | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 423 | 0 | {my $r; # {primary id}[label] | |||||||||||||||||||||||||||
| 424 | 0 | for my $source(sort keys %$links) # Construct primary id to labels | |||||||||||||||||||||||||||
| 425 | 0 | {my $target = $links->{$source}; | |||||||||||||||||||||||||||
| 426 | 0 | ▶ | push @{$r->{$target}}, $source unless $source eq $target; # No need to reverse the primary id | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 427 | } | ||||||||||||||||||||||||||||
| 428 | |||||||||||||||||||||||||||||
| 429 | $x->by(sub # Reload labels | ||||||||||||||||||||||||||||
| 430 | 0 | ▶ | {my ($o) = @_; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||
| 431 | 0 | ▶ | if (defined($o->attr(qw(id))) and my $i = $o->id) # Id if defined | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $o->attr("id") and my $i = $o->id
MC/DC0%0/2
defined $o->attr("id") and my $i = $o->id
defined $o->attr("id")
my $i = $o->id
Truth table0%0/3
A and B
A= defined $o->attr("id")B= my $i = $o->id
| |||||||||||||||||||||||||||||
| 432 | 0 | ▶ | {if (my $labels = $r->{$i}) # Labels for this id if present | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 433 | 0 | {for my $label(@$labels) # Each label for this id | |||||||||||||||||||||||||||
| 434 | 0 | {$o->addLabels($label); # Add the label | |||||||||||||||||||||||||||
| 435 | } | ||||||||||||||||||||||||||||
| 436 | } | ||||||||||||||||||||||||||||
| 437 | } | ||||||||||||||||||||||||||||
| 438 | 0 | }); | |||||||||||||||||||||||||||
| 439 | } | ||||||||||||||||||||||||||||
| 440 | |||||||||||||||||||||||||||||
| 441 | 0 | ▶ | if ($processSub->($x, $links->{$lint->project}, $fileToGuid, $lint)) # Call user method to process parse tree with labels in place and the location of all the labels and ids | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 442 | 0 | {my $l = $lint; # Shorten name | |||||||||||||||||||||||||||
| 443 | 0 | ▶ | my $s = $l->preferredSource // $x->prettyString; # Representation of xml | ||||||||||||||||||||||||||
|
Condition0%0/3
$l->preferredSource // $x->prettyString
MC/DC0%0/2
$l->preferredSource // $x->prettyString
$l->preferredSource
$x->prettyString
Truth table0%0/3
A // B
A= $l->preferredSourceB= $x->prettyString
| |||||||||||||||||||||||||||||
| 444 | 0 | $l->source = join "\n", $l->header, $l->docType, $s; # Reconstruct source | |||||||||||||||||||||||||||
| 445 | 0 | $l->labels = $x; # Associated parse tree so we can save the labels | |||||||||||||||||||||||||||
| 446 | 0 | my %a = map {$_=>$l->{$_}} grep{!($l->can($_))} keys %$l; # Reconstruct attributes as this items which do not have a method attached | |||||||||||||||||||||||||||
| 447 | |||||||||||||||||||||||||||||
| 448 | 0 | $l->lint(%a); # Lint reprocessed source | |||||||||||||||||||||||||||
| 449 | } | ||||||||||||||||||||||||||||
| 450 | 0 | }); | |||||||||||||||||||||||||||
| 451 | } | ||||||||||||||||||||||||||||
| 452 | 0 | $ps->finish; | |||||||||||||||||||||||||||
| 453 | } | ||||||||||||||||||||||||||||
| 454 | } # relint | ||||||||||||||||||||||||||||
| 455 | |||||||||||||||||||||||||||||
| 456 | sub resolveUniqueLink($$) #S Return the unique (file, leading id) of the specified link in the link map or () if no such definition exists | ||||||||||||||||||||||||||||
| 457 | 0 | ▶ | {my ($linkMap, $link) = @_; # Link map, label | ||||||||||||||||||||||||||
|
Subroutine
resolveUniqueLink: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 458 | 0 | ▶ | if ($link =~ m(\s)s) # Complain about any white space in the label | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 459 | 0 | {cluck "White space in label removed: $link"; | |||||||||||||||||||||||||||
| 460 | 0 | $link =~ s(\s) ()gs; # Remove white space from label | |||||||||||||||||||||||||||
| 461 | } | ||||||||||||||||||||||||||||
| 462 | 0 | my $l = $linkMap->{$link}; # Attempt to resolve link | |||||||||||||||||||||||||||
| 463 | 0 | ▶ | return () unless $l; # No definition | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 464 | 0 | ▶ | return () if @$l != 1; # Too many definitions | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 465 | 0 | @{$l->[0]} # (file, leading id) | |||||||||||||||||||||||||||
| 466 | } # resolveUniqueLink | ||||||||||||||||||||||||||||
| 467 | |||||||||||||||||||||||||||||
| 468 | sub urlEncode($) #S Return a url encoded string | ||||||||||||||||||||||||||||
| 469 | 0 | ▶ | {my ($s) = @_; # String | ||||||||||||||||||||||||||
|
Subroutine
urlEncode: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 470 | 0 | $s =~ s(\s) (%20)gsr; | |||||||||||||||||||||||||||
| 471 | } | ||||||||||||||||||||||||||||
| 472 | |||||||||||||||||||||||||||||
| 473 | sub resolveDitaLink($$$$) #S Given a specified B<$link>Return the unique (file, leading id, topic ) of the specified link in the link map or () if no such definition exists | ||||||||||||||||||||||||||||
| 474 | 0 | ▶ | {my ($linkMap, $fileToGuid, $link, $sourceFile) = @_; # Link map, file map, label, file we are resolving from | ||||||||||||||||||||||||||
|
Subroutine
resolveDitaLink: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||
| 475 | |||||||||||||||||||||||||||||
| 476 | 0 | ▶ | if ($link =~ m(\s)s) # Complain about any white space in the label | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 477 | 0 | {cluck "White space in label removed: $link"; | |||||||||||||||||||||||||||
| 478 | 0 | $link =~ s(\s) ()gs; # Remove white space from label | |||||||||||||||||||||||||||
| 479 | } | ||||||||||||||||||||||||||||
| 480 | |||||||||||||||||||||||||||||
| 481 | 0 | ▶ | if (my $l = $linkMap->{$link}) # Attempt to resolve link | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 482 | 0 | ▶ | {if (@$l == 1) # Require a unique target | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 483 | 0 | {my ($targetFile, $id) = @{$l->[0]}; # (file, id) | |||||||||||||||||||||||||||
| 484 | |||||||||||||||||||||||||||||
| 485 | 0 | ▶ | if (my $topicId = $fileToGuid->{$targetFile}) # Topic id for target file | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 486 | 0 | ▶ | {if ($sourceFile eq $targetFile) # Link in same file | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 487 | 0 | {return urlEncode("#$topicId/$id"); | |||||||||||||||||||||||||||
| 488 | } | ||||||||||||||||||||||||||||
| 489 | else # Link to a different file | ||||||||||||||||||||||||||||
| 490 | 0 | {my $f = $targetFile =~ s(\A.*\/) ()r; | |||||||||||||||||||||||||||
| 491 | 0 | ▶ | if ($topicId ne $id) # Link to sub topic in different file | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 492 | 0 | {return urlEncode("$f#$topicId/$id"); | |||||||||||||||||||||||||||
| 493 | } | ||||||||||||||||||||||||||||
| 494 | else # Link to topic in different file | ||||||||||||||||||||||||||||
| 495 | 0 | {return urlEncode("$f#$topicId"); | |||||||||||||||||||||||||||
| 496 | } | ||||||||||||||||||||||||||||
| 497 | } | ||||||||||||||||||||||||||||
| 498 | } | ||||||||||||||||||||||||||||
| 499 | else | ||||||||||||||||||||||||||||
| 500 | 0 | {warn "Data::Edit::Xml::Lint No topic id recorded for file $targetFile"; | |||||||||||||||||||||||||||
| 501 | } | ||||||||||||||||||||||||||||
| 502 | } | ||||||||||||||||||||||||||||
| 503 | else | ||||||||||||||||||||||||||||
| 504 | 0 | {warn "Data::Edit::Xml::Lint Not a unique link =$link=\n"; | |||||||||||||||||||||||||||
| 505 | } | ||||||||||||||||||||||||||||
| 506 | } | ||||||||||||||||||||||||||||
| 507 | else | ||||||||||||||||||||||||||||
| 508 | 0 | {warn "Data::Edit::Xml::Lint No such link =$link=\n"; # Xref will report any failures in detail | |||||||||||||||||||||||||||
| 509 | } | ||||||||||||||||||||||||||||
| 510 | undef # Resolution failed | ||||||||||||||||||||||||||||
| 511 | 0 | } # resolveDitaLink; | |||||||||||||||||||||||||||
| 512 | |||||||||||||||||||||||||||||
| 513 | sub reuseInProject($) #PS Record the reuse of an item in the named project | ||||||||||||||||||||||||||||
| 514 | 0 | ▶ | {my ($project) = @_; # Name of the project in which it is reused | ||||||||||||||||||||||||||
|
Subroutine
reuseInProject: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 515 | 0 | qq(\n<!--reusedInProject: $project -->); | |||||||||||||||||||||||||||
| 516 | } | ||||||||||||||||||||||||||||
| 517 | |||||||||||||||||||||||||||||
| 518 | sub reuseFileInProject($$) #S Record the reuse of the specified file in the specified project | ||||||||||||||||||||||||||||
| 519 | 0 | ▶ | {my ($file, $project) = @_; # Name of file that is being reused, name of project in which it is reused | ||||||||||||||||||||||||||
|
Subroutine
reuseFileInProject: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 520 | 0 | appendFile($file, reuseInProject($project)); # Add a reuse record to the file being reused. | |||||||||||||||||||||||||||
| 521 | } | ||||||||||||||||||||||||||||
| 522 | |||||||||||||||||||||||||||||
| 523 | sub countLinkTargets($$) #PS Count the number of targets this link resolves to. | ||||||||||||||||||||||||||||
| 524 | 0 | ▶ | {my ($linkMap, $link) = @_; # Link map, label | ||||||||||||||||||||||||||
|
Subroutine
countLinkTargets: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 525 | 0 | my $l = $linkMap->{$link}; # Attempt to resolve link | |||||||||||||||||||||||||||
| 526 | 0 | ▶ | return 0 unless $l; # No definition | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 527 | 0 | scalar @$l; # Definition count | |||||||||||||||||||||||||||
| 528 | } # countLinkTargets | ||||||||||||||||||||||||||||
| 529 | |||||||||||||||||||||||||||||
| 530 | sub resolveFileToGuid($$) #S Return the unique definition of the specified link in the link map or undef if no such definition exists | ||||||||||||||||||||||||||||
| 531 | 0 | ▶ | {my ($fileToGuids, $file) = @_; # File to guids map, file | ||||||||||||||||||||||||||
|
Subroutine
resolveFileToGuid: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 532 | 0 | $fileToGuids->{$file}; # Attempt to resolve file | |||||||||||||||||||||||||||
| 533 | } # resolveFileToGuid | ||||||||||||||||||||||||||||
| 534 | |||||||||||||||||||||||||||||
| 535 | sub multipleLabelDefs($) #S Return ([L<project|/project>; L<source label or id|Data::Edit::Xml/Labels>; targets count]*) of all L<labels or id|Data::Edit::Xml/Labels> that have multiple definitions | ||||||||||||||||||||||||||||
| 536 | 0 | ▶ | {my ($labelDefs) = @_; # Label definitions | ||||||||||||||||||||||||||
|
Subroutine
multipleLabelDefs: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||
| 537 | 0 | ▶ | return () unless $labelDefs; # Label and Id definitions | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 538 | 0 | ▶ | ref($labelDefs) =~ /hash/is or confess "No labelDefs provided"; # Check definitions have been provided | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 539 | |||||||||||||||||||||||||||||
| 540 | 0 | my @multipleLabelDefs; # Labels or ids with multiple definitions | |||||||||||||||||||||||||||
| 541 | 0 | for my $project(sort keys % $labelDefs) # Sub(linkmap = {L<project|/project>}{L<label or id|Data::Edit::Xml/Labels}=[L<file|/file>; id]) returns true if the processing of each L<file|/file> is to be performed after the link mapping has been analyzed at the start, Sub(L<parse tree representation of a file|Data::Edit::Xml>, linkmap, reloaded L<linter|Data::Edit::Xml::Lint>) returns true if a L<lint|/lint> is required after each L<file|/file> has been processed, L<files|/file> to reprocess | |||||||||||||||||||||||||||
| 542 | 0 | {for my $label(sort keys %{$labelDefs->{$project}}) # Each source label or id | |||||||||||||||||||||||||||
| 543 | 0 | ▶ | {if (my $l = $labelDefs->{$project}{$label}) # Source label or id | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 544 | 0 | ▶ | {push @multipleLabelDefs, [$project, $label, $l] if @$l > 1; # Ids or labels with multiple definitions | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 545 | } | ||||||||||||||||||||||||||||
| 546 | } | ||||||||||||||||||||||||||||
| 547 | } | ||||||||||||||||||||||||||||
| 548 | |||||||||||||||||||||||||||||
| 549 | @multipleLabelDefs | ||||||||||||||||||||||||||||
| 550 | 0 | } # multipleLabelDefs | |||||||||||||||||||||||||||
| 551 | |||||||||||||||||||||||||||||
| 552 | sub multipleLabelDefsReport($) #S Return a L<report|/report> showing L<labels and id|Data::Edit::Xml/Labels> with multiple definitions in each L<project|/project> ordered by most defined | ||||||||||||||||||||||||||||
| 553 | 0 | ▶ | {my ($labelDefs) = @_; # Label and Id definitions | ||||||||||||||||||||||||||
|
Subroutine
multipleLabelDefsReport: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 554 | |||||||||||||||||||||||||||||
| 555 | 0 | ▶ | if (my @m = Data::Edit::Xml::Lint::multipleLabelDefs # Find multiple label or id definitions | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 556 | ($labelDefs)) | ||||||||||||||||||||||||||||
| 557 | 0 | {$_->[2] = scalar(@{$_->[2]}) for @m; # Replace array of multiple definitions with count thereof | |||||||||||||||||||||||||||
| 558 | 0 | my $m = @m; | |||||||||||||||||||||||||||
| 559 | return "MultipleLabelOrIdDefinitions ($m):\n".formatTable # Zero multiple label or id definitions | ||||||||||||||||||||||||||||
| 560 | ([[qw(Project Label Count)], | ||||||||||||||||||||||||||||
| 561 | 0 | sort {$b->[2] <=> $a->[2]} @m # Sort so that the most frequent are first | |||||||||||||||||||||||||||
| 562 | ]); | ||||||||||||||||||||||||||||
| 563 | } | ||||||||||||||||||||||||||||
| 564 | 'No MultipleLabelOrIdDefinitions' # Zero multiple label or id definitions | ||||||||||||||||||||||||||||
| 565 | 0 | } # multipleLabelDefsReport | |||||||||||||||||||||||||||
| 566 | |||||||||||||||||||||||||||||
| 567 | sub singleLabelDefs($) #S Return ([L<project|/project>; label or id]*) of all labels or ids that have a single definition | ||||||||||||||||||||||||||||
| 568 | 0 | ▶ | {my ($labelDefs) = @_; # Label and Id definitions | ||||||||||||||||||||||||||
|
Subroutine
singleLabelDefs: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||
| 569 | 0 | ▶ | $labelDefs and ref($labelDefs) =~ /hash/is or # Check definitions have been provided | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$labelDefs and ref($labelDefs) =~ /hash/is
MC/DC0%0/2
$labelDefs and ref($labelDefs) =~ /hash/is
$labelDefs
ref($labelDefs) =~ /hash/is
Truth table0%0/3
A and B
A= $labelDefsB= ref($labelDefs) =~ /hash/is
| |||||||||||||||||||||||||||||
| 570 | confess "No labelDefs provided"; | ||||||||||||||||||||||||||||
| 571 | 0 | my @singleLabelDefs; # Labels or ids with just one definition | |||||||||||||||||||||||||||
| 572 | 0 | for my $project(sort keys % $labelDefs) # Sub(linkmap = {L<project/>}{L<label or id|Data::Edit::Xml/Labels>}=[</file>; id]) returns true if the processing of each L<file|/file> is to be performed after the link mapping has been analyzed at the start, Sub(L<parse tree representation of a file|Data::Edit::Xml>, linkmap, L<reloaded linter|Data::Edit::Xml::Lint>) returns true if a L<lint|/lint> is required after each L<file|/file> has been processed, L<files|/file> to reprocess | |||||||||||||||||||||||||||
| 573 | 0 | {for my $label(sort keys %{$labelDefs->{$project}}) # Each source label or id | |||||||||||||||||||||||||||
| 574 | 0 | ▶ | {if (my $l = $labelDefs->{$project}{$label}) # Source label or id | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 575 | 0 | ▶ | {push @singleLabelDefs, [$project, $label] if @$l == 1; # Ids or labels with just one definition | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 576 | } | ||||||||||||||||||||||||||||
| 577 | } | ||||||||||||||||||||||||||||
| 578 | } | ||||||||||||||||||||||||||||
| 579 | |||||||||||||||||||||||||||||
| 580 | @singleLabelDefs | ||||||||||||||||||||||||||||
| 581 | 0 | } # singleLabelDefs | |||||||||||||||||||||||||||
| 582 | |||||||||||||||||||||||||||||
| 583 | sub singleLabelDefsReport($) #S Return a L<report|/report> showing L<label or id|Data::Edit::Xml/Labels> with just one definitions ordered by L<project|/project>, L<label name|Data::Edit::Xml/Labels> | ||||||||||||||||||||||||||||
| 584 | 0 | ▶ | {my ($labelDefs) = @_; # Label and Id definitions | ||||||||||||||||||||||||||
|
Subroutine
singleLabelDefsReport: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 585 | |||||||||||||||||||||||||||||
| 586 | 0 | ▶ | if (my @s = Data::Edit::Xml::Lint::singleLabelDefs # Find single label or id definitions | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 587 | ($labelDefs)) | ||||||||||||||||||||||||||||
| 588 | 0 | {my $s = @s; | |||||||||||||||||||||||||||
| 589 | return "SingleLabelOrIdDefinitions ($s):\n".formatTable | ||||||||||||||||||||||||||||
| 590 | ([[qw(Project Label)], | ||||||||||||||||||||||||||||
| 591 | sort # Sort by project and label | ||||||||||||||||||||||||||||
| 592 | 0 | {my $p = $a->[0] cmp $b->[0]; | |||||||||||||||||||||||||||
| 593 | 0 | my $l = $a->[1] cmp $b->[1]; | |||||||||||||||||||||||||||
| 594 | 0 | ▶ | return $p if $p; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 595 | $l | ||||||||||||||||||||||||||||
| 596 | } @s | ||||||||||||||||||||||||||||
| 597 | ]); | ||||||||||||||||||||||||||||
| 598 | } | ||||||||||||||||||||||||||||
| 599 | 'No SingleLabelOrIdDefinitions' # Zero multiple label or id definitions | ||||||||||||||||||||||||||||
| 600 | 0 | } # singleOrIdDefinitionsReport | |||||||||||||||||||||||||||
| 601 | |||||||||||||||||||||||||||||
| 602 | |||||||||||||||||||||||||||||
| 603 | #D1 Report # Methods for L<reporting|Data::Edit::Xml::Lint/report> the results of L<linting|/lint> several L<files|/file> | ||||||||||||||||||||||||||||
| 604 | |||||||||||||||||||||||||||||
| 605 | sub p4($$) #PS Format a fraction as a percentage to 4 decimal places | ||||||||||||||||||||||||||||
| 606 | 0 | ▶ | {my ($p, $f) = @_; # Pass, fail | ||||||||||||||||||||||||||
|
Subroutine
p4: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 607 | 0 | my $n = $p + $f; | |||||||||||||||||||||||||||
| 608 | 0 | ▶ | return 0 if $n == 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 609 | 0 | ▶ | $n > 0 or confess "Division by zero"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 610 | 0 | my $r = sprintf("%3.4f", 100 * $p / $n); | |||||||||||||||||||||||||||
| 611 | 0 | $r =~ s/\.0+\Z//gsr # Remove trailing zeroes | |||||||||||||||||||||||||||
| 612 | } | ||||||||||||||||||||||||||||
| 613 | |||||||||||||||||||||||||||||
| 614 | sub report($;$) #S Analyze the results of prior L<lints|/lint> and return a hash reporting various statistics and a L<printable|/print> report | ||||||||||||||||||||||||||||
| 615 | 0 | ▶ | {my ($outputDirectory, $filter) = @_; # Directory to search, optional regular expression to filter files | ||||||||||||||||||||||||||
|
Subroutine
report: not called CC=32 SCAR=69.6
Pod
documented
| |||||||||||||||||||||||||||||
| 616 | |||||||||||||||||||||||||||||
| 617 | 0 | my @x; # Lints for all L<files|/file> | |||||||||||||||||||||||||||
| 618 | 0 | for my $in(findFiles($outputDirectory)) # Find files to report on | |||||||||||||||||||||||||||
| 619 | 0 | ▶ | {next if $filter and $in !~ m($filter); # Filter files if a filter has been supplied | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$filter and not $in =~ /$filter/
MC/DC0%0/2
$filter and not $in =~ /$filter/
$filter
not $in =~ /$filter/
Truth table0%0/3
A and not(B)
A= $filterB= not $in =~ /$filter/
| |||||||||||||||||||||||||||||
| 620 | 0 | push @x, Data::Edit::Xml::Lint::read($in); # Reload a previously written L<file|/file> | |||||||||||||||||||||||||||
| 621 | } | ||||||||||||||||||||||||||||
| 622 | |||||||||||||||||||||||||||||
| 623 | 0 | ▶ | lll "No files selected" unless @x; # No files selected | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 624 | 0 | ▶ | return undef unless @x; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 625 | |||||||||||||||||||||||||||||
| 626 | 0 | my %projects; # Pass/Fail by project | |||||||||||||||||||||||||||
| 627 | my %files; # Pass fail by file | ||||||||||||||||||||||||||||
| 628 | 0 | my %filesToProjects; # Project from file name | |||||||||||||||||||||||||||
| 629 | 0 | my $totalErrors = 0; # Total number of errors | |||||||||||||||||||||||||||
| 630 | 0 | my $totalCompressedErrorsFileByFile = 0; # Total number of errors summed file by file | |||||||||||||||||||||||||||
| 631 | 0 | my %examples; # Compressed errors example files | |||||||||||||||||||||||||||
| 632 | my %docTypes; # Document types | ||||||||||||||||||||||||||||
| 633 | |||||||||||||||||||||||||||||
| 634 | 0 | for my $x(@x) # Aggregate the results of individual lints | |||||||||||||||||||||||||||
| 635 | 0 | {my $file = $x->file; | |||||||||||||||||||||||||||
| 636 | 0 | ▶ | next unless $file; # Not in the expected format | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 637 | 0 | ▶ | my $project = $x->project // 'unknown'; | ||||||||||||||||||||||||||
|
Condition0%0/2
$x->project // "unknown"
MC/DC0%0/1
$x->project // "unknown"
$x->project
Truth table0%0/2
A
A= $x->project
| |||||||||||||||||||||||||||||
| 638 | 0 | my $cErrors = $x->compressedErrors; # Compressed errors | |||||||||||||||||||||||||||
| 639 | 0 | my $errors = $x->errors; # Number of uncompressed errors | |||||||||||||||||||||||||||
| 640 | 0 | my $cet = $x->compressedErrorText; # Compressed errors | |||||||||||||||||||||||||||
| 641 | 0 | my $et = $x->errorText; # Uncompressed error text | |||||||||||||||||||||||||||
| 642 | 0 | $filesToProjects{$file} = $project; | |||||||||||||||||||||||||||
| 643 | 0 | ▶ | my $pf = $errors ? qq(fail) : qq(pass); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 644 | 0 | $projects{$project}{$pf}++; | |||||||||||||||||||||||||||
| 645 | 0 | $files{$file} = $cErrors; | |||||||||||||||||||||||||||
| 646 | 0 | $totalErrors += $errors; | |||||||||||||||||||||||||||
| 647 | 0 | $totalCompressedErrorsFileByFile += $cErrors; | |||||||||||||||||||||||||||
| 648 | |||||||||||||||||||||||||||||
| 649 | 0 | ▶ | if ($cet) # Compressed errors over all files | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 650 | 0 | {for my $message(@$cet) | |||||||||||||||||||||||||||
| 651 | 0 | {$message =~ s(\A<!--) ()gs; # Remove xml comments | |||||||||||||||||||||||||||
| 652 | 0 | $message =~ s(-->\Z) ()gs; | |||||||||||||||||||||||||||
| 653 | 0 | $message =~ s(\s*\x29) (\x29)gs; | |||||||||||||||||||||||||||
| 654 | 0 | $message = deduplicateSequentialWordsInString($message); # Remove duplicate sequential words in message | |||||||||||||||||||||||||||
| 655 | |||||||||||||||||||||||||||||
| 656 | 0 | my $m = firstNChars $message, maxLintMsgLength; # Limit the length of messages to make the report more readable and collect similar errors together. | |||||||||||||||||||||||||||
| 657 | 0 | $examples{$m}{$file}++ # Files that exhibit this message | |||||||||||||||||||||||||||
| 658 | } | ||||||||||||||||||||||||||||
| 659 | } | ||||||||||||||||||||||||||||
| 660 | 0 | ▶ | if (my $d = $x->docType) # Document type summary | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 661 | 0 | ▶ | {$docTypes{(split /\s+/, $d)[1]//$d}++; | ||||||||||||||||||||||||||
|
Condition0%0/3
(split(/\s+/, $d, 0))[1] // $d
MC/DC0%0/2
(split(/\s+/, $d, 0))[1] // $d
(split(/\s+/, $d, 0))[1]
$d
Truth table0%0/3
A // B
A= (split(/\s+/, $d, 0))[1]B= $d
| |||||||||||||||||||||||||||||
| 662 | } | ||||||||||||||||||||||||||||
| 663 | } | ||||||||||||||||||||||||||||
| 664 | |||||||||||||||||||||||||||||
| 665 | 0 | my @passingProjects; | |||||||||||||||||||||||||||
| 666 | my @failingProjects; | ||||||||||||||||||||||||||||
| 667 | 0 | for my $project(sort keys %projects) # Count pass/fail files by project | |||||||||||||||||||||||||||
| 668 | 0 | ▶ | {my $p = $projects{$project}{pass} // 0; | ||||||||||||||||||||||||||
|
Condition0%0/2
$projects{$project}{"pass"} // 0
MC/DC0%0/1
$projects{$project}{"pass"} // 0
$projects{$project}{"pass"}
Truth table0%0/2
A
A= $projects{$project}{"pass"}
| |||||||||||||||||||||||||||||
| 669 | 0 | ▶ | my $f = $projects{$project}{fail} // 0; | ||||||||||||||||||||||||||
|
Condition0%0/2
$projects{$project}{"fail"} // 0
MC/DC0%0/1
$projects{$project}{"fail"} // 0
$projects{$project}{"fail"}
Truth table0%0/2
A
A= $projects{$project}{"fail"}
| |||||||||||||||||||||||||||||
| 670 | 0 | my $q = p4($p, $f); | |||||||||||||||||||||||||||
| 671 | |||||||||||||||||||||||||||||
| 672 | 0 | ▶ | if ($f) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 673 | 0 | {push @failingProjects, [$project, $p, $f, $p + $f, p4($p, $f)]; | |||||||||||||||||||||||||||
| 674 | } | ||||||||||||||||||||||||||||
| 675 | else | ||||||||||||||||||||||||||||
| 676 | 0 | {push @passingProjects, [$project, $p]; | |||||||||||||||||||||||||||
| 677 | } | ||||||||||||||||||||||||||||
| 678 | } | ||||||||||||||||||||||||||||
| 679 | 0 | @failingProjects = sort {$a->[4] <=> $b->[4]} @failingProjects; | |||||||||||||||||||||||||||
| 680 | 0 | @passingProjects = sort {$a->[0] cmp $b->[0]} @passingProjects; | |||||||||||||||||||||||||||
| 681 | |||||||||||||||||||||||||||||
| 682 | 0 | my $failingProjects = @failingProjects; | |||||||||||||||||||||||||||
| 683 | 0 | my $passingProjects = @passingProjects; | |||||||||||||||||||||||||||
| 684 | |||||||||||||||||||||||||||||
| 685 | 0 | my $totalNumberOfFails = scalar grep {$files{$_} > 0} keys %files; | |||||||||||||||||||||||||||
| 686 | 0 | my $totalNumberOfPasses = scalar grep {$files{$_} == 0} keys %files; | |||||||||||||||||||||||||||
| 687 | 0 | my $totalPassFailPercent = p4($totalNumberOfPasses, $totalNumberOfFails); | |||||||||||||||||||||||||||
| 688 | 0 | my $ts = dateTimeStamp; | |||||||||||||||||||||||||||
| 689 | 0 | my $numberOfProjects = keys %projects; | |||||||||||||||||||||||||||
| 690 | 0 | my $numberOfFiles = $totalNumberOfPasses + $totalNumberOfFails; | |||||||||||||||||||||||||||
| 691 | 0 | my $totalCompressedErrors = scalar keys %examples; | |||||||||||||||||||||||||||
| 692 | 0 | my $totalPassFailPercentB = boldString($totalPassFailPercent); | |||||||||||||||||||||||||||
| 693 | |||||||||||||||||||||||||||||
| 694 | 0 | my $summary = <<END; # Report summary | |||||||||||||||||||||||||||
| 695 | $totalPassFailPercent % success. Projects: $failingProjects+$passingProjects=$numberOfProjects. Files: $totalNumberOfFails+$totalNumberOfPasses=$numberOfFiles. Errors: $totalCompressedErrors,$totalErrors On $ts | ||||||||||||||||||||||||||||
| 696 | END | ||||||||||||||||||||||||||||
| 697 | |||||||||||||||||||||||||||||
| 698 | 0 | push my @report, $summary, "\n"; | |||||||||||||||||||||||||||
| 699 | |||||||||||||||||||||||||||||
| 700 | 0 | push @report, sprintf(<<END, # Report title | |||||||||||||||||||||||||||
| 701 | CompressedErrorMessagesByCount: %8d | ||||||||||||||||||||||||||||
| 702 | |||||||||||||||||||||||||||||
| 703 | FailingFiles : %8d | ||||||||||||||||||||||||||||
| 704 | PassingFiles : %8d | ||||||||||||||||||||||||||||
| 705 | |||||||||||||||||||||||||||||
| 706 | FailingProjects: %8d | ||||||||||||||||||||||||||||
| 707 | PassingProjects: %8d | ||||||||||||||||||||||||||||
| 708 | END | ||||||||||||||||||||||||||||
| 709 | scalar keys %examples, | ||||||||||||||||||||||||||||
| 710 | $totalNumberOfFails, | ||||||||||||||||||||||||||||
| 711 | $totalNumberOfPasses, | ||||||||||||||||||||||||||||
| 712 | scalar(@failingProjects), | ||||||||||||||||||||||||||||
| 713 | scalar(@passingProjects)); | ||||||||||||||||||||||||||||
| 714 | |||||||||||||||||||||||||||||
| 715 | 0 | ▶ | if (@failingProjects) # Failing projects report | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 716 | 0 | {push @report, sprintf(<<END, | |||||||||||||||||||||||||||
| 717 | |||||||||||||||||||||||||||||
| 718 | |||||||||||||||||||||||||||||
| 719 | FailingProjects: %8d | ||||||||||||||||||||||||||||
| 720 | # Percent Pass Fail Total Project | ||||||||||||||||||||||||||||
| 721 | END | ||||||||||||||||||||||||||||
| 722 | scalar(@failingProjects)); | ||||||||||||||||||||||||||||
| 723 | |||||||||||||||||||||||||||||
| 724 | 0 | for(1..@failingProjects) | |||||||||||||||||||||||||||
| 725 | 0 | {my ($project, $pass, $fail, $total, $percent) = @{$failingProjects[$_-1]}; | |||||||||||||||||||||||||||
| 726 | 0 | push @report, sprintf("%4d %8.4f %4d %4d %5d %s\n", | |||||||||||||||||||||||||||
| 727 | $_, $percent, $pass, $fail, $total, $project); | ||||||||||||||||||||||||||||
| 728 | } | ||||||||||||||||||||||||||||
| 729 | } | ||||||||||||||||||||||||||||
| 730 | |||||||||||||||||||||||||||||
| 731 | 0 | ▶ | if (@passingProjects) # Passing projects report | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 732 | 0 | {push @report, sprintf(<<END, | |||||||||||||||||||||||||||
| 733 | |||||||||||||||||||||||||||||
| 734 | |||||||||||||||||||||||||||||
| 735 | PassingProjects: %8d | ||||||||||||||||||||||||||||
| 736 | # Files Project | ||||||||||||||||||||||||||||
| 737 | END | ||||||||||||||||||||||||||||
| 738 | scalar(@passingProjects)); | ||||||||||||||||||||||||||||
| 739 | |||||||||||||||||||||||||||||
| 740 | 0 | for(1..@passingProjects) | |||||||||||||||||||||||||||
| 741 | 0 | {my ($project, $files) = @{$passingProjects[$_-1]}; | |||||||||||||||||||||||||||
| 742 | 0 | push @report, sprintf("%4d %4d %s\n", | |||||||||||||||||||||||||||
| 743 | $_, $files, $project); | ||||||||||||||||||||||||||||
| 744 | } | ||||||||||||||||||||||||||||
| 745 | } | ||||||||||||||||||||||||||||
| 746 | |||||||||||||||||||||||||||||
| 747 | 0 | ▶ | if (my $N = keys %examples) # Compressed errors report | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 748 | 0 | {my @ce = sort {$b->[0] <=> $a->[0]} | |||||||||||||||||||||||||||
| 749 | 0 | map {my @f = keys $examples{$_}->%*; [scalar(@f), $_, \@f]} | |||||||||||||||||||||||||||
| 750 | keys %examples; | ||||||||||||||||||||||||||||
| 751 | |||||||||||||||||||||||||||||
| 752 | 0 | my @e; | |||||||||||||||||||||||||||
| 753 | 0 | for my $ce(@ce) | |||||||||||||||||||||||||||
| 754 | 0 | {my ($count, $message, $files) = @$ce; | |||||||||||||||||||||||||||
| 755 | 0 | $message =~ s(\A<!--) ()gs; | |||||||||||||||||||||||||||
| 756 | 0 | $message =~ s(-->\Z) ()gs; | |||||||||||||||||||||||||||
| 757 | 0 | $message =~ s(\s*\x29) (\x29)gs; | |||||||||||||||||||||||||||
| 758 | 0 | $message = trim($message); | |||||||||||||||||||||||||||
| 759 | |||||||||||||||||||||||||||||
| 760 | 0 | my @f = map {fne($_)} sort {fileSize($a) <=> fileSize($b)} @$files; # Smallest examples first, shorten file names | |||||||||||||||||||||||||||
| 761 | 0 | ▶ | $#f = maxExampleFiles if scalar(@f) > maxExampleFiles; # Limit example files | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 762 | |||||||||||||||||||||||||||||
| 763 | 0 | push @e, [$count, $message, shift @f]; # First line | |||||||||||||||||||||||||||
| 764 | 0 | push @e, [q(), q(), $_] for @f; # Subsequent lines | |||||||||||||||||||||||||||
| 765 | } | ||||||||||||||||||||||||||||
| 766 | |||||||||||||||||||||||||||||
| 767 | 0 | push @report, <<END, | |||||||||||||||||||||||||||
| 768 | |||||||||||||||||||||||||||||
| 769 | |||||||||||||||||||||||||||||
| 770 | CompressedErrorMessagesByCount: $N | ||||||||||||||||||||||||||||
| 771 | |||||||||||||||||||||||||||||
| 772 | END | ||||||||||||||||||||||||||||
| 773 | # formatTableBasic(\@e); | ||||||||||||||||||||||||||||
| 774 | |||||||||||||||||||||||||||||
| 775 | formatTable(\@e, <<END, # Report compressed error messages | ||||||||||||||||||||||||||||
| 776 | Count Number of times this message appears | ||||||||||||||||||||||||||||
| 777 | Message The error message from xmllint - compressed and truncated if necessary | ||||||||||||||||||||||||||||
| 778 | Examples Files that exhibit this message | ||||||||||||||||||||||||||||
| 779 | END | ||||||||||||||||||||||||||||
| 780 | title => q(Compressed Error messages by Count), | ||||||||||||||||||||||||||||
| 781 | head => <<END, | ||||||||||||||||||||||||||||
| 782 | NNNN compressed error messages on DDDD | ||||||||||||||||||||||||||||
| 783 | END | ||||||||||||||||||||||||||||
| 784 | ); | ||||||||||||||||||||||||||||
| 785 | } | ||||||||||||||||||||||||||||
| 786 | |||||||||||||||||||||||||||||
| 787 | my @filesFail = sort # Failing files: sort by number of errors, project, file name | ||||||||||||||||||||||||||||
| 788 | 0 | {my $e = $a->[0] <=> $b->[0]; | |||||||||||||||||||||||||||
| 789 | 0 | my $p = $a->[1] cmp $b->[1]; | |||||||||||||||||||||||||||
| 790 | 0 | my $f = $a->[2] cmp $b->[2]; | |||||||||||||||||||||||||||
| 791 | 0 | ▶ | return $e if $e; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 792 | 0 | ▶ | return $p if $p; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 793 | $f | ||||||||||||||||||||||||||||
| 794 | } | ||||||||||||||||||||||||||||
| 795 | 0 | map {[$files{$_}, $filesToProjects{$_}, $_]} | |||||||||||||||||||||||||||
| 796 | 0 | grep {$files{$_} > 0} | |||||||||||||||||||||||||||
| 797 | keys %files; | ||||||||||||||||||||||||||||
| 798 | |||||||||||||||||||||||||||||
| 799 | 0 | ▶ | if (my $filesFail = @filesFail) # Failing files report | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 800 | 0 | {my @r; | |||||||||||||||||||||||||||
| 801 | 0 | for my $n(1..@filesFail) | |||||||||||||||||||||||||||
| 802 | 0 | {my ($errors, $project, $file) = @{$filesFail[$n-1]}; | |||||||||||||||||||||||||||
| 803 | 0 | push @r, [$n, $errors, $file]; | |||||||||||||||||||||||||||
| 804 | } | ||||||||||||||||||||||||||||
| 805 | 0 | push @report, <<END, formatTable(\@r, <<END2); | |||||||||||||||||||||||||||
| 806 | |||||||||||||||||||||||||||||
| 807 | FailingFiles: $totalNumberOfFails Files that failed to pass lint by number of compressed errors | ||||||||||||||||||||||||||||
| 808 | |||||||||||||||||||||||||||||
| 809 | END | ||||||||||||||||||||||||||||
| 810 | # Failing File number | ||||||||||||||||||||||||||||
| 811 | Errors The number of errors in this file | ||||||||||||||||||||||||||||
| 812 | File The file with errors | ||||||||||||||||||||||||||||
| 813 | END2 | ||||||||||||||||||||||||||||
| 814 | } | ||||||||||||||||||||||||||||
| 815 | |||||||||||||||||||||||||||||
| 816 | 0 | ▶ | if (my $N = scalar keys %docTypes) # Document type summary | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 817 | 0 | {my $s = formatTable(\%docTypes, [qw(Document Count)]); | |||||||||||||||||||||||||||
| 818 | 0 | push @report, <<END; | |||||||||||||||||||||||||||
| 819 | |||||||||||||||||||||||||||||
| 820 | |||||||||||||||||||||||||||||
| 821 | DocumentTypes: $N | ||||||||||||||||||||||||||||
| 822 | |||||||||||||||||||||||||||||
| 823 | $s | ||||||||||||||||||||||||||||
| 824 | END | ||||||||||||||||||||||||||||
| 825 | } | ||||||||||||||||||||||||||||
| 826 | |||||||||||||||||||||||||||||
| 827 | 0 | push @report, "\n", (split /\n/, $report[0])[0]; # Repeat summary line | |||||||||||||||||||||||||||
| 828 | |||||||||||||||||||||||||||||
| 829 | 0 | ▶ | if (my $d = dateTimeStamp) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 830 | 0 | {unshift @report, <<END, # Time stamp | |||||||||||||||||||||||||||
| 831 | Summary of passing and failing projects on: $d | ||||||||||||||||||||||||||||
| 832 | END | ||||||||||||||||||||||||||||
| 833 | } | ||||||||||||||||||||||||||||
| 834 | |||||||||||||||||||||||||||||
| 835 | 0 | return genHash('Data::Edit::Xml::Lint::Report', # Return report | |||||||||||||||||||||||||||
| 836 | compressedErrors => \%examples, | ||||||||||||||||||||||||||||
| 837 | docTypes => \%docTypes, | ||||||||||||||||||||||||||||
| 838 | failingFiles => [@filesFail], | ||||||||||||||||||||||||||||
| 839 | failingProjects => [@failingProjects], | ||||||||||||||||||||||||||||
| 840 | filter => $filter, | ||||||||||||||||||||||||||||
| 841 | numberOfFiles => $numberOfFiles, | ||||||||||||||||||||||||||||
| 842 | numberOfProjects => $numberOfProjects, | ||||||||||||||||||||||||||||
| 843 | passingProjects => [@passingProjects], | ||||||||||||||||||||||||||||
| 844 | passRatePercent => $totalPassFailPercent, | ||||||||||||||||||||||||||||
| 845 | print => (join '', @report), | ||||||||||||||||||||||||||||
| 846 | summary => $summary, | ||||||||||||||||||||||||||||
| 847 | timestamp => $ts, | ||||||||||||||||||||||||||||
| 848 | totalCompressedErrorsFileByFile => $totalCompressedErrorsFileByFile, | ||||||||||||||||||||||||||||
| 849 | totalCompressedErrors => scalar keys %examples, | ||||||||||||||||||||||||||||
| 850 | totalErrors => $totalErrors, | ||||||||||||||||||||||||||||
| 851 | ); | ||||||||||||||||||||||||||||
| 852 | } # report | ||||||||||||||||||||||||||||
| 853 | |||||||||||||||||||||||||||||
| 854 | sub fixDitaXrefHrefs($@) # Fix the dita xref href attributes in the corpus determined by B<foldersAndExtensions>. | ||||||||||||||||||||||||||||
| 855 | 0 | ▶ | {my ($maximumNumberOfProcesses, @foldersAndExtensions) = @_; # Maximum number of processes to run in parallel, folders and file extensions to process. | ||||||||||||||||||||||||||
|
Subroutine
fixDitaXrefHrefs: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 856 | relint($maximumNumberOfProcesses, # Reprocess all the files | ||||||||||||||||||||||||||||
| 857 | sub # Analysis sub | ||||||||||||||||||||||||||||
| 858 | 0 | ▶ | {my ($linkMap, $filesToGuids) = @_; # Link map, files to guids | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 859 | 0 | 1 | |||||||||||||||||||||||||||
| 860 | }, | ||||||||||||||||||||||||||||
| 861 | sub # Reprocess sub | ||||||||||||||||||||||||||||
| 862 | 0 | ▶ | {my ($x, $linkMap, $filesToGuids, $lint) = @_; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 863 | 0 | my $count; # Count the number of changes made | |||||||||||||||||||||||||||
| 864 | $x->by(sub # Look for xrefs in parse tree | ||||||||||||||||||||||||||||
| 865 | 0 | ▶ | {my ($r) = @_; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||
| 866 | 0 | ▶ | if ($r->at_xref) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 867 | 0 | ▶ | {if (my $h = $r->href) # Href | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 868 | 0 | ▶ | {if ($h !~ m(#)s) # If the href has a # in it we assume that it has already been fixed! | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 869 | 0 | ▶ | {if (my $H = resolveDitaLink | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 870 | ($linkMap, $filesToGuids, $h, $lint->file)) | ||||||||||||||||||||||||||||
| 871 | 0 | {$r->href = $H; # Fix href | |||||||||||||||||||||||||||
| 872 | 0 | ++$count; | |||||||||||||||||||||||||||
| 873 | } | ||||||||||||||||||||||||||||
| 874 | } | ||||||||||||||||||||||||||||
| 875 | } | ||||||||||||||||||||||||||||
| 876 | } | ||||||||||||||||||||||||||||
| 877 | 0 | }); | |||||||||||||||||||||||||||
| 878 | |||||||||||||||||||||||||||||
| 879 | 0 | $count | |||||||||||||||||||||||||||
| 880 | 0 | }, @foldersAndExtensions); | |||||||||||||||||||||||||||
| 881 | } | ||||||||||||||||||||||||||||
| 882 | |||||||||||||||||||||||||||||
| 883 | #D2 Attributes | ||||||||||||||||||||||||||||
| 884 | |||||||||||||||||||||||||||||
| 885 | 1 | if (1) | |||||||||||||||||||||||||||
| 886 | {package Data::Edit::Xml::Lint::Report; | ||||||||||||||||||||||||||||
| 887 | 1 | ▶ | use Data::Table::Text qw(:all); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 888 | 1 | genLValueScalarMethods(qw(compressedErrors)); # Compressed errors over all files | |||||||||||||||||||||||||||
| 889 | 1 | genLValueScalarMethods(qw(docTypes)); # Array of [number of errors, L<project|/project>, L<files|/file>] ordered from least to most errors | |||||||||||||||||||||||||||
| 890 | 1 | genLValueScalarMethods(qw(failingFiles)); # {docType}++ - Hash of document types encountered | |||||||||||||||||||||||||||
| 891 | 1 | genLValueScalarMethods(qw(failingProjects)); # [Projects with xmllint errors] | |||||||||||||||||||||||||||
| 892 | 1 | genLValueScalarMethods(qw(filter)); # File selection filter | |||||||||||||||||||||||||||
| 893 | 1 | genLValueScalarMethods(qw(numberOfFiles)); # Number of L<files|/file> encountered | |||||||||||||||||||||||||||
| 894 | 1 | genLValueScalarMethods(qw(numberOfProjects)); # Number of L<projects|/project> defined - each L<project|/project> can contain zero or more L<files|/file> | |||||||||||||||||||||||||||
| 895 | 1 | genLValueScalarMethods(qw(passingProjects)); # [Projects with no xmllint errors] | |||||||||||||||||||||||||||
| 896 | 1 | genLValueScalarMethods(qw(passRatePercent)); # Total number of passes as a percentage of all input files | |||||||||||||||||||||||||||
| 897 | 1 | genLValueScalarMethods(qw(print)); # A printable L<report|/report> of the above | |||||||||||||||||||||||||||
| 898 | 1 | genLValueScalarMethods(qw(timestamp)); # Timestamp of report | |||||||||||||||||||||||||||
| 899 | 1 | genLValueScalarMethods(qw(totalCompressedErrorsFileByFile)); # Total number of errors summed file by file | |||||||||||||||||||||||||||
| 900 | 1 | genLValueScalarMethods(qw(totalCompressedErrors)); # Number of compressed errors | |||||||||||||||||||||||||||
| 901 | 1 | genLValueScalarMethods(qw(totalErrors)); # Total number of errors | |||||||||||||||||||||||||||
| 902 | } | ||||||||||||||||||||||||||||
| 903 | |||||||||||||||||||||||||||||
| 904 | sub createTest($$$;$) #P Create a test file | ||||||||||||||||||||||||||||
| 905 | 0 | ▶ | {my ($project, $source, $target, $additional) = @_; # Project name, source of topic, target of references, additional text for topic | ||||||||||||||||||||||||||
|
Subroutine
createTest: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 906 | 0 | ▶ | $additional //= ''; | ||||||||||||||||||||||||||
|
Condition0%0/2
$additional //= ""
MC/DC0%0/1
$additional //= ""
$additional
Truth table0%0/2
A
A= $additional
| |||||||||||||||||||||||||||||
| 907 | 0 | [$project, $source, $target, $additional, <<END] | |||||||||||||||||||||||||||
| 908 | <?xml version="1.0" encoding="UTF-8"?> | ||||||||||||||||||||||||||||
| 909 | <!DOCTYPE concept PUBLIC "-//OASIS//DTD DITA Concept//EN" "concept.dtd" []> | ||||||||||||||||||||||||||||
| 910 | <concept id="c_${project}_${source}"> | ||||||||||||||||||||||||||||
| 911 | <title>project=$project source=$source target=$target</title> | ||||||||||||||||||||||||||||
| 912 | <conbody id="b_${project}_${source}"> | ||||||||||||||||||||||||||||
| 913 | <p>See: <xref href="B_${project}_${target}"/></p>$additional | ||||||||||||||||||||||||||||
| 914 | </conbody> | ||||||||||||||||||||||||||||
| 915 | </concept> | ||||||||||||||||||||||||||||
| 916 | END | ||||||||||||||||||||||||||||
| 917 | } | ||||||||||||||||||||||||||||
| 918 | |||||||||||||||||||||||||||||
| 919 | sub createTests #P Create some tests | ||||||||||||||||||||||||||||
| 920 | 0 | ▶ | {my @tests; | ||||||||||||||||||||||||||
|
Subroutine
createTests: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 921 | 0 | for my $project(qw(aaa bbb ccc ddd)) | |||||||||||||||||||||||||||
| 922 | 0 | {push @tests, | |||||||||||||||||||||||||||
| 923 | (createTest($project, 1, 1), | ||||||||||||||||||||||||||||
| 924 | createTest($project, 2, 1), | ||||||||||||||||||||||||||||
| 925 | createTest($project, 3, 2), | ||||||||||||||||||||||||||||
| 926 | createTest($project, 4, 3)); | ||||||||||||||||||||||||||||
| 927 | } | ||||||||||||||||||||||||||||
| 928 | @tests | ||||||||||||||||||||||||||||
| 929 | 0 | } | |||||||||||||||||||||||||||
| 930 | |||||||||||||||||||||||||||||
| 931 | #D podDocumentation | ||||||||||||||||||||||||||||
| 932 | |||||||||||||||||||||||||||||
| 933 | =pod | ||||||||||||||||||||||||||||
| 934 | |||||||||||||||||||||||||||||
| 935 | =encoding utf-8 | ||||||||||||||||||||||||||||
| 936 | |||||||||||||||||||||||||||||
| 937 | =head1 Name | ||||||||||||||||||||||||||||
| 938 | |||||||||||||||||||||||||||||
| 939 | L<Data::Edit::Xml::Lint|Data::Edit::Xml::Lint> - L<lint|/lint> xml | ||||||||||||||||||||||||||||
| 940 | L<files|/file> in parallel using xmllint, report the failure rate and reprocess | ||||||||||||||||||||||||||||
| 941 | linted files to fix cross references. | ||||||||||||||||||||||||||||
| 942 | |||||||||||||||||||||||||||||
| 943 | =head1 Synopsis | ||||||||||||||||||||||||||||
| 944 | |||||||||||||||||||||||||||||
| 945 | =head2 Linting and reporting | ||||||||||||||||||||||||||||
| 946 | |||||||||||||||||||||||||||||
| 947 | Create some sample xml L<files|/file>, some with errors, lint them in parallel | ||||||||||||||||||||||||||||
| 948 | and retrieve the number of errors and failing L<files|/file>: | ||||||||||||||||||||||||||||
| 949 | |||||||||||||||||||||||||||||
| 950 | for my $n(1..$N) # Some projects | ||||||||||||||||||||||||||||
| 951 | {my $x = Data::Edit::Xml::Lint::new(); # New xml file linter | ||||||||||||||||||||||||||||
| 952 | |||||||||||||||||||||||||||||
| 953 | my $catalog = $x->catalog = catalogName; # Use catalog if possible | ||||||||||||||||||||||||||||
| 954 | my $project = $x->project = projectName($n); # Project name | ||||||||||||||||||||||||||||
| 955 | my $file = $x->file = fileName($n); # Target file | ||||||||||||||||||||||||||||
| 956 | |||||||||||||||||||||||||||||
| 957 | $x->source = <<END; # Sample source | ||||||||||||||||||||||||||||
| 958 | <?xml version="1.0" encoding="UTF-8"?> | ||||||||||||||||||||||||||||
| 959 | <!DOCTYPE concept PUBLIC "-//HPE//DTD HPE DITA Concept//EN" "concept.dtd" []> | ||||||||||||||||||||||||||||
| 960 | <concept id="$project"> | ||||||||||||||||||||||||||||
| 961 | <title>Project $project</title> | ||||||||||||||||||||||||||||
| 962 | <conbody> | ||||||||||||||||||||||||||||
| 963 | <p>Body of $project</p> | ||||||||||||||||||||||||||||
| 964 | </conbody> | ||||||||||||||||||||||||||||
| 965 | </concept> | ||||||||||||||||||||||||||||
| 966 | END | ||||||||||||||||||||||||||||
| 967 | |||||||||||||||||||||||||||||
| 968 | $x->source =~ s/id="\w+?"//gs if addError($n); # Introduce an error into some projects | ||||||||||||||||||||||||||||
| 969 | |||||||||||||||||||||||||||||
| 970 | $x->lint(foo=>1); # Write the source to the target file, lint using xmllint, include some attributes to be included as comments at the end of the target file | ||||||||||||||||||||||||||||
| 971 | } | ||||||||||||||||||||||||||||
| 972 | |||||||||||||||||||||||||||||
| 973 | Data::Edit::Xml::Lint::wait; # Wait for lints to complete | ||||||||||||||||||||||||||||
| 974 | |||||||||||||||||||||||||||||
| 975 | say STDERR Data::Edit::Xml::Lint::report($outDir, "xml")->print; # Report total pass fail rate | ||||||||||||||||||||||||||||
| 976 | } | ||||||||||||||||||||||||||||
| 977 | |||||||||||||||||||||||||||||
| 978 | Produces: | ||||||||||||||||||||||||||||
| 979 | |||||||||||||||||||||||||||||
| 980 | 50 % success converting 3 projects containing 10 xml files on 2017-07-13 at 17:43:24 | ||||||||||||||||||||||||||||
| 981 | |||||||||||||||||||||||||||||
| 982 | ProjectStatistics | ||||||||||||||||||||||||||||
| 983 | # Percent Pass Fail Total Project | ||||||||||||||||||||||||||||
| 984 | 1 33.3333 1 2 3 aaa | ||||||||||||||||||||||||||||
| 985 | 2 50.0000 2 2 4 bbb | ||||||||||||||||||||||||||||
| 986 | 3 66.6667 2 1 3 ccc | ||||||||||||||||||||||||||||
| 987 | |||||||||||||||||||||||||||||
| 988 | FailingFiles | ||||||||||||||||||||||||||||
| 989 | # Errors Project File | ||||||||||||||||||||||||||||
| 990 | 1 1 ccc out/ccc5.xml | ||||||||||||||||||||||||||||
| 991 | 2 1 aaa out/aaa9.xml | ||||||||||||||||||||||||||||
| 992 | 3 1 bbb out/bbb1.xml | ||||||||||||||||||||||||||||
| 993 | 4 1 bbb out/bbb7.xml | ||||||||||||||||||||||||||||
| 994 | 5 1 aaa out/aaa3.xml | ||||||||||||||||||||||||||||
| 995 | |||||||||||||||||||||||||||||
| 996 | =head2 Rereading | ||||||||||||||||||||||||||||
| 997 | |||||||||||||||||||||||||||||
| 998 | Once a L<file|/file> has been L<linted|/lint>, it can be reread with L<read|/read> | ||||||||||||||||||||||||||||
| 999 | to obtain details about the xml including any B<id> attributes defined (see: idDefs below) and | ||||||||||||||||||||||||||||
| 1000 | any L<labels|Data::Edit::Xml/Labels> that refer to these B<id> attributes (see: labelDefs | ||||||||||||||||||||||||||||
| 1001 | below). Such L<labels|Data::Edit::Xml/Labels> provide additional identities for a | ||||||||||||||||||||||||||||
| 1002 | node beyond that provided by the B<id> attribute. | ||||||||||||||||||||||||||||
| 1003 | |||||||||||||||||||||||||||||
| 1004 | {catalog => "/home/phil/hp/dtd/Dtd_2016_07_12/catalog-hpe.xml", | ||||||||||||||||||||||||||||
| 1005 | definition => "bbb", | ||||||||||||||||||||||||||||
| 1006 | docType => "<!DOCTYPE concept PUBLIC \"-//HPE//DTD HPE DITA Concept//EN\" \"concept.dtd\" []>", | ||||||||||||||||||||||||||||
| 1007 | errors => 1, | ||||||||||||||||||||||||||||
| 1008 | file => "out/bbb1.xml", | ||||||||||||||||||||||||||||
| 1009 | foo => 1, | ||||||||||||||||||||||||||||
| 1010 | header => "<?xml version=\"1.0\" encoding=\"UTF-8\"?>", | ||||||||||||||||||||||||||||
| 1011 | idDefs => { bbb => 1, c1 => 1 }, | ||||||||||||||||||||||||||||
| 1012 | labelDefs => { | ||||||||||||||||||||||||||||
| 1013 | bbb => "bbb", | ||||||||||||||||||||||||||||
| 1014 | c1 => "c1", | ||||||||||||||||||||||||||||
| 1015 | conbody1 => "c1", | ||||||||||||||||||||||||||||
| 1016 | conbody2 => "c1", | ||||||||||||||||||||||||||||
| 1017 | concept1 => "bbb", | ||||||||||||||||||||||||||||
| 1018 | concept2 => "bbb", | ||||||||||||||||||||||||||||
| 1019 | }, | ||||||||||||||||||||||||||||
| 1020 | labels => "bbb concept1 concept2", | ||||||||||||||||||||||||||||
| 1021 | project => "bbb", | ||||||||||||||||||||||||||||
| 1022 | sha256 => "b00cdebf2e1837fa15140d25315e5558ed59eb735b5fad4bade23969babf9531", | ||||||||||||||||||||||||||||
| 1023 | source => "..." | ||||||||||||||||||||||||||||
| 1024 | } | ||||||||||||||||||||||||||||
| 1025 | |||||||||||||||||||||||||||||
| 1026 | =head2 ReLinting | ||||||||||||||||||||||||||||
| 1027 | |||||||||||||||||||||||||||||
| 1028 | In order to fix references between L<files|/file>, a list of L<files|/file> can be | ||||||||||||||||||||||||||||
| 1029 | L<relinted|/relint> which performs the following actions: | ||||||||||||||||||||||||||||
| 1030 | |||||||||||||||||||||||||||||
| 1031 | =over 2 | ||||||||||||||||||||||||||||
| 1032 | |||||||||||||||||||||||||||||
| 1033 | =item 1 | ||||||||||||||||||||||||||||
| 1034 | |||||||||||||||||||||||||||||
| 1035 | reads the specified L<files|/file> via L<read|/read> | ||||||||||||||||||||||||||||
| 1036 | |||||||||||||||||||||||||||||
| 1037 | =item 2 | ||||||||||||||||||||||||||||
| 1038 | |||||||||||||||||||||||||||||
| 1039 | constructs an B<id map> to locate an B<id>s from B<label>s defined in the | ||||||||||||||||||||||||||||
| 1040 | specified L<files|/file> | ||||||||||||||||||||||||||||
| 1041 | |||||||||||||||||||||||||||||
| 1042 | =item 3 | ||||||||||||||||||||||||||||
| 1043 | |||||||||||||||||||||||||||||
| 1044 | L<Reparses|Data::Edit::Xml/new> each of the specified L<files|/file> to build a | ||||||||||||||||||||||||||||
| 1045 | parse tree representing the xml in each file. | ||||||||||||||||||||||||||||
| 1046 | |||||||||||||||||||||||||||||
| 1047 | =item 4 | ||||||||||||||||||||||||||||
| 1048 | |||||||||||||||||||||||||||||
| 1049 | Calls a user supplied B<sub> passing it the L<parse tree|Data::Edit::Xml/new> | ||||||||||||||||||||||||||||
| 1050 | for each specified file and the B<id map>. The B<sub> should traverse the | ||||||||||||||||||||||||||||
| 1051 | L<parse tree|Data::Edit::Xml/new> fixing attributes which make references | ||||||||||||||||||||||||||||
| 1052 | between the L<files|/file> using the supplied B<id map>. | ||||||||||||||||||||||||||||
| 1053 | |||||||||||||||||||||||||||||
| 1054 | =item 5 | ||||||||||||||||||||||||||||
| 1055 | |||||||||||||||||||||||||||||
| 1056 | Writes any modified L<parse trees|Data::Edit::Xml/new> back to the originating | ||||||||||||||||||||||||||||
| 1057 | L<file|/file> thus fixing the changes | ||||||||||||||||||||||||||||
| 1058 | |||||||||||||||||||||||||||||
| 1059 | =back | ||||||||||||||||||||||||||||
| 1060 | |||||||||||||||||||||||||||||
| 1061 | =head1 Description | ||||||||||||||||||||||||||||
| 1062 | |||||||||||||||||||||||||||||
| 1063 | |||||||||||||||||||||||||||||
| 1064 | |||||||||||||||||||||||||||||
| 1065 | Version 20190721. | ||||||||||||||||||||||||||||
| 1066 | |||||||||||||||||||||||||||||
| 1067 | |||||||||||||||||||||||||||||
| 1068 | The following sections describe the methods in each functional area of this | ||||||||||||||||||||||||||||
| 1069 | module. For an alphabetic listing of all methods by name see L<Index|/Index>. | ||||||||||||||||||||||||||||
| 1070 | |||||||||||||||||||||||||||||
| 1071 | |||||||||||||||||||||||||||||
| 1072 | |||||||||||||||||||||||||||||
| 1073 | =head1 Constructor | ||||||||||||||||||||||||||||
| 1074 | |||||||||||||||||||||||||||||
| 1075 | Construct a new linter | ||||||||||||||||||||||||||||
| 1076 | |||||||||||||||||||||||||||||
| 1077 | =head2 new() | ||||||||||||||||||||||||||||
| 1078 | |||||||||||||||||||||||||||||
| 1079 | Create a new xml linter - call this method statically as in L<Data::Edit::Xml::Lint|/new> and then fill in the relevant L<Attributes>. | ||||||||||||||||||||||||||||
| 1080 | |||||||||||||||||||||||||||||
| 1081 | |||||||||||||||||||||||||||||
| 1082 | This is a static method and so should be invoked as: | ||||||||||||||||||||||||||||
| 1083 | |||||||||||||||||||||||||||||
| 1084 | Data::Edit::Xml::Lint::new | ||||||||||||||||||||||||||||
| 1085 | |||||||||||||||||||||||||||||
| 1086 | |||||||||||||||||||||||||||||
| 1087 | =head2 Attributes | ||||||||||||||||||||||||||||
| 1088 | |||||||||||||||||||||||||||||
| 1089 | Attributes describing a lint. | ||||||||||||||||||||||||||||
| 1090 | |||||||||||||||||||||||||||||
| 1091 | =head3 author :lvalue | ||||||||||||||||||||||||||||
| 1092 | |||||||||||||||||||||||||||||
| 1093 | Optional author of the xml - only needed if you want to generate an SDL file map. | ||||||||||||||||||||||||||||
| 1094 | |||||||||||||||||||||||||||||
| 1095 | |||||||||||||||||||||||||||||
| 1096 | =head3 catalog :lvalue | ||||||||||||||||||||||||||||
| 1097 | |||||||||||||||||||||||||||||
| 1098 | Optional catalog file containing the locations of the DTDs used to validate the xml or use L<dtds|/dtds> to supply a B<DTD> instead. | ||||||||||||||||||||||||||||
| 1099 | |||||||||||||||||||||||||||||
| 1100 | |||||||||||||||||||||||||||||
| 1101 | =head3 compressedErrors :lvalue | ||||||||||||||||||||||||||||
| 1102 | |||||||||||||||||||||||||||||
| 1103 | Number of compressed errors discovered. | ||||||||||||||||||||||||||||
| 1104 | |||||||||||||||||||||||||||||
| 1105 | |||||||||||||||||||||||||||||
| 1106 | =head3 compressedErrorText :lvalue | ||||||||||||||||||||||||||||
| 1107 | |||||||||||||||||||||||||||||
| 1108 | Text of compressed errors. | ||||||||||||||||||||||||||||
| 1109 | |||||||||||||||||||||||||||||
| 1110 | |||||||||||||||||||||||||||||
| 1111 | =head3 ditaType :lvalue | ||||||||||||||||||||||||||||
| 1112 | |||||||||||||||||||||||||||||
| 1113 | Optional Dita topic type(concept|task|troubleshooting|reference) of the xml - only needed if you want to generate an SDL file map. | ||||||||||||||||||||||||||||
| 1114 | |||||||||||||||||||||||||||||
| 1115 | |||||||||||||||||||||||||||||
| 1116 | =head3 docType :lvalue | ||||||||||||||||||||||||||||
| 1117 | |||||||||||||||||||||||||||||
| 1118 | The second line: the document type extracted from the L<source|/source>. | ||||||||||||||||||||||||||||
| 1119 | |||||||||||||||||||||||||||||
| 1120 | |||||||||||||||||||||||||||||
| 1121 | =head3 dtds :lvalue | ||||||||||||||||||||||||||||
| 1122 | |||||||||||||||||||||||||||||
| 1123 | Optional directory containing the DTDs used to validate the xml. | ||||||||||||||||||||||||||||
| 1124 | |||||||||||||||||||||||||||||
| 1125 | |||||||||||||||||||||||||||||
| 1126 | =head3 errors :lvalue | ||||||||||||||||||||||||||||
| 1127 | |||||||||||||||||||||||||||||
| 1128 | Total number of uncompressed lint errors detected by xmllint over all files. | ||||||||||||||||||||||||||||
| 1129 | |||||||||||||||||||||||||||||
| 1130 | |||||||||||||||||||||||||||||
| 1131 | =head3 errorText :lvalue | ||||||||||||||||||||||||||||
| 1132 | |||||||||||||||||||||||||||||
| 1133 | Text of uncompressed lint errors detected by xmllint over all files. | ||||||||||||||||||||||||||||
| 1134 | |||||||||||||||||||||||||||||
| 1135 | |||||||||||||||||||||||||||||
| 1136 | =head3 file :lvalue | ||||||||||||||||||||||||||||
| 1137 | |||||||||||||||||||||||||||||
| 1138 | File that the xml should be written to or read from by L<lint|/lint>, L<read|/read> or L<relint|/relint>. | ||||||||||||||||||||||||||||
| 1139 | |||||||||||||||||||||||||||||
| 1140 | |||||||||||||||||||||||||||||
| 1141 | =head3 fileNumber :lvalue | ||||||||||||||||||||||||||||
| 1142 | |||||||||||||||||||||||||||||
| 1143 | File number - assigned by the caller to help debugging transformations. | ||||||||||||||||||||||||||||
| 1144 | |||||||||||||||||||||||||||||
| 1145 | |||||||||||||||||||||||||||||
| 1146 | =head3 lineNumber :lvalue | ||||||||||||||||||||||||||||
| 1147 | |||||||||||||||||||||||||||||
| 1148 | The file and line number of the caller so we can identify which request for lint gave rise to a particular file | ||||||||||||||||||||||||||||
| 1149 | |||||||||||||||||||||||||||||
| 1150 | |||||||||||||||||||||||||||||
| 1151 | =head3 guid :lvalue | ||||||||||||||||||||||||||||
| 1152 | |||||||||||||||||||||||||||||
| 1153 | Guid or id of the outermost tag - if not supplied the first definition encountered in each file will be used on the basis that all Dita topics require an id. | ||||||||||||||||||||||||||||
| 1154 | |||||||||||||||||||||||||||||
| 1155 | |||||||||||||||||||||||||||||
| 1156 | =head3 header :lvalue | ||||||||||||||||||||||||||||
| 1157 | |||||||||||||||||||||||||||||
| 1158 | The first line: the xml header extracted from L<source|/source>. | ||||||||||||||||||||||||||||
| 1159 | |||||||||||||||||||||||||||||
| 1160 | |||||||||||||||||||||||||||||
| 1161 | =head3 idDefs :lvalue | ||||||||||||||||||||||||||||
| 1162 | |||||||||||||||||||||||||||||
| 1163 | {id} = count - the number of times this id is defined in the xml contained in this L<file|/file>. | ||||||||||||||||||||||||||||
| 1164 | |||||||||||||||||||||||||||||
| 1165 | |||||||||||||||||||||||||||||
| 1166 | =head3 inputFile :lvalue | ||||||||||||||||||||||||||||
| 1167 | |||||||||||||||||||||||||||||
| 1168 | The file from which this xml was obtained. | ||||||||||||||||||||||||||||
| 1169 | |||||||||||||||||||||||||||||
| 1170 | |||||||||||||||||||||||||||||
| 1171 | =head3 labelDefs :lvalue | ||||||||||||||||||||||||||||
| 1172 | |||||||||||||||||||||||||||||
| 1173 | {label or id} = id - the id of the node containing a L<label|Data::Edit::Xml/Labels> defined on the xml. | ||||||||||||||||||||||||||||
| 1174 | |||||||||||||||||||||||||||||
| 1175 | |||||||||||||||||||||||||||||
| 1176 | =head3 labels :lvalue | ||||||||||||||||||||||||||||
| 1177 | |||||||||||||||||||||||||||||
| 1178 | Optional parse tree to supply L<labels|Data::Edit::Xml/Labels> for the current L<source|/source> as the labels are present in the parse tree not in the string representing the parse tree. | ||||||||||||||||||||||||||||
| 1179 | |||||||||||||||||||||||||||||
| 1180 | |||||||||||||||||||||||||||||
| 1181 | =head3 linted :lvalue | ||||||||||||||||||||||||||||
| 1182 | |||||||||||||||||||||||||||||
| 1183 | Date the lint was performed by L<lint|/lint>. We avoid adding a time as well because this then induces much longer sync times with AWS S3. | ||||||||||||||||||||||||||||
| 1184 | |||||||||||||||||||||||||||||
| 1185 | |||||||||||||||||||||||||||||
| 1186 | =head3 preferredSource :lvalue | ||||||||||||||||||||||||||||
| 1187 | |||||||||||||||||||||||||||||
| 1188 | Preferred representation of the xml source, used by L<relint|/relint> to supply a preferred representation for the source. | ||||||||||||||||||||||||||||
| 1189 | |||||||||||||||||||||||||||||
| 1190 | |||||||||||||||||||||||||||||
| 1191 | =head3 processes :lvalue | ||||||||||||||||||||||||||||
| 1192 | |||||||||||||||||||||||||||||
| 1193 | Maximum number of xmllint processes to run in parallel - 8 by default if linting in parallel is being used. Linting in parallel is pointless if each file is already being converted in parallel. Conversely, linting in parallel is helpful if the xml files are being converted serially. | ||||||||||||||||||||||||||||
| 1194 | |||||||||||||||||||||||||||||
| 1195 | |||||||||||||||||||||||||||||
| 1196 | =head3 project :lvalue | ||||||||||||||||||||||||||||
| 1197 | |||||||||||||||||||||||||||||
| 1198 | Optional L<project|/project> name to allow error counts to be aggregated by L<project|/project> and to allow L<id and labels|Data::Edit::Xml/Labels> to be scoped to the L<files|/file> contained in each L<project|/project>. | ||||||||||||||||||||||||||||
| 1199 | |||||||||||||||||||||||||||||
| 1200 | |||||||||||||||||||||||||||||
| 1201 | =head3 reusedInProject :lvalue | ||||||||||||||||||||||||||||
| 1202 | |||||||||||||||||||||||||||||
| 1203 | List of projects in which this file is reused, which can be set via L<reuseFileInProject|/reuseFileInProject> every time you discover another project in which a file is reused. | ||||||||||||||||||||||||||||
| 1204 | |||||||||||||||||||||||||||||
| 1205 | |||||||||||||||||||||||||||||
| 1206 | =head3 source :lvalue | ||||||||||||||||||||||||||||
| 1207 | |||||||||||||||||||||||||||||
| 1208 | The source Xml to be written to L<file|/file> and linted. | ||||||||||||||||||||||||||||
| 1209 | |||||||||||||||||||||||||||||
| 1210 | |||||||||||||||||||||||||||||
| 1211 | =head3 title :lvalue | ||||||||||||||||||||||||||||
| 1212 | |||||||||||||||||||||||||||||
| 1213 | Optional title of the xml - only needed if you want to generate an SDL file map. | ||||||||||||||||||||||||||||
| 1214 | |||||||||||||||||||||||||||||
| 1215 | |||||||||||||||||||||||||||||
| 1216 | =head1 Lint | ||||||||||||||||||||||||||||
| 1217 | |||||||||||||||||||||||||||||
| 1218 | Lint xml L<files|/file> in parallel | ||||||||||||||||||||||||||||
| 1219 | |||||||||||||||||||||||||||||
| 1220 | =head2 squeezeDitaRef($) | ||||||||||||||||||||||||||||
| 1221 | |||||||||||||||||||||||||||||
| 1222 | Squeeze a string so it can be safely stored inside blank separated list inside an xml comment. | ||||||||||||||||||||||||||||
| 1223 | |||||||||||||||||||||||||||||
| 1224 | Parameter Description | ||||||||||||||||||||||||||||
| 1225 | 1 $ref String to squeeze | ||||||||||||||||||||||||||||
| 1226 | |||||||||||||||||||||||||||||
| 1227 | This is a static method and so should be invoked as: | ||||||||||||||||||||||||||||
| 1228 | |||||||||||||||||||||||||||||
| 1229 | Data::Edit::Xml::Lint::squeezeDitaRef | ||||||||||||||||||||||||||||
| 1230 | |||||||||||||||||||||||||||||
| 1231 | |||||||||||||||||||||||||||||
| 1232 | =head2 nolint($@) | ||||||||||||||||||||||||||||
| 1233 | |||||||||||||||||||||||||||||
| 1234 | Store just the attributes in a file so that they can be retrieved later to process non xml objects referenced in the xml - like images | ||||||||||||||||||||||||||||
| 1235 | |||||||||||||||||||||||||||||
| 1236 | Parameter Description | ||||||||||||||||||||||||||||
| 1237 | 1 $lint Linter | ||||||||||||||||||||||||||||
| 1238 | 2 %attributes Attributes to be recorded as xml comments | ||||||||||||||||||||||||||||
| 1239 | |||||||||||||||||||||||||||||
| 1240 | =head2 read($) | ||||||||||||||||||||||||||||
| 1241 | |||||||||||||||||||||||||||||
| 1242 | Reread a linted xml L<file|/file> and extract the L<attributes|/Attributes> associated with the L<lint|/lint> | ||||||||||||||||||||||||||||
| 1243 | |||||||||||||||||||||||||||||
| 1244 | Parameter Description | ||||||||||||||||||||||||||||
| 1245 | 1 $file File containing xml | ||||||||||||||||||||||||||||
| 1246 | |||||||||||||||||||||||||||||
| 1247 | B<Example:> | ||||||||||||||||||||||||||||
| 1248 | |||||||||||||||||||||||||||||
| 1249 | |||||||||||||||||||||||||||||
| 1250 | if (1) | ||||||||||||||||||||||||||||
| 1251 | {my $x = Data::Edit::Xml::new(<<END); | ||||||||||||||||||||||||||||
| 1252 | <?xml version="1.0" encoding="UTF-8"?> | ||||||||||||||||||||||||||||
| 1253 | <!DOCTYPE concept PUBLIC "-//OASIS//DTD DITA Concept//EN" "concept.dtd" []> | ||||||||||||||||||||||||||||
| 1254 | <concept id="c1"> | ||||||||||||||||||||||||||||
| 1255 | <title/> | ||||||||||||||||||||||||||||
| 1256 | <conbody> | ||||||||||||||||||||||||||||
| 1257 | </conbody> | ||||||||||||||||||||||||||||
| 1258 | </concept> | ||||||||||||||||||||||||||||
| 1259 | END | ||||||||||||||||||||||||||||
| 1260 | |||||||||||||||||||||||||||||
| 1261 | $x->addLabels_c2_c3_c4; | ||||||||||||||||||||||||||||
| 1262 | $x->createGuidId; | ||||||||||||||||||||||||||||
| 1263 | is_deeply [$x->getLabels], [qw(c1 c2 c3 c4)]; | ||||||||||||||||||||||||||||
| 1264 | |||||||||||||||||||||||||||||
| 1265 | my $l = new; # Linter | ||||||||||||||||||||||||||||
| 1266 | $l->catalog = $catalog; # Catalog | ||||||||||||||||||||||||||||
| 1267 | $l->ditaType = -t $x; # Topic type | ||||||||||||||||||||||||||||
| 1268 | $l->file = fpf($outDir, q(zzz.dita)); # Output file | ||||||||||||||||||||||||||||
| 1269 | $l->guid = $x->id; # Guid | ||||||||||||||||||||||||||||
| 1270 | $l->inputFile = q(zzz.xml); # Add source file information | ||||||||||||||||||||||||||||
| 1271 | $l->labels = $x; # Add label information to the output file so when all the files are written they can be retargeted by Data::Edit::Xml::Lint | ||||||||||||||||||||||||||||
| 1272 | $l->project = q(aaa); # Group files into Id scopes | ||||||||||||||||||||||||||||
| 1273 | $l->title = q(test lint); # Title | ||||||||||||||||||||||||||||
| 1274 | $l->source = $x->ditaPrettyPrintWithHeaders; # Source from parse tree | ||||||||||||||||||||||||||||
| 1275 | $l->lint; | ||||||||||||||||||||||||||||
| 1276 | |||||||||||||||||||||||||||||
| 1277 | my $m = &𝗿𝗲𝗮𝗱($l->file); | ||||||||||||||||||||||||||||
| 1278 | my $y = &reload($l->file); | ||||||||||||||||||||||||||||
| 1279 | ok $l->source eq $m->source; | ||||||||||||||||||||||||||||
| 1280 | ok -p $x eq -p $y; | ||||||||||||||||||||||||||||
| 1281 | is_deeply [$x->getLabels], [$y->getLabels]; | ||||||||||||||||||||||||||||
| 1282 | clearFolder($outDir, 1e2); | ||||||||||||||||||||||||||||
| 1283 | } | ||||||||||||||||||||||||||||
| 1284 | |||||||||||||||||||||||||||||
| 1285 | |||||||||||||||||||||||||||||
| 1286 | This is a static method and so should be invoked as: | ||||||||||||||||||||||||||||
| 1287 | |||||||||||||||||||||||||||||
| 1288 | Data::Edit::Xml::Lint::read | ||||||||||||||||||||||||||||
| 1289 | |||||||||||||||||||||||||||||
| 1290 | |||||||||||||||||||||||||||||
| 1291 | =head2 reload($) | ||||||||||||||||||||||||||||
| 1292 | |||||||||||||||||||||||||||||
| 1293 | Reload a parse tree from a linted file restoring any labels and return the parse tree or B<undef> if the file is not a lint file. | ||||||||||||||||||||||||||||
| 1294 | |||||||||||||||||||||||||||||
| 1295 | Parameter Description | ||||||||||||||||||||||||||||
| 1296 | 1 $file File to read | ||||||||||||||||||||||||||||
| 1297 | |||||||||||||||||||||||||||||
| 1298 | =head2 lintAttributes($) | ||||||||||||||||||||||||||||
| 1299 | |||||||||||||||||||||||||||||
| 1300 | Get all the attributes minus the source of all the linted files in the specified folder | ||||||||||||||||||||||||||||
| 1301 | |||||||||||||||||||||||||||||
| 1302 | Parameter Description | ||||||||||||||||||||||||||||
| 1303 | 1 $folder Folder to search | ||||||||||||||||||||||||||||
| 1304 | |||||||||||||||||||||||||||||
| 1305 | B<Example:> | ||||||||||||||||||||||||||||
| 1306 | |||||||||||||||||||||||||||||
| 1307 | |||||||||||||||||||||||||||||
| 1308 | if (1) | ||||||||||||||||||||||||||||
| 1309 | {my @a = 𝗹𝗶𝗻𝘁𝗔𝘁𝘁𝗿𝗶𝗯𝘂𝘁𝗲𝘀($outDir); | ||||||||||||||||||||||||||||
| 1310 | ok $_->project eq q(aaa) for @a; | ||||||||||||||||||||||||||||
| 1311 | } | ||||||||||||||||||||||||||||
| 1312 | |||||||||||||||||||||||||||||
| 1313 | |||||||||||||||||||||||||||||
| 1314 | This is a static method and so should be invoked as: | ||||||||||||||||||||||||||||
| 1315 | |||||||||||||||||||||||||||||
| 1316 | Data::Edit::Xml::Lint::lintAttributes | ||||||||||||||||||||||||||||
| 1317 | |||||||||||||||||||||||||||||
| 1318 | |||||||||||||||||||||||||||||
| 1319 | =head2 relint($$$@) | ||||||||||||||||||||||||||||
| 1320 | |||||||||||||||||||||||||||||
| 1321 | Locate all the L<labels or id|Data::Edit::Xml/Labels> in the specified L<files|/file>, analyze the map of labels and ids with B<analysisSub> parse each L<file|/file>, process each parse with B<processSub>, then L<lint/lint> the reprocessed xml back to the original L<file|/file> - this allows you to reprocess the contents of each L<file|/file> with knowledge of where L<labels or id|Data::Edit::Xml/Labels> are located in the other L<files|/file> associated with a L<project|/project>. The B<analysisSub>(linkmap = {project}{labels or id>}=[file, id]) should return true if the processing of each file is to be performed subsequently. The B<processSub>(parse tree representation of a file, id and label mapping, reloaded linter) should return true if a L<lint|/lint> is required to save the results after each L<file|/file> has been processed else false. Optionally, the B<analysisSub> may set the L<preferredSource|/preferredSource> attribute to indicate the preferred representation of the xml. | ||||||||||||||||||||||||||||
| 1322 | |||||||||||||||||||||||||||||
| 1323 | Parameter Description | ||||||||||||||||||||||||||||
| 1324 | 1 $processes Maximum number of processes to use | ||||||||||||||||||||||||||||
| 1325 | 2 $analysisSub Analysis 𝘀𝘂𝗯 | ||||||||||||||||||||||||||||
| 1326 | 3 $processSub Process 𝘀𝘂𝗯 | ||||||||||||||||||||||||||||
| 1327 | 4 @foldersAndExtensions Folders and extensions of files to process (recursively) | ||||||||||||||||||||||||||||
| 1328 | |||||||||||||||||||||||||||||
| 1329 | This is a static method and so should be invoked as: | ||||||||||||||||||||||||||||
| 1330 | |||||||||||||||||||||||||||||
| 1331 | Data::Edit::Xml::Lint::relint | ||||||||||||||||||||||||||||
| 1332 | |||||||||||||||||||||||||||||
| 1333 | |||||||||||||||||||||||||||||
| 1334 | =head2 resolveUniqueLink($$) | ||||||||||||||||||||||||||||
| 1335 | |||||||||||||||||||||||||||||
| 1336 | Return the unique (file, leading id) of the specified link in the link map or () if no such definition exists | ||||||||||||||||||||||||||||
| 1337 | |||||||||||||||||||||||||||||
| 1338 | Parameter Description | ||||||||||||||||||||||||||||
| 1339 | 1 $linkMap Link map | ||||||||||||||||||||||||||||
| 1340 | 2 $link Label | ||||||||||||||||||||||||||||
| 1341 | |||||||||||||||||||||||||||||
| 1342 | This is a static method and so should be invoked as: | ||||||||||||||||||||||||||||
| 1343 | |||||||||||||||||||||||||||||
| 1344 | Data::Edit::Xml::Lint::resolveUniqueLink | ||||||||||||||||||||||||||||
| 1345 | |||||||||||||||||||||||||||||
| 1346 | |||||||||||||||||||||||||||||
| 1347 | =head2 urlEncode($) | ||||||||||||||||||||||||||||
| 1348 | |||||||||||||||||||||||||||||
| 1349 | Return a url encoded string | ||||||||||||||||||||||||||||
| 1350 | |||||||||||||||||||||||||||||
| 1351 | Parameter Description | ||||||||||||||||||||||||||||
| 1352 | 1 $s String | ||||||||||||||||||||||||||||
| 1353 | |||||||||||||||||||||||||||||
| 1354 | This is a static method and so should be invoked as: | ||||||||||||||||||||||||||||
| 1355 | |||||||||||||||||||||||||||||
| 1356 | Data::Edit::Xml::Lint::urlEncode | ||||||||||||||||||||||||||||
| 1357 | |||||||||||||||||||||||||||||
| 1358 | |||||||||||||||||||||||||||||
| 1359 | =head2 resolveDitaLink($$$$) | ||||||||||||||||||||||||||||
| 1360 | |||||||||||||||||||||||||||||
| 1361 | Given a specified B<$link>Return the unique (file, leading id, topic ) of the specified link in the link map or () if no such definition exists | ||||||||||||||||||||||||||||
| 1362 | |||||||||||||||||||||||||||||
| 1363 | Parameter Description | ||||||||||||||||||||||||||||
| 1364 | 1 $linkMap Link map | ||||||||||||||||||||||||||||
| 1365 | 2 $fileToGuid File map | ||||||||||||||||||||||||||||
| 1366 | 3 $link Label | ||||||||||||||||||||||||||||
| 1367 | 4 $sourceFile File we are resolving from | ||||||||||||||||||||||||||||
| 1368 | |||||||||||||||||||||||||||||
| 1369 | This is a static method and so should be invoked as: | ||||||||||||||||||||||||||||
| 1370 | |||||||||||||||||||||||||||||
| 1371 | Data::Edit::Xml::Lint::resolveDitaLink | ||||||||||||||||||||||||||||
| 1372 | |||||||||||||||||||||||||||||
| 1373 | |||||||||||||||||||||||||||||
| 1374 | =head2 reuseFileInProject($$) | ||||||||||||||||||||||||||||
| 1375 | |||||||||||||||||||||||||||||
| 1376 | Record the reuse of the specified file in the specified project | ||||||||||||||||||||||||||||
| 1377 | |||||||||||||||||||||||||||||
| 1378 | Parameter Description | ||||||||||||||||||||||||||||
| 1379 | 1 $file Name of file that is being reused | ||||||||||||||||||||||||||||
| 1380 | 2 $project Name of project in which it is reused | ||||||||||||||||||||||||||||
| 1381 | |||||||||||||||||||||||||||||
| 1382 | This is a static method and so should be invoked as: | ||||||||||||||||||||||||||||
| 1383 | |||||||||||||||||||||||||||||
| 1384 | Data::Edit::Xml::Lint::reuseFileInProject | ||||||||||||||||||||||||||||
| 1385 | |||||||||||||||||||||||||||||
| 1386 | |||||||||||||||||||||||||||||
| 1387 | =head2 resolveFileToGuid($$) | ||||||||||||||||||||||||||||
| 1388 | |||||||||||||||||||||||||||||
| 1389 | Return the unique definition of the specified link in the link map or undef if no such definition exists | ||||||||||||||||||||||||||||
| 1390 | |||||||||||||||||||||||||||||
| 1391 | Parameter Description | ||||||||||||||||||||||||||||
| 1392 | 1 $fileToGuids File to guids map | ||||||||||||||||||||||||||||
| 1393 | 2 $file File | ||||||||||||||||||||||||||||
| 1394 | |||||||||||||||||||||||||||||
| 1395 | This is a static method and so should be invoked as: | ||||||||||||||||||||||||||||
| 1396 | |||||||||||||||||||||||||||||
| 1397 | Data::Edit::Xml::Lint::resolveFileToGuid | ||||||||||||||||||||||||||||
| 1398 | |||||||||||||||||||||||||||||
| 1399 | |||||||||||||||||||||||||||||
| 1400 | =head2 multipleLabelDefs($) | ||||||||||||||||||||||||||||
| 1401 | |||||||||||||||||||||||||||||
| 1402 | Return ([L<project|/project>; L<source label or id|Data::Edit::Xml/Labels>; targets count]*) of all L<labels or id|Data::Edit::Xml/Labels> that have multiple definitions | ||||||||||||||||||||||||||||
| 1403 | |||||||||||||||||||||||||||||
| 1404 | Parameter Description | ||||||||||||||||||||||||||||
| 1405 | 1 $labelDefs Label definitions | ||||||||||||||||||||||||||||
| 1406 | |||||||||||||||||||||||||||||
| 1407 | This is a static method and so should be invoked as: | ||||||||||||||||||||||||||||
| 1408 | |||||||||||||||||||||||||||||
| 1409 | Data::Edit::Xml::Lint::multipleLabelDefs | ||||||||||||||||||||||||||||
| 1410 | |||||||||||||||||||||||||||||
| 1411 | |||||||||||||||||||||||||||||
| 1412 | =head2 multipleLabelDefsReport($) | ||||||||||||||||||||||||||||
| 1413 | |||||||||||||||||||||||||||||
| 1414 | Return a L<report|/report> showing L<labels and id|Data::Edit::Xml/Labels> with multiple definitions in each L<project|/project> ordered by most defined | ||||||||||||||||||||||||||||
| 1415 | |||||||||||||||||||||||||||||
| 1416 | Parameter Description | ||||||||||||||||||||||||||||
| 1417 | 1 $labelDefs Label and Id definitions | ||||||||||||||||||||||||||||
| 1418 | |||||||||||||||||||||||||||||
| 1419 | This is a static method and so should be invoked as: | ||||||||||||||||||||||||||||
| 1420 | |||||||||||||||||||||||||||||
| 1421 | Data::Edit::Xml::Lint::multipleLabelDefsReport | ||||||||||||||||||||||||||||
| 1422 | |||||||||||||||||||||||||||||
| 1423 | |||||||||||||||||||||||||||||
| 1424 | =head2 singleLabelDefs($) | ||||||||||||||||||||||||||||
| 1425 | |||||||||||||||||||||||||||||
| 1426 | Return ([L<project|/project>; label or id]*) of all labels or ids that have a single definition | ||||||||||||||||||||||||||||
| 1427 | |||||||||||||||||||||||||||||
| 1428 | Parameter Description | ||||||||||||||||||||||||||||
| 1429 | 1 $labelDefs Label and Id definitions | ||||||||||||||||||||||||||||
| 1430 | |||||||||||||||||||||||||||||
| 1431 | This is a static method and so should be invoked as: | ||||||||||||||||||||||||||||
| 1432 | |||||||||||||||||||||||||||||
| 1433 | Data::Edit::Xml::Lint::singleLabelDefs | ||||||||||||||||||||||||||||
| 1434 | |||||||||||||||||||||||||||||
| 1435 | |||||||||||||||||||||||||||||
| 1436 | =head2 singleLabelDefsReport($) | ||||||||||||||||||||||||||||
| 1437 | |||||||||||||||||||||||||||||
| 1438 | Return a L<report|/report> showing L<label or id|Data::Edit::Xml/Labels> with just one definitions ordered by L<project|/project>, L<label name|Data::Edit::Xml/Labels> | ||||||||||||||||||||||||||||
| 1439 | |||||||||||||||||||||||||||||
| 1440 | Parameter Description | ||||||||||||||||||||||||||||
| 1441 | 1 $labelDefs Label and Id definitions | ||||||||||||||||||||||||||||
| 1442 | |||||||||||||||||||||||||||||
| 1443 | This is a static method and so should be invoked as: | ||||||||||||||||||||||||||||
| 1444 | |||||||||||||||||||||||||||||
| 1445 | Data::Edit::Xml::Lint::singleLabelDefsReport | ||||||||||||||||||||||||||||
| 1446 | |||||||||||||||||||||||||||||
| 1447 | |||||||||||||||||||||||||||||
| 1448 | =head1 Report | ||||||||||||||||||||||||||||
| 1449 | |||||||||||||||||||||||||||||
| 1450 | Methods for L<reporting|Data::Edit::Xml::Lint/report> the results of L<linting|/lint> several L<files|/file> | ||||||||||||||||||||||||||||
| 1451 | |||||||||||||||||||||||||||||
| 1452 | =head2 report($$) | ||||||||||||||||||||||||||||
| 1453 | |||||||||||||||||||||||||||||
| 1454 | Analyze the results of prior L<lints|/lint> and return a hash reporting various statistics and a L<printable|/print> report | ||||||||||||||||||||||||||||
| 1455 | |||||||||||||||||||||||||||||
| 1456 | Parameter Description | ||||||||||||||||||||||||||||
| 1457 | 1 $outputDirectory Directory to search | ||||||||||||||||||||||||||||
| 1458 | 2 $filter Optional regular expression to filter files | ||||||||||||||||||||||||||||
| 1459 | |||||||||||||||||||||||||||||
| 1460 | This is a static method and so should be invoked as: | ||||||||||||||||||||||||||||
| 1461 | |||||||||||||||||||||||||||||
| 1462 | Data::Edit::Xml::Lint::report | ||||||||||||||||||||||||||||
| 1463 | |||||||||||||||||||||||||||||
| 1464 | |||||||||||||||||||||||||||||
| 1465 | =head2 fixDitaXrefHrefs($@) | ||||||||||||||||||||||||||||
| 1466 | |||||||||||||||||||||||||||||
| 1467 | Fix the dita xref href attributes in the corpus determined by B<foldersAndExtensions>. | ||||||||||||||||||||||||||||
| 1468 | |||||||||||||||||||||||||||||
| 1469 | Parameter Description | ||||||||||||||||||||||||||||
| 1470 | 1 $maximumNumberOfProcesses Maximum number of processes to run in parallel | ||||||||||||||||||||||||||||
| 1471 | 2 @foldersAndExtensions Folders and file extensions to process. | ||||||||||||||||||||||||||||
| 1472 | |||||||||||||||||||||||||||||
| 1473 | B<Example:> | ||||||||||||||||||||||||||||
| 1474 | |||||||||||||||||||||||||||||
| 1475 | |||||||||||||||||||||||||||||
| 1476 | 𝗳𝗶𝘅𝗗𝗶𝘁𝗮𝗫𝗿𝗲𝗳𝗛𝗿𝗲𝗳𝘀(1, $outDir, "xml"); | ||||||||||||||||||||||||||||
| 1477 | |||||||||||||||||||||||||||||
| 1478 | |||||||||||||||||||||||||||||
| 1479 | =head2 Attributes | ||||||||||||||||||||||||||||
| 1480 | |||||||||||||||||||||||||||||
| 1481 | =head3 compressedErrors :lvalue | ||||||||||||||||||||||||||||
| 1482 | |||||||||||||||||||||||||||||
| 1483 | Compressed errors over all files | ||||||||||||||||||||||||||||
| 1484 | |||||||||||||||||||||||||||||
| 1485 | |||||||||||||||||||||||||||||
| 1486 | =head3 docTypes :lvalue | ||||||||||||||||||||||||||||
| 1487 | |||||||||||||||||||||||||||||
| 1488 | Array of [number of errors, L<project|/project>, L<files|/file>] ordered from least to most errors | ||||||||||||||||||||||||||||
| 1489 | |||||||||||||||||||||||||||||
| 1490 | |||||||||||||||||||||||||||||
| 1491 | =head3 failingFiles :lvalue | ||||||||||||||||||||||||||||
| 1492 | |||||||||||||||||||||||||||||
| 1493 | {docType}++ - Hash of document types encountered | ||||||||||||||||||||||||||||
| 1494 | |||||||||||||||||||||||||||||
| 1495 | |||||||||||||||||||||||||||||
| 1496 | =head3 failingProjects :lvalue | ||||||||||||||||||||||||||||
| 1497 | |||||||||||||||||||||||||||||
| 1498 | [Projects with xmllint errors] | ||||||||||||||||||||||||||||
| 1499 | |||||||||||||||||||||||||||||
| 1500 | |||||||||||||||||||||||||||||
| 1501 | =head3 filter :lvalue | ||||||||||||||||||||||||||||
| 1502 | |||||||||||||||||||||||||||||
| 1503 | File selection filter | ||||||||||||||||||||||||||||
| 1504 | |||||||||||||||||||||||||||||
| 1505 | |||||||||||||||||||||||||||||
| 1506 | =head3 numberOfFiles :lvalue | ||||||||||||||||||||||||||||
| 1507 | |||||||||||||||||||||||||||||
| 1508 | Number of L<files|/file> encountered | ||||||||||||||||||||||||||||
| 1509 | |||||||||||||||||||||||||||||
| 1510 | |||||||||||||||||||||||||||||
| 1511 | =head3 numberOfProjects :lvalue | ||||||||||||||||||||||||||||
| 1512 | |||||||||||||||||||||||||||||
| 1513 | Number of L<projects|/project> defined - each L<project|/project> can contain zero or more L<files|/file> | ||||||||||||||||||||||||||||
| 1514 | |||||||||||||||||||||||||||||
| 1515 | |||||||||||||||||||||||||||||
| 1516 | =head3 passingProjects :lvalue | ||||||||||||||||||||||||||||
| 1517 | |||||||||||||||||||||||||||||
| 1518 | [Projects with no xmllint errors] | ||||||||||||||||||||||||||||
| 1519 | |||||||||||||||||||||||||||||
| 1520 | |||||||||||||||||||||||||||||
| 1521 | =head3 passRatePercent :lvalue | ||||||||||||||||||||||||||||
| 1522 | |||||||||||||||||||||||||||||
| 1523 | Total number of passes as a percentage of all input files | ||||||||||||||||||||||||||||
| 1524 | |||||||||||||||||||||||||||||
| 1525 | |||||||||||||||||||||||||||||
| 1526 | =head3 print :lvalue | ||||||||||||||||||||||||||||
| 1527 | |||||||||||||||||||||||||||||
| 1528 | A printable L<report|/report> of the above | ||||||||||||||||||||||||||||
| 1529 | |||||||||||||||||||||||||||||
| 1530 | |||||||||||||||||||||||||||||
| 1531 | =head3 timestamp :lvalue | ||||||||||||||||||||||||||||
| 1532 | |||||||||||||||||||||||||||||
| 1533 | Timestamp of report | ||||||||||||||||||||||||||||
| 1534 | |||||||||||||||||||||||||||||
| 1535 | |||||||||||||||||||||||||||||
| 1536 | =head3 totalCompressedErrorsFileByFile :lvalue | ||||||||||||||||||||||||||||
| 1537 | |||||||||||||||||||||||||||||
| 1538 | Total number of errors summed file by file | ||||||||||||||||||||||||||||
| 1539 | |||||||||||||||||||||||||||||
| 1540 | |||||||||||||||||||||||||||||
| 1541 | =head3 totalCompressedErrors :lvalue | ||||||||||||||||||||||||||||
| 1542 | |||||||||||||||||||||||||||||
| 1543 | Number of compressed errors | ||||||||||||||||||||||||||||
| 1544 | |||||||||||||||||||||||||||||
| 1545 | |||||||||||||||||||||||||||||
| 1546 | =head3 totalErrors :lvalue | ||||||||||||||||||||||||||||
| 1547 | |||||||||||||||||||||||||||||
| 1548 | Total number of errors | ||||||||||||||||||||||||||||
| 1549 | |||||||||||||||||||||||||||||
| 1550 | |||||||||||||||||||||||||||||
| 1551 | |||||||||||||||||||||||||||||
| 1552 | =head1 Private Methods | ||||||||||||||||||||||||||||
| 1553 | |||||||||||||||||||||||||||||
| 1554 | =head2 lint($@) | ||||||||||||||||||||||||||||
| 1555 | |||||||||||||||||||||||||||||
| 1556 | Lint a L<files|/file>, using xmllint and update the source file with the results in text format so as to be be easy to search with grep. | ||||||||||||||||||||||||||||
| 1557 | |||||||||||||||||||||||||||||
| 1558 | Parameter Description | ||||||||||||||||||||||||||||
| 1559 | 1 $lint Linter | ||||||||||||||||||||||||||||
| 1560 | 2 %attributes Attributes to be recorded as xml comments | ||||||||||||||||||||||||||||
| 1561 | |||||||||||||||||||||||||||||
| 1562 | =head2 compressErrors(@) | ||||||||||||||||||||||||||||
| 1563 | |||||||||||||||||||||||||||||
| 1564 | Compress the errors so we count the ones that do not look similar. Errors typically occupy three lines with the last line containing ^ at the end to mark the location of the error. | ||||||||||||||||||||||||||||
| 1565 | |||||||||||||||||||||||||||||
| 1566 | Parameter Description | ||||||||||||||||||||||||||||
| 1567 | 1 @errors Errors | ||||||||||||||||||||||||||||
| 1568 | |||||||||||||||||||||||||||||
| 1569 | This is a static method and so should be invoked as: | ||||||||||||||||||||||||||||
| 1570 | |||||||||||||||||||||||||||||
| 1571 | Data::Edit::Xml::Lint::compressErrors | ||||||||||||||||||||||||||||
| 1572 | |||||||||||||||||||||||||||||
| 1573 | |||||||||||||||||||||||||||||
| 1574 | =head2 formatAttributes(%) | ||||||||||||||||||||||||||||
| 1575 | |||||||||||||||||||||||||||||
| 1576 | Format the attributes section of the output file | ||||||||||||||||||||||||||||
| 1577 | |||||||||||||||||||||||||||||
| 1578 | Parameter Description | ||||||||||||||||||||||||||||
| 1579 | 1 $attributes Hash of attributes | ||||||||||||||||||||||||||||
| 1580 | |||||||||||||||||||||||||||||
| 1581 | =head2 reuseInProject($) | ||||||||||||||||||||||||||||
| 1582 | |||||||||||||||||||||||||||||
| 1583 | Record the reuse of an item in the named project | ||||||||||||||||||||||||||||
| 1584 | |||||||||||||||||||||||||||||
| 1585 | Parameter Description | ||||||||||||||||||||||||||||
| 1586 | 1 $project Name of the project in which it is reused | ||||||||||||||||||||||||||||
| 1587 | |||||||||||||||||||||||||||||
| 1588 | This is a static method and so should be invoked as: | ||||||||||||||||||||||||||||
| 1589 | |||||||||||||||||||||||||||||
| 1590 | Data::Edit::Xml::Lint::reuseInProject | ||||||||||||||||||||||||||||
| 1591 | |||||||||||||||||||||||||||||
| 1592 | |||||||||||||||||||||||||||||
| 1593 | =head2 countLinkTargets($$) | ||||||||||||||||||||||||||||
| 1594 | |||||||||||||||||||||||||||||
| 1595 | Count the number of targets this link resolves to. | ||||||||||||||||||||||||||||
| 1596 | |||||||||||||||||||||||||||||
| 1597 | Parameter Description | ||||||||||||||||||||||||||||
| 1598 | 1 $linkMap Link map | ||||||||||||||||||||||||||||
| 1599 | 2 $link Label | ||||||||||||||||||||||||||||
| 1600 | |||||||||||||||||||||||||||||
| 1601 | This is a static method and so should be invoked as: | ||||||||||||||||||||||||||||
| 1602 | |||||||||||||||||||||||||||||
| 1603 | Data::Edit::Xml::Lint::countLinkTargets | ||||||||||||||||||||||||||||
| 1604 | |||||||||||||||||||||||||||||
| 1605 | |||||||||||||||||||||||||||||
| 1606 | =head2 p4($$) | ||||||||||||||||||||||||||||
| 1607 | |||||||||||||||||||||||||||||
| 1608 | Format a fraction as a percentage to 4 decimal places | ||||||||||||||||||||||||||||
| 1609 | |||||||||||||||||||||||||||||
| 1610 | Parameter Description | ||||||||||||||||||||||||||||
| 1611 | 1 $p Pass | ||||||||||||||||||||||||||||
| 1612 | 2 $f Fail | ||||||||||||||||||||||||||||
| 1613 | |||||||||||||||||||||||||||||
| 1614 | This is a static method and so should be invoked as: | ||||||||||||||||||||||||||||
| 1615 | |||||||||||||||||||||||||||||
| 1616 | Data::Edit::Xml::Lint::p4 | ||||||||||||||||||||||||||||
| 1617 | |||||||||||||||||||||||||||||
| 1618 | |||||||||||||||||||||||||||||
| 1619 | =head2 createTest($$$$) | ||||||||||||||||||||||||||||
| 1620 | |||||||||||||||||||||||||||||
| 1621 | Create a test file | ||||||||||||||||||||||||||||
| 1622 | |||||||||||||||||||||||||||||
| 1623 | Parameter Description | ||||||||||||||||||||||||||||
| 1624 | 1 $project Project name | ||||||||||||||||||||||||||||
| 1625 | 2 $source Source of topic | ||||||||||||||||||||||||||||
| 1626 | 3 $target Target of references | ||||||||||||||||||||||||||||
| 1627 | 4 $additional Additional text for topic | ||||||||||||||||||||||||||||
| 1628 | |||||||||||||||||||||||||||||
| 1629 | =head2 createTests() | ||||||||||||||||||||||||||||
| 1630 | |||||||||||||||||||||||||||||
| 1631 | Create some tests | ||||||||||||||||||||||||||||
| 1632 | |||||||||||||||||||||||||||||
| 1633 | |||||||||||||||||||||||||||||
| 1634 | |||||||||||||||||||||||||||||
| 1635 | =head1 Index | ||||||||||||||||||||||||||||
| 1636 | |||||||||||||||||||||||||||||
| 1637 | |||||||||||||||||||||||||||||
| 1638 | 1 L<author|/author> - Optional author of the xml - only needed if you want to generate an SDL file map. | ||||||||||||||||||||||||||||
| 1639 | |||||||||||||||||||||||||||||
| 1640 | 2 L<catalog|/catalog> - Optional catalog file containing the locations of the DTDs used to validate the xml or use L<dtds|/dtds> to supply a B<DTD> instead. | ||||||||||||||||||||||||||||
| 1641 | |||||||||||||||||||||||||||||
| 1642 | 3 L<compressedErrors|/compressedErrors> - Compressed errors over all files | ||||||||||||||||||||||||||||
| 1643 | |||||||||||||||||||||||||||||
| 1644 | 4 L<compressedErrorText|/compressedErrorText> - Text of compressed errors. | ||||||||||||||||||||||||||||
| 1645 | |||||||||||||||||||||||||||||
| 1646 | 5 L<compressErrors|/compressErrors> - Compress the errors so we count the ones that do not look similar. | ||||||||||||||||||||||||||||
| 1647 | |||||||||||||||||||||||||||||
| 1648 | 6 L<countLinkTargets|/countLinkTargets> - Count the number of targets this link resolves to. | ||||||||||||||||||||||||||||
| 1649 | |||||||||||||||||||||||||||||
| 1650 | 7 L<createTest|/createTest> - Create a test file | ||||||||||||||||||||||||||||
| 1651 | |||||||||||||||||||||||||||||
| 1652 | 8 L<createTests|/createTests> - Create some tests | ||||||||||||||||||||||||||||
| 1653 | |||||||||||||||||||||||||||||
| 1654 | 9 L<ditaType|/ditaType> - Optional Dita topic type(concept|task|troubleshooting|reference) of the xml - only needed if you want to generate an SDL file map. | ||||||||||||||||||||||||||||
| 1655 | |||||||||||||||||||||||||||||
| 1656 | 10 L<docType|/docType> - The second line: the document type extracted from the L<source|/source>. | ||||||||||||||||||||||||||||
| 1657 | |||||||||||||||||||||||||||||
| 1658 | 11 L<docTypes|/docTypes> - Array of [number of errors, L<project|/project>, L<files|/file>] ordered from least to most errors | ||||||||||||||||||||||||||||
| 1659 | |||||||||||||||||||||||||||||
| 1660 | 12 L<dtds|/dtds> - Optional directory containing the DTDs used to validate the xml. | ||||||||||||||||||||||||||||
| 1661 | |||||||||||||||||||||||||||||
| 1662 | 13 L<errors|/errors> - Total number of uncompressed lint errors detected by xmllint over all files. | ||||||||||||||||||||||||||||
| 1663 | |||||||||||||||||||||||||||||
| 1664 | 14 L<errorText|/errorText> - Text of uncompressed lint errors detected by xmllint over all files. | ||||||||||||||||||||||||||||
| 1665 | |||||||||||||||||||||||||||||
| 1666 | 15 L<failingFiles|/failingFiles> - {docType}++ - Hash of document types encountered | ||||||||||||||||||||||||||||
| 1667 | |||||||||||||||||||||||||||||
| 1668 | 16 L<failingProjects|/failingProjects> - [Projects with xmllint errors] | ||||||||||||||||||||||||||||
| 1669 | |||||||||||||||||||||||||||||
| 1670 | 17 L<file|/file> - File that the xml should be written to or read from by L<lint|/lint>, L<read|/read> or L<relint|/relint>. | ||||||||||||||||||||||||||||
| 1671 | |||||||||||||||||||||||||||||
| 1672 | 18 L<fileNumber|/fileNumber> - File number - assigned by the caller to help debugging transformations. | ||||||||||||||||||||||||||||
| 1673 | |||||||||||||||||||||||||||||
| 1674 | 19 L<filter|/filter> - File selection filter | ||||||||||||||||||||||||||||
| 1675 | |||||||||||||||||||||||||||||
| 1676 | 20 L<fixDitaXrefHrefs|/fixDitaXrefHrefs> - Fix the dita xref href attributes in the corpus determined by B<foldersAndExtensions>. | ||||||||||||||||||||||||||||
| 1677 | |||||||||||||||||||||||||||||
| 1678 | 21 L<formatAttributes|/formatAttributes> - Format the attributes section of the output file | ||||||||||||||||||||||||||||
| 1679 | |||||||||||||||||||||||||||||
| 1680 | 22 L<guid|/guid> - Guid or id of the outermost tag - if not supplied the first definition encountered in each file will be used on the basis that all Dita topics require an id. | ||||||||||||||||||||||||||||
| 1681 | |||||||||||||||||||||||||||||
| 1682 | 23 L<header|/header> - The first line: the xml header extracted from L<source|/source>. | ||||||||||||||||||||||||||||
| 1683 | |||||||||||||||||||||||||||||
| 1684 | 24 L<idDefs|/idDefs> - {id} = count - the number of times this id is defined in the xml contained in this L<file|/file>. | ||||||||||||||||||||||||||||
| 1685 | |||||||||||||||||||||||||||||
| 1686 | 25 L<inputFile|/inputFile> - The file from which this xml was obtained. | ||||||||||||||||||||||||||||
| 1687 | |||||||||||||||||||||||||||||
| 1688 | 26 L<labelDefs|/labelDefs> - {label or id} = id - the id of the node containing a L<label|Data::Edit::Xml/Labels> defined on the xml. | ||||||||||||||||||||||||||||
| 1689 | |||||||||||||||||||||||||||||
| 1690 | 27 L<labels|/labels> - Optional parse tree to supply L<labels|Data::Edit::Xml/Labels> for the current L<source|/source> as the labels are present in the parse tree not in the string representing the parse tree. | ||||||||||||||||||||||||||||
| 1691 | |||||||||||||||||||||||||||||
| 1692 | 28 L<lineNumber|/lineNumber> - The file and line number of the caller so we can identify which request for lint gave rise to a particular file | ||||||||||||||||||||||||||||
| 1693 | |||||||||||||||||||||||||||||
| 1694 | 29 L<lint|/lint> - Lint a L<files|/file>, using xmllint and update the source file with the results in text format so as to be be easy to search with grep. | ||||||||||||||||||||||||||||
| 1695 | |||||||||||||||||||||||||||||
| 1696 | 30 L<lintAttributes|/lintAttributes> - Get all the attributes minus the source of all the linted files in the specified folder | ||||||||||||||||||||||||||||
| 1697 | |||||||||||||||||||||||||||||
| 1698 | 31 L<linted|/linted> - Date the lint was performed by L<lint|/lint>. | ||||||||||||||||||||||||||||
| 1699 | |||||||||||||||||||||||||||||
| 1700 | 32 L<multipleLabelDefs|/multipleLabelDefs> - Return ([L<project|/project>; L<source label or id|Data::Edit::Xml/Labels>; targets count]*) of all L<labels or id|Data::Edit::Xml/Labels> that have multiple definitions | ||||||||||||||||||||||||||||
| 1701 | |||||||||||||||||||||||||||||
| 1702 | 33 L<multipleLabelDefsReport|/multipleLabelDefsReport> - Return a L<report|/report> showing L<labels and id|Data::Edit::Xml/Labels> with multiple definitions in each L<project|/project> ordered by most defined | ||||||||||||||||||||||||||||
| 1703 | |||||||||||||||||||||||||||||
| 1704 | 34 L<new|/new> - Create a new xml linter - call this method statically as in L<Data::Edit::Xml::Lint|/new> and then fill in the relevant L<Attributes>. | ||||||||||||||||||||||||||||
| 1705 | |||||||||||||||||||||||||||||
| 1706 | 35 L<nolint|/nolint> - Store just the attributes in a file so that they can be retrieved later to process non xml objects referenced in the xml - like images | ||||||||||||||||||||||||||||
| 1707 | |||||||||||||||||||||||||||||
| 1708 | 36 L<numberOfFiles|/numberOfFiles> - Number of L<files|/file> encountered | ||||||||||||||||||||||||||||
| 1709 | |||||||||||||||||||||||||||||
| 1710 | 37 L<numberOfProjects|/numberOfProjects> - Number of L<projects|/project> defined - each L<project|/project> can contain zero or more L<files|/file> | ||||||||||||||||||||||||||||
| 1711 | |||||||||||||||||||||||||||||
| 1712 | 38 L<p4|/p4> - Format a fraction as a percentage to 4 decimal places | ||||||||||||||||||||||||||||
| 1713 | |||||||||||||||||||||||||||||
| 1714 | 39 L<passingProjects|/passingProjects> - [Projects with no xmllint errors] | ||||||||||||||||||||||||||||
| 1715 | |||||||||||||||||||||||||||||
| 1716 | 40 L<passRatePercent|/passRatePercent> - Total number of passes as a percentage of all input files | ||||||||||||||||||||||||||||
| 1717 | |||||||||||||||||||||||||||||
| 1718 | 41 L<preferredSource|/preferredSource> - Preferred representation of the xml source, used by L<relint|/relint> to supply a preferred representation for the source. | ||||||||||||||||||||||||||||
| 1719 | |||||||||||||||||||||||||||||
| 1720 | 42 L<print|/print> - A printable L<report|/report> of the above | ||||||||||||||||||||||||||||
| 1721 | |||||||||||||||||||||||||||||
| 1722 | 43 L<processes|/processes> - Maximum number of xmllint processes to run in parallel - 8 by default if linting in parallel is being used. | ||||||||||||||||||||||||||||
| 1723 | |||||||||||||||||||||||||||||
| 1724 | 44 L<project|/project> - Optional L<project|/project> name to allow error counts to be aggregated by L<project|/project> and to allow L<id and labels|Data::Edit::Xml/Labels> to be scoped to the L<files|/file> contained in each L<project|/project>. | ||||||||||||||||||||||||||||
| 1725 | |||||||||||||||||||||||||||||
| 1726 | 45 L<read|/read> - Reread a linted xml L<file|/file> and extract the L<attributes|/Attributes> associated with the L<lint|/lint> | ||||||||||||||||||||||||||||
| 1727 | |||||||||||||||||||||||||||||
| 1728 | 46 L<relint|/relint> - Locate all the L<labels or id|Data::Edit::Xml/Labels> in the specified L<files|/file>, analyze the map of labels and ids with B<analysisSub> parse each L<file|/file>, process each parse with B<processSub>, then L<lint/lint> the reprocessed xml back to the original L<file|/file> - this allows you to reprocess the contents of each L<file|/file> with knowledge of where L<labels or id|Data::Edit::Xml/Labels> are located in the other L<files|/file> associated with a L<project|/project>. | ||||||||||||||||||||||||||||
| 1729 | |||||||||||||||||||||||||||||
| 1730 | 47 L<reload|/reload> - Reload a parse tree from a linted file restoring any labels and return the parse tree or B<undef> if the file is not a lint file. | ||||||||||||||||||||||||||||
| 1731 | |||||||||||||||||||||||||||||
| 1732 | 48 L<report|/report> - Analyze the results of prior L<lints|/lint> and return a hash reporting various statistics and a L<printable|/print> report | ||||||||||||||||||||||||||||
| 1733 | |||||||||||||||||||||||||||||
| 1734 | 49 L<resolveDitaLink|/resolveDitaLink> - Given a specified B<$link>Return the unique (file, leading id, topic ) of the specified link in the link map or () if no such definition exists | ||||||||||||||||||||||||||||
| 1735 | |||||||||||||||||||||||||||||
| 1736 | 50 L<resolveFileToGuid|/resolveFileToGuid> - Return the unique definition of the specified link in the link map or undef if no such definition exists | ||||||||||||||||||||||||||||
| 1737 | |||||||||||||||||||||||||||||
| 1738 | 51 L<resolveUniqueLink|/resolveUniqueLink> - Return the unique (file, leading id) of the specified link in the link map or () if no such definition exists | ||||||||||||||||||||||||||||
| 1739 | |||||||||||||||||||||||||||||
| 1740 | 52 L<reusedInProject|/reusedInProject> - List of projects in which this file is reused, which can be set via L<reuseFileInProject|/reuseFileInProject> every time you discover another project in which a file is reused. | ||||||||||||||||||||||||||||
| 1741 | |||||||||||||||||||||||||||||
| 1742 | 53 L<reuseFileInProject|/reuseFileInProject> - Record the reuse of the specified file in the specified project | ||||||||||||||||||||||||||||
| 1743 | |||||||||||||||||||||||||||||
| 1744 | 54 L<reuseInProject|/reuseInProject> - Record the reuse of an item in the named project | ||||||||||||||||||||||||||||
| 1745 | |||||||||||||||||||||||||||||
| 1746 | 55 L<singleLabelDefs|/singleLabelDefs> - Return ([L<project|/project>; label or id]*) of all labels or ids that have a single definition | ||||||||||||||||||||||||||||
| 1747 | |||||||||||||||||||||||||||||
| 1748 | 56 L<singleLabelDefsReport|/singleLabelDefsReport> - Return a L<report|/report> showing L<label or id|Data::Edit::Xml/Labels> with just one definitions ordered by L<project|/project>, L<label name|Data::Edit::Xml/Labels> | ||||||||||||||||||||||||||||
| 1749 | |||||||||||||||||||||||||||||
| 1750 | 57 L<source|/source> - The source Xml to be written to L<file|/file> and linted. | ||||||||||||||||||||||||||||
| 1751 | |||||||||||||||||||||||||||||
| 1752 | 58 L<squeezeDitaRef|/squeezeDitaRef> - Squeeze a string so it can be safely stored inside blank separated list inside an xml comment. | ||||||||||||||||||||||||||||
| 1753 | |||||||||||||||||||||||||||||
| 1754 | 59 L<timestamp|/timestamp> - Timestamp of report | ||||||||||||||||||||||||||||
| 1755 | |||||||||||||||||||||||||||||
| 1756 | 60 L<title|/title> - Optional title of the xml - only needed if you want to generate an SDL file map. | ||||||||||||||||||||||||||||
| 1757 | |||||||||||||||||||||||||||||
| 1758 | 61 L<totalCompressedErrors|/totalCompressedErrors> - Number of compressed errors | ||||||||||||||||||||||||||||
| 1759 | |||||||||||||||||||||||||||||
| 1760 | 62 L<totalCompressedErrorsFileByFile|/totalCompressedErrorsFileByFile> - Total number of errors summed file by file | ||||||||||||||||||||||||||||
| 1761 | |||||||||||||||||||||||||||||
| 1762 | 63 L<totalErrors|/totalErrors> - Total number of errors | ||||||||||||||||||||||||||||
| 1763 | |||||||||||||||||||||||||||||
| 1764 | 64 L<urlEncode|/urlEncode> - Return a url encoded string | ||||||||||||||||||||||||||||
| 1765 | |||||||||||||||||||||||||||||
| 1766 | =head1 Installation | ||||||||||||||||||||||||||||
| 1767 | |||||||||||||||||||||||||||||
| 1768 | This module is written in 100% Pure Perl and, thus, it is easy to read, | ||||||||||||||||||||||||||||
| 1769 | comprehend, use, modify and install via B<cpan>: | ||||||||||||||||||||||||||||
| 1770 | |||||||||||||||||||||||||||||
| 1771 | sudo cpan install Data::Edit::Xml::Lint | ||||||||||||||||||||||||||||
| 1772 | |||||||||||||||||||||||||||||
| 1773 | =head1 Author | ||||||||||||||||||||||||||||
| 1774 | |||||||||||||||||||||||||||||
| 1775 | L<philiprbrenan@gmail.com|mailto:philiprbrenan@gmail.com> | ||||||||||||||||||||||||||||
| 1776 | |||||||||||||||||||||||||||||
| 1777 | L<http://www.appaapps.com|http://www.appaapps.com> | ||||||||||||||||||||||||||||
| 1778 | |||||||||||||||||||||||||||||
| 1779 | =head1 Copyright | ||||||||||||||||||||||||||||
| 1780 | |||||||||||||||||||||||||||||
| 1781 | Copyright (c) 2016-2019 Philip R Brenan. | ||||||||||||||||||||||||||||
| 1782 | |||||||||||||||||||||||||||||
| 1783 | This module is free software. It may be used, redistributed and/or modified | ||||||||||||||||||||||||||||
| 1784 | under the same terms as Perl itself. | ||||||||||||||||||||||||||||
| 1785 | |||||||||||||||||||||||||||||
| 1786 | =cut | ||||||||||||||||||||||||||||
| 1787 | |||||||||||||||||||||||||||||
| 1788 | |||||||||||||||||||||||||||||
| 1789 | |||||||||||||||||||||||||||||
| 1790 | # Tests and documentation | ||||||||||||||||||||||||||||
| 1791 | |||||||||||||||||||||||||||||
| 1792 | sub test | ||||||||||||||||||||||||||||
| 1793 | 1 | ▶ | {my $p = __PACKAGE__; | ||||||||||||||||||||||||||
|
Subroutine
test: called CC=5 SCAR=16.5
Pod
undocumented
| |||||||||||||||||||||||||||||
| 1794 | 1 | binmode($_, ":utf8") for *STDOUT, *STDERR; | |||||||||||||||||||||||||||
| 1795 | 1 | ▶ | return if eval "eof(${p}::DATA)"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1796 | 1 | my $s = eval "join('', <${p}::DATA>)"; | |||||||||||||||||||||||||||
| 1797 | 1 | ▶ | $@ and die $@; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1798 | 0 | ▶ | eval $s; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 1799 | 1 | ▶ | $@ and die $@; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1800 | 0 | 1 | |||||||||||||||||||||||||||
| 1801 | } | ||||||||||||||||||||||||||||
| 1802 | |||||||||||||||||||||||||||||
| 1803 | 1 | ▶ | test unless caller; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1804 | |||||||||||||||||||||||||||||
| 1805 | 1 | 1; | |||||||||||||||||||||||||||
| 1806 | # podDocumentation | ||||||||||||||||||||||||||||
| 1807 | __DATA__ | ||||||||||||||||||||||||||||