bin/alvisXMLjoin

filter: Statementstmt 100% 18 / 18 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 6 / 6 Podpod n/a totaltotal 100% 24 / 24 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« blib/lib/Alvis/Convert.pm ↑ Summary bin/alvisXMLmerge »
1 #!/usr/bin/perl -w
2
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4
5 1 ▶use Getopt::Long;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Pod::Usage;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Encode;
Subroutine BEGIN: called CC=1 SCAR=0.0
8
9 1 ▶use Alvis::Utils qw(open_file);
Subroutine BEGIN: called CC=1 SCAR=0.0
10
11 1 ▶use encoding 'utf8';
Subroutine BEGIN: called CC=1 SCAR=0.0
12 use open ':utf8';
13
14 my $xml_header = '<?xml version="1.0" encoding="UTF-8"?>';
15 my $doc_col = '<documentCollection xmlns="http://alvis.info/enriched/" version="1.1">';
16 my $doc_col_end = '</documentCollection>';
17
18 ################################################################################
19 # main
20
21 join_files(read_params());
22
23 ################################################################################
24 sub join_files {
25
26 my $files = shift;
27
28 print $xml_header, "\n", $doc_col, "\n";
29 for my $file ( @{$files} ) {
30 my $FP = open_file($file);
31 for my $str (<$FP>) {
32 if ( $str =~ /^<\?xml version/ ) {
33 next;
34 }
35 elsif ( $str =~ /^\s*<documentCollection/ ) {
36 next;
37 }
38 elsif ( $str =~ /^\s*<\/documentCollection/ ) {
39 next;
40 }
41 else {
42 print $str;
43 }
44 }
45 close $FP;
46 }
47 print $doc_col_end, "\n";
48 }
49
50 ################################################################################
51 sub read_params
52 {
53 my @files;
54 GetOptions(
55 '<>' => sub { push @files, @_ },
56 'h|help' => sub { pod2usage(1) }
57 );
58
59 pod2usage( -message => "ERROR: list of files is not specified" )
60 if ( !defined( $files[0] ) );
61
62 # TODO: this is the case then directory is emty
63 return \() if ($files[0] =~ /\/\*/ && not(-e $files[0]));
64 for my $file (@files) {
65 pod2usage( -message => "ERROR: file does not exist '$file'" )
66 unless (-f $file);
67 }
68 return \@files;
69 }
70 ################################################################################
71
72 __END__
« blib/lib/Alvis/Convert.pm ↑ Summary bin/alvisXMLmerge »