XOG/Command/merge.pm untested

filter: Statementstmt 0.0% 0 / 44 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 0.0% 0 / 12 Podpod 0.0% 0 / 6 totaltotal 0.0% 0 / 73 CC 5 SCAR 19.5
CC
5
Cov
0%
execute
20.0
find_local_project_files
6.0
opt_spec
2.0
CRAP 7.0
1 package Clarity::XOG::Command::merge;
2  
3 use strict;
4 use warnings;
5  
6 use Clarity::XOG -command;
7 use Clarity::XOG::Merge;
8  
9 use Data::Dumper;
10 use File::Find::Rule;
11  
12 sub opt_spec
13 {
14 (
15 [ "out|o=s", "Write result to that file", { default => "XOGMERGE.xml" } ],
16 [ "in|i=s", "Search default input files in that subdir", { default => "." } ],
17 [ "verbose|v", "Be verbose", { default => 0 } ],
18 [ "debug|d", "Output debugging info", { default => 0 } ],
19 [ "force|f", "Force overwrite of existing output file.", { default => 0 } ],
20 );
21 }
22  
23 sub abstract { "merge several files" }
24  
25 sub description {
26  
27 " Merge Clarity project files.
28  
29 You either specify the files to merge or it finds all *.xml files
30 either in local directory or the directory you specified with -i.
31  
32 Specify an output file with -o, default is 'XOGMERGE.xml' in current
33 directory. If you want to force overwrite an existing output file
34 without asking then specify -f.
35  
36 During the process a temporary directory is created, used, and
37 cleaned up at the end.
38  
39 To self-test the xogtool use the 'xogtool selftest'.
40  
41 Options:"; }
42  
43 # The merge works as follows: In a first pass there is some XML element
44 # counting through the source xml files; that's kind of an
45 # optimization. In a 2nd pass all source xml files are read again, now
46 # all contained projects are sorted into temporary files respectively
47 # and then appended to final xml output file.
48  
49  
50 sub validate_args {
51 my ($self, $opt, $args) = @_;
52  
53 # no-op
54 }
55  
56 sub find_local_project_files {
57 my ($self, $opt, $args, $out_file) = @_;
58  
59 my $in_dir = $opt->{in};
60  
61 my @files =
62 grep { $_ ne $out_file }
63 File::Find::Rule
64 ->maxdepth(1)
65 ->file
66 ->name('*.XML', '*.xml')
67 ->in($in_dir);
68 if ($opt->{verbose}) {
69 print "Merge files:\n";
70 print " $_\n" foreach @files;
71 }
72 return \@files;
73 }
74  
75 sub execute {
76 my ($self, $opt, $args) = @_;
77  
78 print STDERR "opt: ", Dumper($opt) if $opt->{debug};
79 print STDERR "args: ", Dumper($args) if $opt->{debug};
80  
81 my $out_file = $opt->{out} || 't/xog-out.xml';
82 my $files = scalar @$args ? $args : $self->find_local_project_files($opt, $args, $out_file);
83  
84 my $merger = Clarity::XOG::Merge->new
85 (
86 files => $files,
87 out_file => $out_file,
88 verbose => $opt->{verbose},
89 debug => $opt->{debug},
90 force => $opt->{force},
91 );
92 $merger->Main;
93 }
94  
95 1;
96  
97 __END__