blib/lib/Dita/PCD.pm

filter: Statementstmt 86.6% 13 / 15 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 5 / 5 Podpod n/a totaltotal 90.0% 18 / 20 CC 1 SCAR 0.6
CC
1
Cov
87%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
↑ Summary
1 #!/usr/bin/perl -I/home/phil/perl/cpan/DataEditXml/lib/ -I/home/phil/perl/cpan/DataTableText/lib/
2 #-------------------------------------------------------------------------------
3 # Dita::PCD - Implementation of the Please Change Dita Language.
4 # Philip R Brenan at gmail dot com, Appa Apps Ltd Inc., 2019
5 #-------------------------------------------------------------------------------
6 #podDocumentation
7 # cd /home/phil/perl/cpan/DitaPCD/; perl Build.PL && perl Build test && sudo perl Build install
8 # initial - 0.1296. checkout: 0.083, optimized: 0.064 with each command a sub
9  
10 package Dita::PCD;
11 our $VERSION = 20201103;
12 1 ▶use warnings FATAL => qw(all);
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use Carp qw(confess cluck);
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use Data::Dump qw(dump);
Subroutine BEGIN: called CC=1 SCAR=0.0
16 0 ▶use Data::Edit::Xml;
Subroutine BEGIN: called CC=1 SCAR=2.6
17 use Data::Table::Text qw(:all);
18  
19 sub padLength {8} # Padding length for editor fields
20  
21 #D1 Please Change Dita # Edit L<Dita> using directives written in L<pcd>. An introduction to l<pcd> can be found at: L<pcdLang>.
22  
23 sub ditaPcdBase($) #P Base of various objects used by the editor
24 {my ($rowType) = @_; # Row type
25 (action => q(), # Action to be applied to the comment
26 actionError => q(), # Error in chosen action if true
27 rowType => $rowType, # Row type
28 rowTypeError => q(), # Error in chosen row type if true
29 );
30 }
31  
32 sub newDitaPcdComment(%) #P Create a new comment
33 {my (%options) = @_; # Attributes
34 my $h =
35 genHash(q(DitaPcdComment), # Description of a comment
36 ditaPcdBase(q(comment)), # Common row start
37 comment => q(), # Comment text
38 );
39 loadHash($h, %options)
40 }
41  
42 sub newDitaPcdDescription(%) #P Create a new description
43 {my (%options) = @_; # Attributes
44 my $h =
45 genHash(q(DitaPcdDescription), # Description
46 ditaPcdBase(q(description)), # Common row start
47 description => q(), # Description text
48 );
49 loadHash($h, %options)
50 }
51  
52 sub newDitaPcdMethod(%) #P Create a new Method
53 {my (%options) = @_; # Attributes
54 my $h =
55 genHash(q(DitaPcdMethod),
56 ditaPcdBase(q(method)), # Common row start
57 context => [], # Context for this method call
58 contextErrors => {}, # Errors in chosen context if entries present
59 methodError => q(), # Error in chosen method if true
60 method => q(), # Method name - a unitary method in Data::Edit::Xml
61 );
62 loadHash($h, %options)
63 }
64  
65 sub newDitaPcdParseTree(%) #P Create a new Parse Tree
66 {my (%options) = @_; # Attributes
67 my $h =
68 genHash(q(DitaPCDParseTree),
69 inputFile => q(),
70 errors => [],
71 rows => [],
72 );
73 loadHash($h, %options)
74 }
75  
76 sub parsePcdString($) #P Parse the specified L<pcd> directives B<$string> specifying changes to be made to L<dita> files.
77 {my ($string) = @_; # String of PCD directives
78  
79 my $ditaTags = &pcdDitaTags; # Dita tag names
80 my @i = split /\n/, $string;
81 my @p; # Parse tree
82  
83 for my $i(keys @i) # Each line==row of a pcd file
84 {my $l = $i[$i]; # Row to process
85 my $j = $i + 1; # Current row number
86  
87 next unless $l =~ m(\S); # Ignore empty rows
88  
89 if ($l =~ m(\A\s*#\s*(.*?)\s*\Z)) # Comment
90 {push @p, newDitaPcdComment(comment=>trim($1));
91 }
92 elsif ($l =~ m(\A\S)) # Description
93 {push @p, newDitaPcdDescription(description=>$l);
94 }
95 else # Method
96 {if (my ($method, @context) = split m/\s+/, trim($l)) # Parse command string invoking method
97 {push @p, newDitaPcdMethod(method=>$method, context=>[@context]);
98 }
99 }
100 }
101  
102 newDitaPcdParseTree(rows => \@p) # Parse tree
103 } # parsePcdString
104  
105 sub parsePcdFile($) #P Parse the specified L<pcd> directives B<$file> specifying changes to be made to L<dita> files.
106 {my ($if) = @_; # Input file
107 my $p = parsePcdString(readFile($if)); # Read and parse file
108 $p->inputFile = $if; # Add input file detail
109 $p # Return parse tree
110 } # parsePcdFile
111  
112 sub editPcdParseTree($) #P Validate a B<$parseTree>
113 {my ($parseTree) = @_; # Parse tree
114  
115 my $ditaTags = {map {$_=>1} &pcdDitaTags}; # Dita tag names
116 my $rowActions = {map {$_=>1} &pcdRowActions}; # Row actions
117 my $rowTypes = {map {$_=>1} &pcdRowTypes}; # Row types
118  
119 my @l = @{$parseTree->rows}; # Rows in parse tree
120 my @errors;
121 my @delete;
122 my @repeat;
123 my @source;
124 my @target;
125  
126 for my $l(@l) # Each line==row of a pcd file
127 {if (my $action = $l->action) # Validate action
128 {if ($action =~ m(\A(after|before)\Z)i)
129 {push @target, $l;
130 }
131 elsif ($action =~ m(\A(copy|move)\Z)i)
132 {push @source, $l;
133 }
134 elsif ($action =~ m(\Adelete\Z)i)
135 {push @delete, $l;
136 }
137 elsif ($action =~ m(\Arepeat\Z)i)
138 {push @repeat, $l;
139 }
140 elsif (!$$rowActions{$action})
141 {$l->actionError = "No such action";
142 # push @errors, $l;
143 }
144 }
145  
146 if (my $rowType = $l->rowType) # Validate row type
147 {if (!$$rowTypes{$rowType})
148 {$l->methodError = q(No such row type);
149 # push @errors, $l;
150 }
151 }
152  
153 if (ref($l) =~ m(method)i and my $method = $l->method) # Validate method
154 {if (!isSubInPackage(q(Data::Edit::Xml), $method))
155 {$l->methodError = q(No such method);
156 # push @errors, $l;
157 }
158  
159 if (my $context = $l->context) # Validate context of method
160 {for my $c(@$context)
161 {if (!$$ditaTags{$c})
162 {$l->contextErrors->{$c}++;
163 # push @errors, $l;
164 }
165 }
166 }
167 }
168 }
169  
170 if (@target == 0 and @source == 1) # Paste required if copy or move
171 {for my $l(@source)
172 {$l->actionError = "At least one after or before required";
173 push @errors, $l;
174 }
175 }
176  
177 if (@source > 1) # Only one copy or move allowed
178 {for my $l(@source)
179 {$l->actionError = "More than one copy and/or move";
180 push @errors, $l;
181 }
182 }
183  
184 if (!@errors and @repeat || @delete) # Perform delete or repeat
185 {my @e;
186 for my $l(@{$parseTree->rows})
187 {if ($l->action =~ m(\Adelete\Z)i) {}
188 elsif ($l->action =~ m(\Arepeat\Z)i) {push @e, $l, $l}
189 else {push @e, $l}
190 }
191 $parseTree->rows = \@e;
192 }
193  
194 if (!@errors and @source and @target) # Perform copy|move after|before
195 {for my $source(@source)
196 {my @e;
197 for my $l(@{$parseTree->rows})
198 {if ($l == $source)
199 {if ($l->action =~ m(\Acopy\Z)i)
200 {push @e, $l;
201 }
202 }
203 else
204 {sub
205 {for my $target(@target)
206 {if ($l == $target)
207 {if ($target->action =~ m(\Abefore\Z)i)
208 {push @e, $source, $l;
209 }
210 else
211 {push @e, $l, $source;
212 }
213 return;
214 }
215 }
216 push @e, $l;
217 }->();
218 }
219 }
220  
221 $parseTree->rows = @e ? \@e : newDitaPcdComment(comment=>q()); # Make sure there is at least one row in the parse tree otherwise it will be difficult to edit it
222 }
223 }
224  
225 if (!@errors) # Remove actions now they have been successfully performed
226 {for my $l(@{$parseTree->rows})
227 {$l->action = q();
228 }
229 }
230  
231 $parseTree->errors = \@errors; # List of rows with errors
232  
233 $parseTree # Return parse tree
234 } # editPcdParseTree
235  
236 sub makeDataList($@) #P Create a data list
237 {my ($name, @values) = @_; # Name, values
238 join " ", qq(<datalist id="$name">), (map {qq(<option value="$_">)} sort @values), q(</datalist>);
239 }
240  
241 sub representPcdParseTreeAsHtml($) #P Parse the specified L<pcd> directives B<$file> specifying changes to be made to L<dita> files.
242 {my ($parseTree) = @_; # Parse tree
243  
244 editPcdParseTree $parseTree; # Annotate with any errors and return
245  
246 my $ditaTags = map {$_=>1} &pcdDitaTags; # Dita tag names
247  
248 my @h; # Generated html
249 push @h, qq(<form class="editor" name="editor">);
250 push @h, qq(<div oninput="expandInputField(event)" class="editor" name="editor">);
251 push @h, q(<table border="0" cellpadding="10" cellspacing="10">);
252 my @l = @{$parseTree->rows};
253 for my $i(keys @l) # Show each row
254 {my $I = $i + 1;
255 my $R = sprintf("%08d_", $I); # Unlikely to be this many rows in a PCD
256 my $l = $l[$i];
257 my $a = $l->action;
258 my $t = lc ref($l) =~ s(\ADitaPcd) ()ir;
259  
260 my $n = $l->rowType = sub
261 {return q(comment) if ref($l) =~ m(comment)i;
262 return q(description) if ref($l) =~ m(description)i;
263 return q(method) if ref($l) =~ m(method)i;
264 confess "Unknown row type: ".ref($l);
265 }->();
266  
267 my $d = $l->{$n}; my $D = length(pad($d, padLength));
268 my $ae = $l->actionError ? q(actionError) : q();
269 my $me = $n =~ m(method) && $l->methodError ? q(methodError) : q();
270 my $te = $l->rowTypeError ? q(rowTypeError) : q();
271  
272 push @h,
273 qq(<tr><td>),
274 qq(<div class="row">),
275 qq(<span class="rowNumber">$I</span>),
276 qq(<input class="action $ae" name="${R}action" list="actions" size="10" type="text" value="$a">),
277 qq(<input name="${R}rowType1" type="hidden" value="$t">),
278 qq(<input class="rowType $te" name="${R}rowType2" list="rowTypes" size="12" type="text" value="$n">),
279 qq(<input class="method $me" name="${R}method" list="methods" size="$D" type="text" value="$d">);
280  
281 if (my $context = $l->{context}) # Show contexts chosen with a spare field at the end for additional context
282 {pop @$context while @$context and $$context[-1] !~ m(\S)s;
283 push @$context, q();
284 for my $j(keys @$context)
285 {my $J = $j + 1;
286 my $c = $$context[$j];
287 my $e = $c && $l->contextErrors->{$c} ? q(contextError) : q();
288 my $lc = length(pad($c, padLength));
289 push @h, qq(<input class="context $e" name="${R}context_$J" list="contexts" size="$lc" type="text" value="$c">);
290 }
291 }
292 push @h, qq(</div>);
293 }
294  
295 push @h, makeDataList q(actions), sort &pcdRowActions;
296 push @h, makeDataList q(rowTypes), sort &pcdRowTypes;
297 push @h, makeDataList q(methods), sort &pcdUnitaryMethods;
298 push @h, makeDataList q(contexts), sort &pcdDitaTags;
299 push @h, <<'END';
300 <script>
301 function expandInputField(event) {
302 const target = event.target;
303 const value = target.value;
304 target.setAttribute("size", value.length + 4);
305 if (target.classList.contains("action")) {
306 if (value.match(/^a$/i)) {target.value = "after"}
307 else if (value.match(/^b$/i)) {target.value = "before"}
308 else if (value.match(/^c$/i)) {target.value = "copy"}
309 else if (value.match(/^d$/i)) {target.value = "delete"}
310 else if (value.match(/^m$/i)) {target.value = "move"}
311 else if (value.match(/^r$/i)) {target.value = "repeat"}
312 }
313 }
314 </script>
315 END
316 push @h, qq(</table></div><p><input class="editButton" name="submit" value="Edit" type="submit"></form>);
317 join "\n", @h
318 } # representPcdParseTreeAsHtml
319  
320 sub printPcdHtml($) #P Print a PCD using L<html>
321 {my ($string) = @_; # Pcd as a string
322  
323 my $p = parsePcdString($string); # Create a parse tree for the pcd
324 push my @h, qq(<div class="pcds">);
325  
326 for my $l($p->rows->@*) # Show each row
327 {my $n = $l->rowType = sub
328 {return q(comment) if ref($l) =~ m(comment)i;
329 return q(description) if ref($l) =~ m(description)i;
330 return q(method) if ref($l) =~ m(method)i;
331 confess "Unknown row type: ".ref($l);
332 }->();
333  
334 if ($n =~ m(comment)i)
335 {push @h, qq(<div class="pcdComment">).$l->{$n}.qq(</div>);
336 }
337 elsif ($n =~ m(description)i)
338 {push @h, qq(<div class="pcdDescription">).$l->{$n}.qq(</div>);
339 }
340 elsif ($n =~ m(method)i)
341 {push my @s, join '', qq(<div class="pcdMethodLine">),
342 qq(<span class="pcdIndent">&nbsp;&nbsp;&nbsp;&nbsp;</span>),
343 qq(<span class="pcdMethod">).$l->{$n}.qq(</span>);
344 if (my $context = $l->{context}) # Show contexts chosen with a spare field at the end for additional context
345 {for my $context(@$context)
346 {push @s, qq(<span class="pcdContext">$context</span>);
347 }
348 push @h, join '&nbsp;', @s;
349 }
350 push @h, qq(</div>);
351 }
352 }
353 push @h, qq(</div>);
354 join "\n", @h
355 } # printPcdHtml
356  
357 sub parseUrlRepresentationOfPcd($) #E Parse the url representation of a parse tree.
358 {my ($url) = @_; # Url
359  
360 my @l;
361 for my $key(sort keys %$url) # Go vertical
362 {my $value = $$url{$key};
363 $value =~ s(\+) ( )gs; # Remove url encoding
364 if ($key =~ m(\A(\d+)_(.*)\Z)s)
365 {my $row = $1;
366 my $field = $2;
367 if ($key =~ m(\A\d+_context_(\d+)\Z)s)
368 {my $context = $1;
369 $l[$row-1]{context}[$context-1] = $value;
370 }
371 else
372 {$l[$row-1]{$field} = $value;
373 }
374 }
375 }
376  
377 my @p; # Reconstruct parse tree
378 for my $l(@l) # Each row of the parse tree
379 {my @action = $l->{action} ? (action => $l->{action}) : (); # Action specification
380 my $method = $l->{method}; # Method
381  
382 if (my $rowType = $l->{rowType1}) # Comment
383 {if ($rowType =~ m(comment)i)
384 {push @p, newDitaPcdComment (@action, comment=>$method);
385 }
386 elsif ($rowType =~ m(description)i) # Description
387 {push @p, newDitaPcdDescription(@action, description=>$method);
388 }
389 elsif ($rowType =~ m(method)i) # Method
390 {my $context = join ' ', @{$l->{context}//[]}; # Join context string so it can be resplit
391 push @p, newDitaPcdMethod
392 (@action, method=>$method, context=>[split /\s+/, $context]);
393 }
394 else # Unknown row type
395 {confess "Unknown row type $rowType";
396 }
397 }
398 else # Missing row type
399 {confess "No row type";
400 }
401 }
402  
403 newDitaPcdParseTree(rows=>\@p);
404 } # parseUrlRepresentationOfPcd
405  
406 sub representPcdParseTreeAsText($) #P Print a parse tree as text
407 {my ($parseTree) = @_; # Parse tree
408  
409 my @l = @{$parseTree->rows}; # Rows of parse tree
410 my @t;
411 for my $l(@l) # Each row
412 {if (my $rowType = ref($l)) # Type of row
413 {if ($rowType =~ m(comment)i) # Comment
414 {push @t, q(# ).$l->comment;
415 }
416 elsif ($rowType =~ m(description)i) # Description
417 {push @t, q(), $l->{description};
418 }
419 elsif ($rowType =~ m(method)i) # Method
420 {my $context = join ' ', @{$l->{context}//[]}; # Join context string so it can be resplit allowing the user to use a single field to enter several context entries
421 push @t, q( ).join ' ', $l->{method}, @{$l->{context}//[]}
422 }
423 else # Unknown row type
424 {confess "Unknown row type $rowType";
425 }
426 }
427 else # Missing row type
428 {confess "No row type";
429 }
430 }
431  
432 join "\n", @t, '';
433 } # representPcdParseTreeAsText
434  
435 sub compilePcdString($;$) #P Compile the specified L<pcd> directives in the supplied B<$string> optionally associated with B<$file>.
436 {my ($string, $file) = @_; # Input string, optional name of file associated with string
437 my $if = $file // q(); # Nominal file
438  
439 my @l = split m/\n/, $string;
440  
441 my @blocks;
442 for my $i(keys @l) # Each line==row a pcd file
443 {my $l = $l[$i];
444 my $j = $i + 1;
445  
446 next if $l =~ m(\A\s*#|\A\s*\Z); # Comment
447  
448 if ($l =~ m(\A\S)s) # Change description
449 {push @blocks, [[trim($l), $i+1, $if], []];
450 }
451 else # Change command block
452 {if (my ($cmd, @Keys) = split m/\s+/, trim($l)) # Parse command
453 {my @keys;
454  
455 for my $key(@Keys) # Transforms keys into Perl strings
456 {if ($key =~ m(undef)) {push @keys, "undef"} # Undef for anything
457 elsif ($key =~ m/\Aqr(.*)\Z/s) {push @keys, $key} # Words wrapped with qr(.*) are regular expressions
458 elsif ($key =~ m(\|)s) {push @keys, "qr(\\A($key)\\Z)"} # Words separated by | are a regular expression indicating choice of tags
459 else {push @keys, "q($key)"}
460 }
461  
462 if (isSubInPackage(q(Data::Edit::Xml), $cmd)) # Validate command
463 {my $p = join(', ', @keys); # Parameter list
464 my $e = qq(sub {Data::Edit::Xml::$cmd(\$_, $p)}); # Create matching Perl expression for command
465 my $r = eval $e; # Evaluate command
466 die "Error at $if line $j;\n$@\n" if $@; # Report any errors
467 push @blocks, [] unless @blocks; # Vivify blocks
468 push @{$blocks[-1][1]}, [$r, $j, $if]; # Save generated code
469 }
470 else # Report wrong command
471 {die "No such command: $cmd at $if line $j\n";
472 }
473 }
474 else # Request command
475 {die "Please specify a command at $if line $j\n";
476 }
477 }
478 }
479 \@blocks
480 } # compilePcdString
481  
482 sub compilePcdFile($) #E Compile the specified L<pcd> directives B<$file> specifying changes to be made to L<dita> files.
483 {my ($if) = @_; # Input file
484 my $l = readFile($if);
485 compilePcdString($l, $if);
486 }
487  
488 sub compilePcdFiles(@) #E Locate and compile the L<dita> files in the specified folder B<@in>.
489 {my (@in) = @_; # Input folders
490 my @blocks; # Blocks of changes
491 my @i = searchDirectoryTreesForMatchingFiles(@in, q(.pcd)); # Pcd source files
492 for my $f(@i) # Each pcd file
493 {push @blocks, @{compilePcdFile($f)};
494 }
495 \@blocks
496 }
497  
498 sub transformDitaWithPcd($$$) #E Transform the contents of file B<$if> represented as a parse tree B<$x> by applying the specified L<pcd> directives in B<$blocks>.
499 {my ($if, $x, $blocks) = @_; # Input file, parse tree, change blocks
500  
501 my %stats; # Statistics
502  
503 for my $block(@$blocks) # Each block of commands
504 {my ($description, $commands) = @$block;
505  
506 $x->by(sub # Traverse parse tree applying each block to each node
507 {my ($node) = @_;
508  
509 sub # Execute the command block against the current node of the parse tree
510 {my ($d, $di, $df) = @$description;
511 %Data::Edit::Xml::savedNodes = @Data::Edit::Xml::saveLastCutOut = (); # Clear state from DEX expeditiously
512  
513 my $o = $node; # Start each block at the current node
514 for my $command(@$commands) # Each command in the block
515 {my ($c, $ci, $cf) = @$command; # Command
516  
517 local $_ = $o; my $r = &$c; # Transform current node
518  
519 unless(defined $r) # Return on undef
520 {my $ml = $stats{failed} {$df}{$di};
521 my $mlf = $stats{failedFile}{$df}{$di}{$if};
522 $stats{failed} {$df}{$di} = $ci if !$ml or $ci > $ml;
523 $stats{failedFile}{$df}{$di}{$if} = $ci if !$mlf or $ci > $mlf;
524 return;
525 }
526  
527 if (!ref($r)) # Print string result
528 {chomp($r);
529 my $l = " in $if at $cf line $ci";
530 if ($r =~ m(\n)s)
531 {$r =~ s(\n) ($l\n)s;
532 }
533 else
534 {$r ="$r$l";
535 }
536 #lll $r;
537 }
538 else # Continue the block with the new value
539 {$o = $r;
540 }
541 }
542  
543 # lll "$d in $if at $df line $di";
544 $stats{passed}{$df}{$di}++;
545 $stats{passedFile}{$df}{$di}{$if}++;
546 }->();
547 });
548 }
549  
550 \%stats
551 }
552  
553 sub transformDitaWithPcdOptimized($$$) #E Transform the specified parse tree B<$x> by applying the specified L<pcd> directive B<$blocks> without any reporting to speed up execution.
554 {my ($if, $x, $blocks) = @_; # Input file, parse tree, change blocks
555  
556 my %stats; # Statistics
557  
558 for my $block(@$blocks) # Each block of commands
559 {my ($description, $commands) = @$block;
560 my ($d, $di, $df) = @$description;
561  
562 $x->by(sub # Traverse parse tree applying each block to each node
563 {my ($node) = @_;
564  
565 %Data::Edit::Xml::savedNodes = @Data::Edit::Xml::saveLastCutOut = (); # Clear state from DEX expeditiously
566  
567 my $o = $node; # Start each block at the current node
568 for my $command(@$commands) # Each command in the block
569 {my $c = $$command[0]; # Command
570 local $_ = $o; my $r = &$c; # Transform current node
571 return unless defined $r; # Return unless we got a response
572 $o = $r if ref $r; # Move on to next node
573 }
574 $stats{passedFile}{$df}{$di}{$if}++; # Record completion of block
575 });
576 }
577  
578 \%stats # Return statistics
579 }
580  
581 sub pleaseChangeDita(%) #E Transform L[dita] files as specified by the directives in L<pcd> files.
582 {my (%options) = @_; # Execution options
583  
584 checkKeys(\%options, # Check report options
585 {in=><<'END',
586 The input folder containing .dita files to be changed and .pcd files describing
587 the changes.
588 END
589 out=><<'END',
590 The output folder containing transformed copies of the input dita files.
591 END
592 reports=><<'END',
593 The output folder containing reports on the changes made.
594 END
595 optional=><<'END',
596 Do not complain if there are no .pcd files present.
597 END
598 });
599  
600 my $in = $options{in}; # Input folder
601 my $out = $options{out}; # Output folder
602 my $reports = $options{reports}; # Reports folder
603  
604 my $blocks = compilePcdFiles($in); # Blocks of changes
605 return undef if $options{optional} and !@$blocks; # No files to process and optional specified
606 @$blocks or confess "No .pcd files found in $in\n"; # No source files
607  
608 my @dita = searchDirectoryTreesForMatchingFiles($in); # The dita files to be converted
609  
610 for my $if(@dita) # Process each dita file against each change file
611 {next if fe($if) =~ m(\A(directory|pcd)\Z)i; # Skip files that are obviously not xml files
612  
613 my $x = Data::Edit::Xml::new($if);
614  
615 my $stats = transformDitaWithPcd($if, $x, $blocks); # Transform the parse tree with the compiled blocks tracing if required
616 # lll "File: $if\n", dump($stats);
617  
618 my $o = swapFilePrefix($if, $in, $out); # Print the results
619 if ($x->ditaRoot)
620 {owf($o, $x->ditaPrettyPrintWithHeaders);
621 }
622 else
623 {owf($o, -p $x);
624 }
625 }
626 } # pleaseChangeDita
627  
628 sub pleaseChangeDitaString($$%) #E Apply a pcd string to an xml string and return the resulting string
629 {my ($xml, $pcd, %options) = @_; # Xml, pcd options, options
630  
631 my $blocks = compilePcdString($pcd); # Compiled Pcd
632 my $x = Data::Edit::Xml::new($xml); # Parse tree to transform
633  
634 transformDitaWithPcd($options{file}//q(), $x, $blocks); # Transform the parse tree with the compiled pcd blocks
635  
636 $x
637 } # pleaseChangeDitaString
638  
639 sub pcdDitaTags
640 {qw(abstract alt anchorref annotation-xml apiname apply area author b bind body bodydiv brand bvar category cause cerror change-completed change-historylist change-item change-organization change-person change-request-id change-request-reference change-request-system change-revisionid change-started change-summary chdesc chdeschd chhead choice choices choicetable choption choptionhd chrow ci cite closereqs cmd cmdname cn codeblock codeph component conbody conbodydiv concept condition consequence context coords copyrholder copyright critdates csymbol data data-about dd ddhd declare degree delim desc dita ditavalmeta ditavalref div dl dlentry dlhead domainofapplication draft-comment dt dthd dvrKeyscopePrefix dvrKeyscopeSuffix dvrResourcePrefix dvrResourceSuffix entry equation-block equation-figure equation-inline equation-number example exportanchors featnum fig figgroup filepath fn foreign fragment fragref glossAbbreviation glossAcronym glossAlt glossBody glossdef glossentry glossgroup glossProperty glossref glossScopeNote glossShortForm glossSurfaceForm glossSymbol glossSynonym glossterm glossUsage groupchoice groupcomp groupseq hazardstatement hazardsymbol howtoavoid i image imagemap index-base index-see index-see-also index-sort-as indexterm info interval itemgroup keydef keyword keywords kwd lambda li line-through lines link linkinfo linklist linkpool linktext list logbase lowlimit lq maction map mapref markupname math mathml matrix matrixrow menclose menucascade merror messagepanel metadata mfenced mfrac mi mlabeledtr mlongdiv mmultiscripts mn mo momentabout mover mpadded mphantom mroot mrow ms mscarries mscarry msgblock msgnum msgph msgroup msqrt msrow mstack mstyle msub msubsup msup mtable mtd mtext mtr munder munderover navtitle note numcharref object ol oper option otherwise overline p parameterentity parml parmname pd ph piece piecewise platform plentry postreq pre prelreqs prereq prodinfo prodname prognum prolog propdesc propdeschd properties property prophead proptype proptypehd propvalue propvaluehd pt publisher q refbody refbodydiv reference refsyn related-links relcell relcolspec relheader reln relrow reltable remedy repsep reqconds reqpers required-cleanup resourceid responsibleParty result row safety screen searchtitle section sectiondiv semantics sep series set shape shortcut shortdesc simpletable sl sli sort-as source spares sparesli stentry step stepresult steps steps-informal steps-unordered stepsection steptroubleshooting stepxmp sthead strow sub substep substeps sup supeqli supequip supplies supplyli svg-container synblk synnote synph syntaxdiagram systemoutput table task taskbody tasktroubleshooting tbody term text textentity tgroup thead title titlealts tm topic topicgroup topichead topicmeta topicref topicset topicsetref troublebody troubleshooting troubleSolution tt tutorialinfo typeofhazard u uicontrol ul unknown uplimit userinput var varname vector vrmlist wintitle xmlatt xmlelement xmlnsname xmlpi xref)}
641  
642 sub pcdUnitaryMethods{qw(addAttr addFirst addFirstAsText addLabels addLast addLastAsText addNext addNextAsText addPrev addPrevAsText addSingleChild addWrapWith an ancestry ap apn approxLocation at atOrBelow atStringContentMatches atText atTop attrAt attrCount attrValueAt attrsNone bitsNodeTextBlank breakIn breakInBackwards breakInForwards breakOut breakOutChild c cText change changeAttr changeAttrValue changeAttributeValue changeKids changeOrDeleteAttr changeOrDeleteAttrValue changeText changeTextToSpace checkParentage checkParser closestLocation concatenateSiblings containsSingleText contentAfter contentAfterAsTags contentAfterAsTags2 contentAsTags contentAsTags2 contentBefore contentBeforeAsTags contentBeforeAsTags2 context copyAttrsFromParent copyAttrsToParent count countAttrNames countAttrNamesAndValues countAttrNamesOnTagExcluding countAttrValues countLabels countNonEmptyTags countOutputClasses countReport countTagNames countTags countTexts countWords createGuidId cut cutFirst cutIfEmpty cutLast cutNext cutPrev deleteAttr deleteAttrs deleteAttrsInTree deleteContent deleteLabels depth depthProfile ditaAddColSpecToTGroup ditaAddPadEntriesToTGroupRows ditaConvertConceptToReference ditaConvertConceptToSection ditaConvertConceptToTask ditaConvertDlToUl ditaConvertFromHtmlDl ditaConvertOlToSubSteps ditaConvertReferenceToConcept ditaConvertReferenceToTask ditaConvertSectionToConcept ditaConvertSectionToReference ditaConvertSectionToTask ditaConvertSimpleTableToTable ditaConvertSubStepsToSteps ditaConvertTopicToTask ditaConvertUlToSubSteps ditaCouldConvertConceptToTask ditaCutTopicmetaFromAClassificationMap ditaExpandAllConRefs ditaFixTGroupColSpec ditaListToChoices ditaListToSteps ditaListToStepsUnordered ditaListToSubSteps ditaListToTable ditaMaximumNumberOfEntriesInATGroupRow ditaMergeLists ditaMergeListsOnce ditaNumberOfColumnsInRow ditaObviousChanges ditaParagraphToNote ditaPrettyPrintWithHeaders ditaRemoveTGroupTrailingEmptyEntries ditaReplaceAnyConref ditaReplaceAnyConrefIdeallyWithMatchingTag ditaReplaceAnyConrefInContext ditaRoot ditaStepsToChoices ditaStepsToList ditaSyntaxDiagramFromDocBookCmdSynopsis ditaSyntaxDiagramToBasicRepresentation ditaTGroupStatistics ditaTopicHeaders ditaWrapWithPUnderConbody ditaXrefs divideHtmlDocumentIntoSections downWhileFirst downWhileHasSingleChild downWhileLast dupPutNext dupPutNextN dupPutPrev expandIncludes extendSectionToNextSection findByForestNumber findById findByNumber findByNumbers first firstBy firstContextOf firstDown firstIn firstInIndex firstIs firstNot firstOf firstSibling firstText firstTextMatches firstUntil firstUntilText firstWhile firstn fixEntryColSpan fixEntryRowSpan fixTGroup fixTable forestNumberTrees formatOxygenMessage getLabels getNodeAs getSectionHeadingLevel giveEveryIdAGuid go goFish hasContent hasSingleChild hasSingleChildText hasSingleChildToDepth height help howFar howFarAbove howFarBelow howFirst howLast howOnlyChild htmlHeadersToSections htmlTableToDita index indexIds invert invertFirst invertLast isADitaMap isAllBlankText isBlankText isEmpty isFirst isFirstN isFirstText isFirstToDepth isLast isLastN isLastText isLastToDepth isNotFirst isNotLast isOnlyChild isOnlyChildBlankText isOnlyChildN isOnlyChildText isOnlyChildToDepth isText joinWithText jsonString labelsInTree last lastBy lastContextOf lastDown lastIn lastInIndex lastIs lastNot lastOf lastSibling lastText lastTextMatches lastUntil lastUntilText lastWhile lastn lineLocation location matchNodesByRepresentation matchTree matchesFirst matchesLast matchesNext matchesPrev matchesText mergeDuplicateChildWithParent mergeLikeElements mergeLikeNext mergeLikePrev mergeOnlyChildLikeNext mergeOnlyChildLikePrev mergeOnlyChildLikePrevLast moveEndLast moveFirst moveLast moveSelectionAfter moveSelectionBefore moveSelectionFirst moveSelectionLast moveStartFirst next nextIn nextIs nextN nextOn nextText nextTextMatches nextUntil nextWhile nextn not numberNode numberTree numberTreesJustIds over over2 overAllTags overFirstTags overLastTags parentage path pathString position present prettyString prettyStringCDATA prettyStringContent prettyStringContentNumbered prettyStringDitaHeaders prettyStringEnd prettyStringNumbered prev prevIn prevIs prevN prevOn prevText prevTextMatches prevUntil prevWhile prevn printAttributes printAttributesExtendingIdsWithLabels printAttributesHtml printAttributesReplacingIdsWithLabels printNode printNodeAsSingleton printStack propagate putContentAfter putContentBefore putCutOutFirst putCutOutLast putCutOutNext putCutOutPrev putFirstAsComment putFirstAsText putFirstRequiredCleanUp putLastAsComment putLastAsText putLastRequiredCleanUp putNextAsComment putNextAsText putNextFirstCut putNextFirstCut2 putNextRequiredCleanUp putNodeAs putPrevAsComment putPrevAsText putPrevLastCut putPrevLastCut2 putPrevRequiredCleanUp putSiblingsAfterParent putSiblingsBeforeParent putSiblingsFirst putSiblingsLast putTextFirst putTextLast putTextNext putTextPrev putUpNextCut putUpNextCut2 putUpPrevCut putUpPrevCut2 renameAttr renameAttrValue renameAttrXtr reorder replaceContentWithText replaceWithBlank replaceWithRequiredCleanUp replaceWithText reportNode reportNodeAttributes reportNodeContext requiredCleanUp set setAttr setDepthProfile setRepresentationAsTagsAndText setRepresentationAsText setSelectionEnd setSelectionStart splitAfter splitAndWrapFromStart splitAndWrapToEnd splitBefore splitParentAfter splitParentBefore sss string stringAsMd5Sum stringContent stringContentOrText stringNode stringQuoted stringTagsAndText stringText structureAdjacentSectionsByLevel swapFirstSibling swapLastSibling swapNext swapPrev swapTagWithParent tocNumbers top unwrap unwrapContentsKeepingText unwrapOnlyChild unwrapParentOfOnlyChild unwrapParentsWithSingleChild unwrapSingleParentsOfSection up upThru upUntil upUntilFirst upUntilIsOnlyChild upUntilLast upWhile upWhileFirst upWhileIsOnlyChild upWhileLast upn wordStyles wrapContentWith wrapContentWithDup wrapDown wrapFirstN wrapFromFirst wrapFromFirstOrLastIn wrapLastN wrapNext wrapNextN wrapPrev wrapPrevN wrapRuns wrapSiblingsAfter wrapSiblingsBefore wrapToLast wrapToLastOrFirstIn wrapUp wrapWith wrapWithAll wrapWithDup wrapWithN writeCompressedFile zipDown zipDownOnce)}
643  
644 sub pcdRowActions
645 {qw(delete repeat copy cut after before)
646 }
647  
648 sub pcdRowTypes
649 {qw(comment description method)
650 }
651  
652 sub formatHtml($) #P Replace <> by &lt; &gt; to make example html displayable
653 {my ($string) = @_; # String
654 $string =~ s(<) (&lt;)gs;
655 $string =~ s(>) (&gt;)gs;
656 join "\n", q(<pre>), $string, q(</pre>);
657 }
658  
659 sub printPcdExamplesHtml($;$) #P Print the PCD examples found in the module description of Data::Edit::Xml.
660 {my ($mod, $formatter) = @_; # Module description of Data::Edit::Xml, optional sub to format xml
661  
662 my @h; # Html table showing before, pcd, after
663  
664 my %m = $mod->methods->%*; # Module description
665  
666 for my $m(sort keys %m)
667 {if (my $e = $m{$m}{example})
668 {my $i = join "\n", $e->before->@*; # Input Xml
669 my $b = $i =~ m(<(concept|reference|task)) ? $i : qq(<a>$i</a>); # Wrap input xml if no root tag supplied
670 my $c = join "\n", qq(Test:), map{qq( $_)} $e->code->@*; # Pcd
671  
672 my $d = $e->doc; # Doc
673  
674 my $braceable = sub # Demonstrates a braceable string
675 {my $u = $m{$m}{userFlags};
676 $u and $u =~ m(b) # Braceable marker
677 }->();
678  
679 push @h, <<END; # Format PCD
680 <tr id="a$m" onclick="clickTitle(event, '$m')"><td class="bold">$m<td>$d
681  
682 <tr id="b$m" class="hide pcdExample" onclick="clickExample(event)">
683 <td><td><table cellspacing="10" cellpadding="10" border="0">
684 END
685  
686 if ($braceable && $formatter) # Braceable and we have a formatter to interpret it
687 {my $B = formatHtml $b;
688 my $A = formatHtml $formatter->($b); # Format input xml
689  
690 push @h, <<END;
691 <tr><th>Input l[xml]<th><th>Output l[xml]
692 <tr><td>$B<td>Press <b>Save</b><td>$A
693 END
694 }
695 else
696 {my $B = sub # Format input xml
697 {my $x = eval {Data::Edit::Xml::new($b)};
698 if ($@)
699 {return qq(<h2>Error</h2><p>$b <p>$@) if $@;
700 }
701 $x->prettyStringHtml;
702 }->();
703  
704 my $A = sub # Format output xml
705 {my $x = eval {pleaseChangeDitaString($b, $c, file=>$m)};
706 return qq(<h2>Error</h2><p>$c<p>$@) if $@;
707 $x->prettyStringHtml
708 }->();
709  
710 my $C = printPcdHtml($c);
711  
712 push @h, <<END;
713 <tr><th>Input l[xml]<th>L[pcd]<th>Output l[xml]
714 <tr><td>$B<td>$C<td>$A
715 END
716 }
717  
718 push @h, <<END; # Format PCD
719 </table>
720 </tr>
721 END
722 }
723 }
724  
725 join "\n", <<END, # Table of examples
726 <script>
727 function clickTitle(event, method) // Click on title to show or dismiss example
728 {const next = document.getElementById('b'+method); // Example associated with title
729  
730 const examples = document.getElementsByClassName("pcdExample"); // Hide all examples except the current example
731 for(var i = 0; i < examples.length; ++i)
732 {const e = examples[i];
733 if (e != next) e.classList.add("hide");
734 }
735  
736 next.classList.toggle("hide"); // Toggle the current example
737 }
738  
739 function clickExample(event) // Click on example to dismiss it
740 {const examples = document.getElementsByClassName("pcdExample");
741 for(var i = 0; i < examples.length; ++i)
742 {examples[i].classList.add("hide");
743 }
744 }
745 </script>
746  
747 <style>
748 .xmlTag {color: red}
749 .xmlAttr {color: blue}
750 .xmlValue {color: green}
751 .xmlText {color: brown}
752 .xmlEquals, .xmlGt, .xmlLt, .xmlSlashGt, .xmlLtSlash {color: darkBlue; font-weight: bold;}
753  
754 .pcdComment {color: darkOrange}
755 .pcdDescription {color: darkGreen}
756 .pcdMethod {color: darkBlue}
757 .pcdContext {color: darkRed}
758  
759 td
760 {padding: 10px;
761 vertical-align: top;
762 }
763  
764 th
765 {text-align: left;
766 }
767  
768 table.pcdExamples tr:nth-child(even)
769 {background-color: #f0fff0;
770 }
771 table.pcdExamples tr:nth-child(odd)
772 {background-color: #fff0ff;
773 }
774 table.pcdExamples
775 {border-spacing: 10px 10px;
776 }
777 tr.hide
778 {display: none;
779 }
780 </style>
781 <p>Click on a l[dex] method description below to see the associated example.
782  
783  
784 <table class="pcdExamples" cellspacing="10" cellpadding="10">
785 <tr><th>Method<th>Description
786 END
787 @h, <<END;
788 </table>
789  
790 <p>In the method names above <b>next</b> and <b>prev</b> meaning <i>next</i>
791 and <i>previous</i> can always be interchanged as can <b>first</b> and
792 <b>last</b> meaning the <i>first</i> or the <i>last</i> child of a parent to
793 generate new and valid method names from the ones listed.
794 END
795 }
796  
797 #Doff
798  
799 #-------------------------------------------------------------------------------
800 # Export
801 #-------------------------------------------------------------------------------
802  
803 use Exporter qw(import);
804  
805 use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
806  
807 @ISA = qw(Exporter);
808 @EXPORT_OK = qw(
809 compilePcdFile
810 compilePcdFiles
811 editPcdParseTree
812 parsePcdFile
813 parsePcdString
814 parseUrlRepresentationOfPcd
815 pcdDitaTags
816 pcdRowActions
817 pcdRowTypes
818 pcdUnitaryMethods
819 pleaseChangeDita
820 pleaseChangeDitaString
821 printPcdExamplesHtml
822 representPcdParseTreeAsHtml
823 representPcdParseTreeAsText
824 transformDitaWithPcd
825 transformDitaWithPcdOptimized
826 );
827  
828 %EXPORT_TAGS = (all=>[@EXPORT, @EXPORT_OK]);
829  
830 my $documentationSynopsis = <<END;
831  
832 Applying the L<pcdLang> file B<test.pcd>:
833  
834 # Sample pcd file
835 Change d under c under b to D
836 change D d c b
837  
838 Change B to b
839 change b B
840 rn BBBB
841  
842 Merge two adjacent b
843 mergeLikePrev b
844  
845 To a sample L<xml> file B<1.dita>:
846  
847 <a>
848 <b>
849 <c>
850 <d/>
851 </c>
852 </b>
853 <B>
854 <c>
855 <d/>
856 </c>
857 </B>
858 </a>
859  
860 Produces the following messages:
861  
862 Change d under c under b to D at test.pcd line 2
863 BBBB at test.pcd line 8
864 <b>
865 <c>
866 <d/>
867 </c>
868 </b>
869 Change B to b at test.pcd line 6
870 Merge two adjacent b at test.pcd line 10
871  
872 And the following output L<XML> in B<out/1.dita>:
873  
874 <a>
875 <b>
876 <c>
877 <D/>
878 </c>
879 <c>
880 <d/>
881 </c>
882 </b>
883 </a>
884  
885 The L<PCD> commands available are those documented in: L<dex>.
886  
887 Each block of commands is applied to each node of the parse tree produced by
888 L<dex>. If the block completes successfully the description line at the head of
889 the block is printed. Execution of a block is halted if one of the commands in
890 the block returns a false value. Any changes made to the parse tree before a
891 block halts are retained so it is sensible to put as many tests as might be
892 necessary at the start of the block to ensure that all the conditions are met
893 to allow the block to complete successfully or to halt the block before the
894 block starts making changes to the parse tree.
895  
896 END
897  
898 # podDocumentation
899  
900 =pod
901  
902 =encoding utf-8
903  
904 =head1 Name
905  
906 Dita::PCD - Implementation of the Please Change Dita Language.
907  
908 =head1 Synopsis
909  
910 Applying the L<PCD|https://philiprbrenan.github.io/data_edit_xml_edit_commands.html> file B<test.pcd>:
911  
912 # Sample pcd file
913 Change d under c under b to D
914 change D d c b
915  
916 Change B to b
917 change b B
918 rn BBBB
919  
920 Merge two adjacent b
921 mergeLikePrev b
922  
923 To a sample L<Xml|https://en.wikipedia.org/wiki/XML> file B<1.dita>:
924  
925 <a>
926 <b>
927 <c>
928 <d/>
929 </c>
930 </b>
931 <B>
932 <c>
933 <d/>
934 </c>
935 </B>
936 </a>
937  
938 Produces the following messages:
939  
940 Change d under c under b to D at test.pcd line 2
941 BBBB at test.pcd line 8
942 <b>
943 <c>
944 <d/>
945 </c>
946 </b>
947 Change B to b at test.pcd line 6
948 Merge two adjacent b at test.pcd line 10
949  
950 And the following output L<Xml|https://en.wikipedia.org/wiki/XML> in B<out/1.dita>:
951  
952 <a>
953 <b>
954 <c>
955 <D/>
956 </c>
957 <c>
958 <d/>
959 </c>
960 </b>
961 </a>
962  
963 The L<Dita::Pcd|https://metacpan.org/pod/Dita::PCD> commands available are those documented in: L<Data::Edit::Xml|https://metacpan.org/pod/Data::Edit::Xml>.
964  
965 Each block of commands is applied to each node of the parse tree produced by
966 L<Data::Edit::Xml|https://metacpan.org/pod/Data::Edit::Xml>. If the block completes successfully the description line at the head of
967 the block is printed. Execution of a block is halted if one of the commands in
968 the block returns a false value. Any changes made to the parse tree before a
969 block halts are retained so it is sensible to put as many tests as might be
970 necessary at the start of the block to ensure that all the conditions are met
971 to allow the block to complete successfully or to halt the block before the
972 block starts making changes to the parse tree.
973  
974 =head1 Description
975  
976 Implementation of the Please Change Dita Language.
977  
978  
979 Version 20201030.
980  
981  
982 The following sections describe the methods in each functional area of this
983 module. For an alphabetic listing of all methods by name see L<Index|/Index>.
984  
985  
986  
987 =head1 Please Change Dita
988  
989 Edit L<Dita|http://docs.oasis-open.org/dita/dita/v1.3/os/part2-tech-content/dita-v1.3-os-part2-tech-content.html> using directives written in L<Dita::Pcd|https://metacpan.org/pod/Dita::PCD>. An introduction to L<Dita::Pcd|https://metacpan.org/pod/Dita::PCD> can be found at: L<PCD|https://philiprbrenan.github.io/data_edit_xml_edit_commands.html>.
990  
991 =head2 parseUrlRepresentationOfPcd($url)
992  
993 Parse the url representation of a parse tree.
994  
995 Parameter Description
996 1 $url Url
997  
998 B<Example:>
999  
1000  
1001 if (1)
1002 {my $testUrl =
1003 {q(001_action) => q(),
1004 q(001_rowType1) => q(comment),
1005 q(001_rowType2) => q(comment),
1006 q(001_method) => q(Sample+Pcd+file),
1007 q(002_action) => q(),
1008 q(002_rowType1) => q(description),
1009 q(002_rowType2) => q(description),
1010 q(002_method) => q(sf-111+unwrap+ph+under+title),
1011 q(003_action) => q(),
1012 q(003_rowType1) => q(method),
1013 q(003_rowType2) => q(method),
1014 q(003_method) => q(unwrap),
1015 q(003_context_1) => q(ph),
1016 q(003_context_2) => q(title),
1017 q(003_context_3) => q()};
1018  
1019  
1020 my $parseTree = parseUrlRepresentationOfPcd($testUrl); # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
1021  
1022  
1023 ok representPcdParseTreeAsText($parseTree) eq <<END;
1024 # Sample Pcd file
1025  
1026 sf-111 unwrap ph under title
1027 unwrap ph title
1028 END
1029 }
1030  
1031  
1032 This method can be imported via:
1033  
1034 use Dita::PCD qw(parseUrlRepresentationOfPcd)
1035  
1036  
1037 =head2 compilePcdFile($if)
1038  
1039 Compile the specified L<Dita::Pcd|https://metacpan.org/pod/Dita::PCD> directives B<$file> specifying changes to be made to L<Dita|http://docs.oasis-open.org/dita/dita/v1.3/os/part2-tech-content/dita-v1.3-os-part2-tech-content.html> files.
1040  
1041 Parameter Description
1042 1 $if Input file
1043  
1044 B<Example:>
1045  
1046  
1047 my $in = temporaryFolder;
1048 my $out = temporaryFolder;
1049  
1050 my $inXml = <<END;
1051 <a>
1052 <b>
1053 <c>
1054 <d/>
1055 </c>
1056 </b>
1057 <B>
1058 <c>
1059 <d/>
1060 </c>
1061 </B>
1062 </a>
1063 END
1064  
1065 my $outXml = <<END;
1066 <a>
1067 <b>
1068 <c>
1069 <D/>
1070 </c>
1071 <c>
1072 <d/>
1073 </c>
1074 </b>
1075 </a>
1076 END
1077  
1078 writeFile(fpe($in, qw(1 dita)), $inXml);
1079  
1080 my $inFile = writeFile(fpe($in, qw(test pcd)), <<END);
1081 Change d under c under b to D
1082 change D d c b
1083  
1084 Change B to b
1085 change b B
1086  
1087 Merge two adjacent b
1088 mlp b
1089 END
1090  
1091 pleaseChangeDita(in=>$in, out=>$out);
1092  
1093 ok readFile(fpe($out, qw(1 dita))) eq $outXml;
1094  
1095  
1096 my $blocks = compilePcdFile($inFile); # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
1097  
1098  
1099 ok dump(compilePcdFiles($in)) eq dump($blocks);
1100  
1101 for(1..1)
1102 {my $x = Data::Edit::Xml::new($inXml);
1103  
1104 transformDitaWithPcdOptimized(q(), $x, $blocks);
1105  
1106 ok -p $x eq $outXml;
1107 }
1108  
1109 clearFolder($_, 1e2) for $in, $out;
1110  
1111 my $in = temporaryFolder;
1112  
1113 my $f = owf(fpe($in, qw(test pcd)), <<END);
1114 # Sample Pcd file
1115 sf-111 unwrap ph under title
1116 unwrap2 ph2 title
1117 END
1118  
1119 my $p = parsePcdFile($f);
1120 delete $p->{inputFile};
1121  
1122 is_deeply $p, bless({
1123 errors => [],
1124 rows => [
1125 bless({
1126 action => "",
1127 actionError => "",
1128 comment => "Sample Pcd file",
1129 rowType => "comment",
1130 rowTypeError => "",
1131 }, "DitaPcdComment"),
1132 bless({
1133 action => "",
1134 actionError => "",
1135 description => "sf-111 unwrap ph under title",
1136 rowType => "description",
1137 rowTypeError => "",
1138 }, "DitaPcdDescription"),
1139 bless({
1140 action => "",
1141 actionError => "",
1142 context => ["ph2", "title"],
1143 contextErrors => {},
1144 method => "unwrap2",
1145 methodError => "",
1146 rowType => "method",
1147 rowTypeError => "",
1148 }, "DitaPcdMethod"),
1149 ],
1150 }, "DitaPCDParseTree");
1151  
1152  
1153 This method can be imported via:
1154  
1155 use Dita::PCD qw(compilePcdFile)
1156  
1157  
1158 =head2 compilePcdFiles(@in)
1159  
1160 Locate and compile the L<Dita|http://docs.oasis-open.org/dita/dita/v1.3/os/part2-tech-content/dita-v1.3-os-part2-tech-content.html> files in the specified folder B<@in>.
1161  
1162 Parameter Description
1163 1 @in Input folders
1164  
1165 B<Example:>
1166  
1167  
1168 my $in = temporaryFolder;
1169 my $out = temporaryFolder;
1170  
1171 my $inXml = <<END;
1172 <a>
1173 <b>
1174 <c>
1175 <d/>
1176 </c>
1177 </b>
1178 <B>
1179 <c>
1180 <d/>
1181 </c>
1182 </B>
1183 </a>
1184 END
1185  
1186 my $outXml = <<END;
1187 <a>
1188 <b>
1189 <c>
1190 <D/>
1191 </c>
1192 <c>
1193 <d/>
1194 </c>
1195 </b>
1196 </a>
1197 END
1198  
1199 writeFile(fpe($in, qw(1 dita)), $inXml);
1200  
1201 my $inFile = writeFile(fpe($in, qw(test pcd)), <<END);
1202 Change d under c under b to D
1203 change D d c b
1204  
1205 Change B to b
1206 change b B
1207  
1208 Merge two adjacent b
1209 mlp b
1210 END
1211  
1212 pleaseChangeDita(in=>$in, out=>$out);
1213  
1214 ok readFile(fpe($out, qw(1 dita))) eq $outXml;
1215  
1216 my $blocks = compilePcdFile($inFile);
1217  
1218  
1219 ok dump(compilePcdFiles($in)) eq dump($blocks); # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
1220  
1221  
1222 for(1..1)
1223 {my $x = Data::Edit::Xml::new($inXml);
1224  
1225 transformDitaWithPcdOptimized(q(), $x, $blocks);
1226  
1227 ok -p $x eq $outXml;
1228 }
1229  
1230 clearFolder($_, 1e2) for $in, $out;
1231  
1232 my $in = temporaryFolder;
1233  
1234 my $f = owf(fpe($in, qw(test pcd)), <<END);
1235 # Sample Pcd file
1236 sf-111 unwrap ph under title
1237 unwrap2 ph2 title
1238 END
1239  
1240 my $p = parsePcdFile($f);
1241 delete $p->{inputFile};
1242  
1243 is_deeply $p, bless({
1244 errors => [],
1245 rows => [
1246 bless({
1247 action => "",
1248 actionError => "",
1249 comment => "Sample Pcd file",
1250 rowType => "comment",
1251 rowTypeError => "",
1252 }, "DitaPcdComment"),
1253 bless({
1254 action => "",
1255 actionError => "",
1256 description => "sf-111 unwrap ph under title",
1257 rowType => "description",
1258 rowTypeError => "",
1259 }, "DitaPcdDescription"),
1260 bless({
1261 action => "",
1262 actionError => "",
1263 context => ["ph2", "title"],
1264 contextErrors => {},
1265 method => "unwrap2",
1266 methodError => "",
1267 rowType => "method",
1268 rowTypeError => "",
1269 }, "DitaPcdMethod"),
1270 ],
1271 }, "DitaPCDParseTree");
1272  
1273  
1274 This method can be imported via:
1275  
1276 use Dita::PCD qw(compilePcdFiles)
1277  
1278  
1279 =head2 transformDitaWithPcd($if, $x, $blocks)
1280  
1281 Transform the contents of file B<$if> represented as a parse tree B<$x> by applying the specified L<Dita::Pcd|https://metacpan.org/pod/Dita::PCD> directives in B<$blocks>.
1282  
1283 Parameter Description
1284 1 $if Input file
1285 2 $x Parse tree
1286 3 $blocks Change blocks
1287  
1288 B<Example:>
1289  
1290  
1291 my $in = temporaryFolder;
1292 my $out = temporaryFolder;
1293  
1294 my $inXml = <<END;
1295 <a>
1296 <b>
1297 <c>
1298 <d/>
1299 </c>
1300 </b>
1301 <B>
1302 <c>
1303 <d/>
1304 </c>
1305 </B>
1306 </a>
1307 END
1308  
1309 my $outXml = <<END;
1310 <a>
1311 <b>
1312 <c>
1313 <D/>
1314 </c>
1315 <c>
1316 <d/>
1317 </c>
1318 </b>
1319 </a>
1320 END
1321  
1322 writeFile(fpe($in, qw(1 dita)), $inXml);
1323  
1324 my $inFile = writeFile(fpe($in, qw(test pcd)), <<END);
1325 Change d under c under b to D
1326 change D d c b
1327  
1328 Change B to b
1329 change b B
1330  
1331 Merge two adjacent b
1332 mlp b
1333 END
1334  
1335 pleaseChangeDita(in=>$in, out=>$out);
1336  
1337 ok readFile(fpe($out, qw(1 dita))) eq $outXml;
1338  
1339 my $blocks = compilePcdFile($inFile);
1340  
1341 ok dump(compilePcdFiles($in)) eq dump($blocks);
1342  
1343 for(1..1)
1344 {my $x = Data::Edit::Xml::new($inXml);
1345  
1346 transformDitaWithPcdOptimized(q(), $x, $blocks);
1347  
1348 ok -p $x eq $outXml;
1349 }
1350  
1351 clearFolder($_, 1e2) for $in, $out;
1352  
1353 my $in = temporaryFolder;
1354  
1355 my $f = owf(fpe($in, qw(test pcd)), <<END);
1356 # Sample Pcd file
1357 sf-111 unwrap ph under title
1358 unwrap2 ph2 title
1359 END
1360  
1361 my $p = parsePcdFile($f);
1362 delete $p->{inputFile};
1363  
1364 is_deeply $p, bless({
1365 errors => [],
1366 rows => [
1367 bless({
1368 action => "",
1369 actionError => "",
1370 comment => "Sample Pcd file",
1371 rowType => "comment",
1372 rowTypeError => "",
1373 }, "DitaPcdComment"),
1374 bless({
1375 action => "",
1376 actionError => "",
1377 description => "sf-111 unwrap ph under title",
1378 rowType => "description",
1379 rowTypeError => "",
1380 }, "DitaPcdDescription"),
1381 bless({
1382 action => "",
1383 actionError => "",
1384 context => ["ph2", "title"],
1385 contextErrors => {},
1386 method => "unwrap2",
1387 methodError => "",
1388 rowType => "method",
1389 rowTypeError => "",
1390 }, "DitaPcdMethod"),
1391 ],
1392 }, "DitaPCDParseTree");
1393  
1394  
1395 This method can be imported via:
1396  
1397 use Dita::PCD qw(transformDitaWithPcd)
1398  
1399  
1400 =head2 transformDitaWithPcdOptimized($if, $x, $blocks)
1401  
1402 Transform the specified parse tree B<$x> by applying the specified L<Dita::Pcd|https://metacpan.org/pod/Dita::PCD> directive B<$blocks> without any reporting to speed up execution.
1403  
1404 Parameter Description
1405 1 $if Input file
1406 2 $x Parse tree
1407 3 $blocks Change blocks
1408  
1409 B<Example:>
1410  
1411  
1412 my $in = temporaryFolder;
1413 my $out = temporaryFolder;
1414  
1415 my $inXml = <<END;
1416 <a>
1417 <b>
1418 <c>
1419 <d/>
1420 </c>
1421 </b>
1422 <B>
1423 <c>
1424 <d/>
1425 </c>
1426 </B>
1427 </a>
1428 END
1429  
1430 my $outXml = <<END;
1431 <a>
1432 <b>
1433 <c>
1434 <D/>
1435 </c>
1436 <c>
1437 <d/>
1438 </c>
1439 </b>
1440 </a>
1441 END
1442  
1443 writeFile(fpe($in, qw(1 dita)), $inXml);
1444  
1445 my $inFile = writeFile(fpe($in, qw(test pcd)), <<END);
1446 Change d under c under b to D
1447 change D d c b
1448  
1449 Change B to b
1450 change b B
1451  
1452 Merge two adjacent b
1453 mlp b
1454 END
1455  
1456 pleaseChangeDita(in=>$in, out=>$out);
1457  
1458 ok readFile(fpe($out, qw(1 dita))) eq $outXml;
1459  
1460 my $blocks = compilePcdFile($inFile);
1461  
1462 ok dump(compilePcdFiles($in)) eq dump($blocks);
1463  
1464 for(1..1)
1465 {my $x = Data::Edit::Xml::new($inXml);
1466  
1467  
1468 transformDitaWithPcdOptimized(q(), $x, $blocks); # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
1469  
1470  
1471 ok -p $x eq $outXml;
1472 }
1473  
1474 clearFolder($_, 1e2) for $in, $out;
1475  
1476  
1477 This method can be imported via:
1478  
1479 use Dita::PCD qw(transformDitaWithPcdOptimized)
1480  
1481  
1482 =head2 pleaseChangeDita(%options)
1483  
1484 Transform L[dita] files as specified by the directives in L<Dita::Pcd|https://metacpan.org/pod/Dita::PCD> files.
1485  
1486 Parameter Description
1487 1 %options Execution options
1488  
1489 B<Example:>
1490  
1491  
1492 my $in = temporaryFolder;
1493 my $out = temporaryFolder;
1494  
1495 my $inXml = <<END;
1496 <a>
1497 <b>
1498 <c>
1499 <d/>
1500 </c>
1501 </b>
1502 <B>
1503 <c>
1504 <d/>
1505 </c>
1506 </B>
1507 </a>
1508 END
1509  
1510 my $outXml = <<END;
1511 <a>
1512 <b>
1513 <c>
1514 <D/>
1515 </c>
1516 <c>
1517 <d/>
1518 </c>
1519 </b>
1520 </a>
1521 END
1522  
1523 writeFile(fpe($in, qw(1 dita)), $inXml);
1524  
1525 my $inFile = writeFile(fpe($in, qw(test pcd)), <<END);
1526 Change d under c under b to D
1527 change D d c b
1528  
1529 Change B to b
1530 change b B
1531  
1532 Merge two adjacent b
1533 mlp b
1534 END
1535  
1536  
1537 pleaseChangeDita(in=>$in, out=>$out); # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
1538  
1539  
1540 ok readFile(fpe($out, qw(1 dita))) eq $outXml;
1541  
1542 my $blocks = compilePcdFile($inFile);
1543  
1544 ok dump(compilePcdFiles($in)) eq dump($blocks);
1545  
1546 for(1..1)
1547 {my $x = Data::Edit::Xml::new($inXml);
1548  
1549 transformDitaWithPcdOptimized(q(), $x, $blocks);
1550  
1551 ok -p $x eq $outXml;
1552 }
1553  
1554 clearFolder($_, 1e2) for $in, $out;
1555  
1556 my $in = temporaryFolder;
1557  
1558 my $f = owf(fpe($in, qw(test pcd)), <<END);
1559 # Sample Pcd file
1560 sf-111 unwrap ph under title
1561 unwrap2 ph2 title
1562 END
1563  
1564 my $p = parsePcdFile($f);
1565 delete $p->{inputFile};
1566  
1567 is_deeply $p, bless({
1568 errors => [],
1569 rows => [
1570 bless({
1571 action => "",
1572 actionError => "",
1573 comment => "Sample Pcd file",
1574 rowType => "comment",
1575 rowTypeError => "",
1576 }, "DitaPcdComment"),
1577 bless({
1578 action => "",
1579 actionError => "",
1580 description => "sf-111 unwrap ph under title",
1581 rowType => "description",
1582 rowTypeError => "",
1583 }, "DitaPcdDescription"),
1584 bless({
1585 action => "",
1586 actionError => "",
1587 context => ["ph2", "title"],
1588 contextErrors => {},
1589 method => "unwrap2",
1590 methodError => "",
1591 rowType => "method",
1592 rowTypeError => "",
1593 }, "DitaPcdMethod"),
1594 ],
1595 }, "DitaPCDParseTree");
1596  
1597  
1598 This method can be imported via:
1599  
1600 use Dita::PCD qw(pleaseChangeDita)
1601  
1602  
1603 =head2 pleaseChangeDitaString($xml, $pcd, %options)
1604  
1605 Apply a pcd string to an xml string and return the resulting string
1606  
1607 Parameter Description
1608 1 $xml Xml
1609 2 $pcd Pcd options
1610 3 %options Options
1611  
1612 B<Example:>
1613  
1614  
1615  
1616 ok pleaseChangeDitaString(q(<a><b>C</b></a>), qq(Unwrap
1617 unwrap b))->string eq qq(<a>C</a>); # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
1618  
1619  
1620  
1621 This method can be imported via:
1622  
1623 use Dita::PCD qw(pleaseChangeDitaString)
1624  
1625  
1626  
1627 =head2 DitaPcdComment Definition
1628  
1629  
1630 Description of a comment
1631  
1632  
1633  
1634  
1635 =head3 Output fields
1636  
1637  
1638 =head4 comment
1639  
1640 Comment text
1641  
1642  
1643  
1644 =head2 DitaPcdDescription Definition
1645  
1646  
1647 Description
1648  
1649  
1650  
1651  
1652 =head3 Output fields
1653  
1654  
1655 =head4 description
1656  
1657 Description text
1658  
1659  
1660  
1661 =head1 Private Methods
1662  
1663 =head2 ditaPcdBase($rowType)
1664  
1665 Base of various objects used by the editor
1666  
1667 Parameter Description
1668 1 $rowType Row type
1669  
1670 =head2 newDitaPcdComment(%options)
1671  
1672 Create a new comment
1673  
1674 Parameter Description
1675 1 %options Attributes
1676  
1677 =head2 newDitaPcdDescription(%options)
1678  
1679 Create a new description
1680  
1681 Parameter Description
1682 1 %options Attributes
1683  
1684 =head2 newDitaPcdMethod(%options)
1685  
1686 Create a new Method
1687  
1688 Parameter Description
1689 1 %options Attributes
1690  
1691 =head2 newDitaPcdParseTree(%options)
1692  
1693 Create a new Parse Tree
1694  
1695 Parameter Description
1696 1 %options Attributes
1697  
1698 =head2 parsePcdString($string)
1699  
1700 Parse the specified L<Dita::Pcd|https://metacpan.org/pod/Dita::PCD> directives B<$string> specifying changes to be made to L<Dita|http://docs.oasis-open.org/dita/dita/v1.3/os/part2-tech-content/dita-v1.3-os-part2-tech-content.html> files.
1701  
1702 Parameter Description
1703 1 $string String of PCD directives
1704  
1705 =head2 parsePcdFile($if)
1706  
1707 Parse the specified L<Dita::Pcd|https://metacpan.org/pod/Dita::PCD> directives B<$file> specifying changes to be made to L<Dita|http://docs.oasis-open.org/dita/dita/v1.3/os/part2-tech-content/dita-v1.3-os-part2-tech-content.html> files.
1708  
1709 Parameter Description
1710 1 $if Input file
1711  
1712 =head2 editPcdParseTree($parseTree)
1713  
1714 Validate a B<$parseTree>
1715  
1716 Parameter Description
1717 1 $parseTree Parse tree
1718  
1719 =head2 makeDataList($name, @values)
1720  
1721 Create a data list
1722  
1723 Parameter Description
1724 1 $name Name
1725 2 @values Values
1726  
1727 =head2 representPcdParseTreeAsHtml($parseTree)
1728  
1729 Parse the specified L<Dita::Pcd|https://metacpan.org/pod/Dita::PCD> directives B<$file> specifying changes to be made to L<Dita|http://docs.oasis-open.org/dita/dita/v1.3/os/part2-tech-content/dita-v1.3-os-part2-tech-content.html> files.
1730  
1731 Parameter Description
1732 1 $parseTree Parse tree
1733  
1734 =head2 printPcdHtml($string)
1735  
1736 Print a PCD using L<HTML|https://en.wikipedia.org/wiki/HTML>
1737  
1738 Parameter Description
1739 1 $string Pcd as a string
1740  
1741 =head2 representPcdParseTreeAsText($parseTree)
1742  
1743 Print a parse tree as text
1744  
1745 Parameter Description
1746 1 $parseTree Parse tree
1747  
1748 =head2 compilePcdString($string, $file)
1749  
1750 Compile the specified L<Dita::Pcd|https://metacpan.org/pod/Dita::PCD> directives in the supplied B<$string> optionally associated with B<$file>.
1751  
1752 Parameter Description
1753 1 $string Input string
1754 2 $file Optional name of file associated with string
1755  
1756 =head2 formatHtml($string)
1757  
1758 Replace <> by &lt; &gt; to make example html displayable
1759  
1760 Parameter Description
1761 1 $string String
1762  
1763 =head2 printPcdExamplesHtml($mod, $formatter)
1764  
1765 Print the PCD examples found in the module description of Data::Edit::Xml.
1766  
1767 Parameter Description
1768 1 $mod Module description of Data::Edit::Xml
1769 2 $formatter Optional sub to format xml
1770  
1771  
1772 =head1 Index
1773  
1774  
1775 1 L<compilePcdFile|/compilePcdFile> - Compile the specified L<Dita::Pcd|https://metacpan.org/pod/Dita::PCD> directives B<$file> specifying changes to be made to L<Dita|http://docs.oasis-open.org/dita/dita/v1.3/os/part2-tech-content/dita-v1.3-os-part2-tech-content.html> files.
1776  
1777 2 L<compilePcdFiles|/compilePcdFiles> - Locate and compile the L<Dita|http://docs.oasis-open.org/dita/dita/v1.3/os/part2-tech-content/dita-v1.3-os-part2-tech-content.html> files in the specified folder B<@in>.
1778  
1779 3 L<compilePcdString|/compilePcdString> - Compile the specified L<Dita::Pcd|https://metacpan.org/pod/Dita::PCD> directives in the supplied B<$string> optionally associated with B<$file>.
1780  
1781 4 L<ditaPcdBase|/ditaPcdBase> - Base of various objects used by the editor
1782  
1783 5 L<editPcdParseTree|/editPcdParseTree> - Validate a B<$parseTree>
1784  
1785 6 L<formatHtml|/formatHtml> - Replace <> by &lt; &gt; to make example html displayable
1786  
1787 7 L<makeDataList|/makeDataList> - Create a data list
1788  
1789 8 L<newDitaPcdComment|/newDitaPcdComment> - Create a new comment
1790  
1791 9 L<newDitaPcdDescription|/newDitaPcdDescription> - Create a new description
1792  
1793 10 L<newDitaPcdMethod|/newDitaPcdMethod> - Create a new Method
1794  
1795 11 L<newDitaPcdParseTree|/newDitaPcdParseTree> - Create a new Parse Tree
1796  
1797 12 L<parsePcdFile|/parsePcdFile> - Parse the specified L<Dita::Pcd|https://metacpan.org/pod/Dita::PCD> directives B<$file> specifying changes to be made to L<Dita|http://docs.oasis-open.org/dita/dita/v1.3/os/part2-tech-content/dita-v1.3-os-part2-tech-content.html> files.
1798  
1799 13 L<parsePcdString|/parsePcdString> - Parse the specified L<Dita::Pcd|https://metacpan.org/pod/Dita::PCD> directives B<$string> specifying changes to be made to L<Dita|http://docs.oasis-open.org/dita/dita/v1.3/os/part2-tech-content/dita-v1.3-os-part2-tech-content.html> files.
1800  
1801 14 L<parseUrlRepresentationOfPcd|/parseUrlRepresentationOfPcd> - Parse the url representation of a parse tree.
1802  
1803 15 L<pleaseChangeDita|/pleaseChangeDita> - Transform L[dita] files as specified by the directives in L<Dita::Pcd|https://metacpan.org/pod/Dita::PCD> files.
1804  
1805 16 L<pleaseChangeDitaString|/pleaseChangeDitaString> - Apply a pcd string to an xml string and return the resulting string
1806  
1807 17 L<printPcdExamplesHtml|/printPcdExamplesHtml> - Print the PCD examples found in the module description of Data::Edit::Xml.
1808  
1809 18 L<printPcdHtml|/printPcdHtml> - Print a PCD using L<HTML|https://en.wikipedia.org/wiki/HTML>
1810  
1811 19 L<representPcdParseTreeAsHtml|/representPcdParseTreeAsHtml> - Parse the specified L<Dita::Pcd|https://metacpan.org/pod/Dita::PCD> directives B<$file> specifying changes to be made to L<Dita|http://docs.oasis-open.org/dita/dita/v1.3/os/part2-tech-content/dita-v1.3-os-part2-tech-content.html> files.
1812  
1813 20 L<representPcdParseTreeAsText|/representPcdParseTreeAsText> - Print a parse tree as text
1814  
1815 21 L<transformDitaWithPcd|/transformDitaWithPcd> - Transform the contents of file B<$if> represented as a parse tree B<$x> by applying the specified L<Dita::Pcd|https://metacpan.org/pod/Dita::PCD> directives in B<$blocks>.
1816  
1817 22 L<transformDitaWithPcdOptimized|/transformDitaWithPcdOptimized> - Transform the specified parse tree B<$x> by applying the specified L<Dita::Pcd|https://metacpan.org/pod/Dita::PCD> directive B<$blocks> without any reporting to speed up execution.
1818  
1819  
1820  
1821 =head1 Exports
1822  
1823 All of the following methods can be imported via:
1824  
1825 use Dita::PCD qw(:all);
1826  
1827 Or individually via:
1828  
1829 use Dita::PCD qw(<method>);
1830  
1831  
1832  
1833 1 L<compilePcdFile|/compilePcdFile>
1834  
1835 2 L<compilePcdFiles|/compilePcdFiles>
1836  
1837 3 L<parseUrlRepresentationOfPcd|/parseUrlRepresentationOfPcd>
1838  
1839 4 L<pleaseChangeDita|/pleaseChangeDita>
1840  
1841 5 L<pleaseChangeDitaString|/pleaseChangeDitaString>
1842  
1843 6 L<transformDitaWithPcd|/transformDitaWithPcd>
1844  
1845 7 L<transformDitaWithPcdOptimized|/transformDitaWithPcdOptimized>
1846  
1847 =head1 Installation
1848  
1849 This module is written in 100% Pure Perl and, thus, it is easy to read,
1850 comprehend, use, modify and install via B<cpan>:
1851  
1852 sudo cpan install Dita::PCD
1853  
1854 =head1 Author
1855  
1856 L<philiprbrenan@gmail.com|mailto:philiprbrenan@gmail.com>
1857  
1858 L<http://www.appaapps.com|http://www.appaapps.com>
1859  
1860 =head1 Copyright
1861  
1862 Copyright (c) 2016-2019 Philip R Brenan.
1863  
1864 This module is free software. It may be used, redistributed and/or modified
1865 under the same terms as Perl itself.
1866  
1867 =cut
1868  
1869  
1870  
1871 # Tests and documentation
1872  
1873 sub test
1874 {my $p = __PACKAGE__;
1875 binmode($_, ":utf8") for *STDOUT, *STDERR;
1876 return if eval "eof(${p}::DATA)";
1877 my $s = eval "join('', <${p}::DATA>)";
1878 $@ and die $@;
1879 eval $s;
1880 $@ and die $@;
1881 1
1882 }
1883  
1884 test unless caller;
1885  
1886 1;
1887 # podDocumentation
1888 __DATA__
↑ Summary