script/mab2_convert.pl untested

filter: Statementstmt 0.0% 0 / 54 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 12 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 0.0% 0 / 11 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 96 CC 4 SCAR 15.5
CC
4
Cov
0%
convert
12.0
cli_usage
6.0
BEGIN
2.0
CRAP 4.7
1 #!/usr/local/bin/perl
2  
3 # PODNAME: mab2_convert.pl
4 our $VERSION = '0.11';
5  
6 use utf8;
7 use warnings;
8  
9 use Getopt::Long;
10 use MAB2::Parser::Disk;
11 use MAB2::Parser::RAW;
12 use MAB2::Parser::XML;
13 use MAB2::Writer::Disk;
14 use MAB2::Writer::RAW;
15 use MAB2::Writer::XML;
16  
17 my ($in, $out, $from, $to);
18  
19 my $options_ok = GetOptions (
20 'i=s' => \$in,
21 'o=s' => \$out,
22 'f=s' => \$from,
23 't=s' => \$to,
24 'help' => sub { cli_usage() },
25 'usage' => sub { cli_usage() },
26 );
27  
28 cli_usage() if !$options_ok or !$in or !$out or !$from or !$to;
29  
30 my $formats = qr{^(Disk|RAW|XML)$};
31 die "Not a valid input format \"$from\"" if $from !~ m/$formats/;
32 die "Not a valid output format \"$to\"" if $to !~ m/$formats/;
33  
34 convert($in, $out, $from, $to);
35  
36 sub cli_usage {
37
38 my $usage = <<END;
39  
40 Usage: mab2_convert.pl -i mab2raw.dat -o mab2xml.xml -f RAW -t XML
41  
42 Description: Convert records from one MAB2 format to an other.
43  
44 Options:
45 -i Specify input file.
46 -o Specify output file.
47 -f Specify input format (Disk|RAW|XML).
48 -t Specify output format (Disk|RAW|XML).
49
50 --help Print this documentation
51 END
52
53 print "Unknown option: @_\n" if ( @_ );
54 print "$usage\n";
55 exit;
56 }
57  
58 sub convert {
59 my ($in, $out, $from, $to) = @_;
60 print "START\n";
61 my $parser = "MAB2::Parser::$from"->new( $in );
62 my $writer;
63 if ($to eq 'XML') {
64 $writer = MAB2::Writer::XML->new( file => $out, xml_declaration => 1, collection => 1 );
65 $writer->start();
66 }
67 else{
68 $writer = "MAB2::Writer::$to"->new( file => $out );
69
70 }
71 while ( my $record = $parser->next() ) {
72 $writer->write($record);
73 }
74 $writer->end() if $to eq 'XML';
75 print "DONE\n";
76 }
77  
78 __END__