File Coverage

blib/lib/Data/Edit/Xml/SDL.pm
Criterion Covered Total %
statement 108 109 99.0
branch 13 20 65.0
condition n/a
subroutine 25 25 100.0
pod 11 17 64.7
total 157 171 91.8


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