File Coverage

blib/lib/Data/Edit/Xml/SDL.pm
Criterion Covered Total %
statement 111 112 99.1
branch 14 22 63.6
condition 1 2 50.0
subroutine 25 25 100.0
pod 11 17 64.7
total 162 178 91.0


line stmt bran cond sub pod time code
1             #!/usr/bin/perl
2             #-------------------------------------------------------------------------------
3             # Create SDL file map from a set of linted xml files
4             # Philip R Brenan at gmail dot com, Appa Apps Ltd, 2016
5             #-------------------------------------------------------------------------------
6             # podDocumentation
7              
8             package Data::Edit::Xml::SDL;
9             require v5.16.0;
10 1     1   472 use warnings FATAL => qw(all);
  1         6  
  1         30  
11 1     1   5 use strict;
  1         1  
  1         46  
12 1     1   8 use Carp;
  1         2  
  1         78  
13 1     1   656 use Data::Edit::Xml::Lint;
  1         83658  
  1         41  
14 1     1   10 use Data::Table::Text qw(:all);
  1         2  
  1         1596  
15             our $VERSION = 20180630;
16              
17             #1 Constructor # Construct a new SDL file map creator
18              
19             sub new # Create a new SDL file map creator - call this method statically as in Data::Edit::Xml::Lint::new()
20 1     1 1 19 {bless {sdlVersion=>'12.0.0.0', language=>(qq(en-US))} # Defaults that can be easily overridden
21             }
22              
23             #2 Attributes # Attributes describing a lint
24              
25             genLValueScalarMethods(qw(filePathFolder)); # Prefix this folder (if supplied) to the filepath
26             genLValueScalarMethods(qw(fileType)); # The fileType of the file to be processed
27             genLValueScalarMethods(qw(folderHasMixedContent)); # folderHasMixedContent field
28             genLValueScalarMethods(qw(ishType)); # IshType field
29             genLValueScalarMethods(qw(imagePath)); # Image path relative to sourcebasepath
30             genLValueScalarMethods(qw(language)); # The language of the content, defaults to: 'en-US'
31             genLValueScalarMethods(qw(lint)); # The lint of the file to be processed
32             genLValueScalarMethods(qw(sdlVersion)); # Version of SDL we are using, defaults to: '12.0.0.0'
33             genLValueScalarMethods(qw(section)); # Sub folder for file on SDL: maps, topics
34             genLValueScalarMethods(qw(sourcebasepath)); # Path to source to be uploaded
35             genLValueScalarMethods(qw(targetFolder)); # The SDL target folder to be used
36             genLValueScalarMethods(qw(version)); # Version of the input content
37              
38             #1 SDL File Map # Generate an SDL file map
39              
40             sub xmlLineOne #P Line one of all xml files
41 1     1 1 14 {''."\n"
42             }
43              
44             sub getFileMap #P File map tag
45 1     1 1 11 {my ($sdl) = @_; # Sdl file map creator
46 1         120 my $s = $sdl->sourcebasepath;
47 1         39 my $v = $sdl->sdlVersion;
48             <
49             ;
50             END
51 1         17 }
52              
53             sub getFile($$) #P File tag
54 3     3 1 11 {my ($sdl, $images) = @_; # Sdl file map creator, processing an image file or not
55 3         47 my $targetFolder = $sdl->targetFolder;
56 3         54 my $ishType = $sdl->ishType;
57 3         55 my $section = $sdl->section;
58 3         49 my $imagePath = $sdl->imagePath;
59 3         56 my $lint = $sdl->lint;
60 3         58 my $project = $lint->project;
61 3         61 my $guid = $lint->guid;
62 3         57 my $file = $lint->file;
63 3         56 my $mixed = ucfirst $sdl->folderHasMixedContent;
64 3 50       26 $mixed =~ m/\A(True|False)\Z/s or
65             confess "FolderhasMixedContent = (True|False) not $mixed";
66              
67 3         10 my $filePrefix = ''; # File name prefix if any
68 3 100       10 if ($images) # The image file prefix if we are processing an image
69 1 50       3 {defined($imagePath) or
70             confess "Use SDL->imagePath() to supply a path for images";
71 1         6 $filePrefix = filePathDir($imagePath); # The image file prefix if we are processing an image
72 1         72 $lint->file =~ s/\.xml\Z//gs; # Remove trailing xml extension on image files
73             }
74              
75 3         63 my (undef, $fileName, $fileExt) = parseFileName($lint->file); # Parse file name
76 3 50       109 $fileExt or confess "No file extension for ".$lint->file;
77 3         16 my $relFile = filePathExt($filePrefix, $fileName, $fileExt);
78             <
79            
80             END
81 3         138 }
82              
83             sub getIshObject #P IshObject tag
84 3     3 1 9 {my ($sdl) = @_; # Sdl
85 3         51 my $ishType = $sdl->ishType;
86 3         52 my $lint = $sdl->lint;
87 3         48 my $guid = $lint->guid;
88             <
89            
90             END
91 3         27 }
92              
93             sub getFTitle #P FTITLE tag
94 3     3 1 6 {my ($sdl) = @_; # Sdl
95 3         41 my $lint = $sdl->lint; # Lint
96 3         62 my $Title = $lint->title; # Title
97             # warn "No title in\n".dump($lint)."\n" unless $Title;
98 3   50     24 my $title = $Title || 'REQUIRED-CLEANUP-TITLE';
99             <
100             $title'
101             END
102 3         22 }
103              
104             sub getVersion #P Version tag
105 3     3 1 8 {my ($sdl) = @_; # Sdl
106 3         82 my $v = $sdl->version;
107             <
108             $v
109             END
110 3         24 }
111              
112             sub getDocLanguage #P DOC-LANGUAGE tag
113 3     3 1 6 {my ($sdl) = @_; # Sdl
114 3         45 my $l = $sdl->language;
115             <
116             $l
117             END
118 3         28 }
119              
120             sub getAuthor #P Author tag
121 3     3 1 6 {my ($sdl) = @_; # Sdl
122 3         44 my $lint = $sdl->lint;
123 3         58 my $a = $lint->author;
124             <
125             $a
126             END
127 3         33 }
128              
129             sub getResolution #P Resolution
130 1     1 1 3 {my ($sdl) = @_; # Sdl
131             <
132             High
133             END
134 1         9 }
135              
136             sub createSDLFileMap($@) # Generate an SDL file map for a selected set of files
137 1     1 1 5 {my ($sdl, @foldersAndExtensions) = @_; # Sdl, Directory tree search specification
138              
139 1         4 my @files = searchDirectoryTreesForMatchingFiles(@foldersAndExtensions); # Find matching files
140              
141 1         4509 my @map = (xmlLineOne, $sdl->getFileMap); # The generated map
142              
143 1         7 for my $file(@files) # Each file contributing to the map
144 3         24 {my $lint = Data::Edit::Xml::Lint::read($file); # Linter for the file
145 3         2927 $sdl->lint = $lint;
146              
147 3         101 my $ditaType = $lint->ditaType;
148 3 50       27 $ditaType or confess "DitaType required for file:\n$file";
149              
150 3 100       37 if ($ditaType =~ m/bookmap/i)
    100          
    50          
151 1         25 {$sdl->ishType = (qq(ISHMasterDoc));
152 1         30 $sdl->section = (qq(maps));
153 1         33 $sdl->folderHasMixedContent = (qq(true));
154 1         18 push @map,
155             $sdl->getFile,
156             $sdl->getIshObject, <
157            
158             END
159             $sdl->getFTitle,
160             $sdl->getVersion,
161             $sdl->getDocLanguage,
162             $sdl->getAuthor,
163             <
164            
165            
166            
167             END
168             }
169              
170             elsif ($ditaType =~ m/concept|reference|task|troubleShooting/i)
171 1         19 {$sdl->ishType = (qq(ISHModule));
172 1         18 $sdl->section = (qq(topics));
173 1         18 $sdl->folderHasMixedContent = (qq(true));
174 1         7 push @map,
175             $sdl->getFile,
176             $sdl->getIshObject, <
177            
178             END
179             $sdl->getFTitle,
180             $sdl->getVersion,
181             $sdl->getDocLanguage,
182             $sdl->getAuthor,
183             <
184            
185            
186            
187             END
188             }
189              
190             elsif ($ditaType =~ m/image/i)
191 1         15 {$sdl->ishType = qq(ISHIllustration);
192 1         28 $sdl->section = qq(images);
193 1         19 $sdl->imagePath = qq(images);
194 1         18 $sdl->folderHasMixedContent = qq(false);
195 1         6 push @map,
196             $sdl->getFile(1),
197             $sdl->getIshObject, <
198            
199             END
200             $sdl->getFTitle,
201             $sdl->getVersion,
202             $sdl->getDocLanguage,
203             $sdl->getResolution,
204             $sdl->getAuthor,
205             <
206            
207            
208            
209             END
210             }
211 0         0 else {confess "Unrecognized ditaType $ditaType"}
212             }
213 1         16 my $T = dateTimeStamp;
214 1         75 push @map, <
215            
216            
217             END
218 1         46 join "", @map;
219             } # createSDLFileMap
220              
221             # podDocumentation
222              
223             =pod
224              
225             =encoding utf-8
226              
227             =head1 Name
228              
229             Data::Edit::Xml::SDL - Create SDL file map from a set of linted xml files
230             produced by L
231              
232             =head1 Synopsis
233              
234             Create an SDL file map from a set of linted xml files produced by
235             L
236              
237             my $s = Data::Edit::Xml::SDL::new();
238             $s->sourcebasepath = 'C:\frame\batch1\out';
239             $s->targetFolder = qq(RyffineImportSGIfm);
240             $s->imagePath = qq(images);
241             $s->version = 1;
242              
243             say STDERR $s->createSDLFileMap(qw(. xml));
244              
245             Produces:
246              
247            
248             ;
249            
250            
251            
252             bm_0003388-002'
253             1
254             en-US
255             bill.gearhart@hpe.com
256            
257            
258            
259              
260             etc.
261              
262             =head1 Description
263              
264             =head2 Constructor
265              
266             Construct a new SDL file map creator
267              
268             =head3 new()
269              
270             Create a new SDL file map creator - call this method statically as in Data::Edit::Xml::Lint::new()
271              
272              
273             =head3 Attributes
274              
275             Attributes describing a lint
276              
277             =head4 filePathFolder :lvalue
278              
279             Prefix this folder (if supplied) to the filepath
280              
281              
282             =head4 fileType :lvalue
283              
284             The fileType of the file to be processed
285              
286              
287             =head4 folderHasMixedContent :lvalue
288              
289             folderHasMixedContent field
290              
291              
292             =head4 ishType :lvalue
293              
294             IshType field
295              
296              
297             =head4 imagePath :lvalue
298              
299             Image path relative to sourcebasepath
300              
301              
302             =head4 language :lvalue
303              
304             The language of the content, defaults to: 'en-US'
305              
306              
307             =head4 lint :lvalue
308              
309             The lint of the file to be processed
310              
311              
312             =head4 sdlVersion :lvalue
313              
314             Version of SDL we are using, defaults to: '12.0.0.0'
315              
316              
317             =head4 section :lvalue
318              
319             Sub folder for file on SDL: maps, topics
320              
321              
322             =head4 sourcebasepath :lvalue
323              
324             Path to source to be uploaded
325              
326              
327             =head4 targetFolder :lvalue
328              
329             The SDL target folder to be used
330              
331              
332             =head4 version :lvalue
333              
334             Version of the input content
335              
336              
337             =head2 SDL File Map
338              
339             Generate an SDL file map
340              
341             =head3 createSDLFileMap($@)
342              
343             Generate an SDL file map for a selected set of files
344              
345             1 $sdl Sdl
346             2 @foldersAndExtensions Directory tree search specification
347              
348              
349             =head1 Private Methods
350              
351             =head2 xmlLineOne()
352              
353             Line one of all xml files
354              
355              
356             =head2 getFileMap()
357              
358             File map tag
359              
360              
361             =head2 getFile($$)
362              
363             File tag
364              
365             1 $sdl Sdl file map creator
366             2 $images Processing an image file or not
367              
368             =head2 getIshObject()
369              
370             IshObject tag
371              
372              
373             =head2 getFTitle()
374              
375             FTITLE tag
376              
377              
378             =head2 getVersion()
379              
380             Version tag
381              
382              
383             =head2 getDocLanguage()
384              
385             DOC-LANGUAGE tag
386              
387              
388             =head2 getAuthor()
389              
390             Author tag
391              
392              
393             =head2 getResolution()
394              
395             Resolution
396              
397              
398              
399             =head1 Index
400              
401              
402             L
403              
404             L
405              
406             L
407              
408             L
409              
410             L
411              
412             L
413              
414             L
415              
416             L
417              
418             L
419              
420             L
421              
422             L
423              
424             L
425              
426             L
427              
428             L
429              
430             L
431              
432             L
433              
434             L
435              
436             L
437              
438             L
439              
440             L
441              
442             L
443              
444             L
445              
446             L
447              
448             =head1 Installation
449              
450             This module is written in 100% Pure Perl and, thus, it is easy to read, use,
451             modify and install.
452              
453             Standard Module::Build process for building and installing modules:
454              
455             perl Build.PL
456             ./Build
457             ./Build test
458             ./Build install
459              
460             =head1 Author
461              
462             L
463              
464             L
465              
466             =head1 Copyright
467              
468             Copyright (c) 2016-2017 Philip R Brenan.
469              
470             This module is free software. It may be used, redistributed and/or modified
471             under the same terms as Perl itself.
472              
473             =cut
474              
475              
476             # Tests and documentation
477              
478             sub test
479 1     1 0 7 {my $p = __PACKAGE__;
480 1 50       53 return if eval "eof(${p}::DATA)";
481 1         42 my $s = eval "join('', <${p}::DATA>)";
482 1 50       6 $@ and die $@;
483 1     1 0 6 eval $s;
  1     1 0 1  
  1     1 0 34  
  1     1 0 4  
  1     1 0 2  
  1     1   19  
  1     1   497  
  1     3   52697  
  1         10  
  1         90  
  1         57  
  1         4  
  1         4  
  1         5  
  3         6  
  3         11  
  3         167  
  3         8  
484 1 50       820 $@ and die $@;
485             }
486              
487             test unless caller;
488              
489             1;
490             # podDocumentation
491              
492             __DATA__