File Coverage

script/ospfconvert
Criterion Covered Total %
statement 23 26 88.4
branch 5 10 50.0
condition n/a
subroutine 7 7 100.0
pod n/a
total 35 43 81.4


line stmt bran cond sub pod time code
1             #!/usr/bin/perl
2              
3             ##########################################################################
4             # Copyright (c) 2010 Alexander Bluhm
5             #
6             # Permission to use, copy, modify, and distribute this software for any
7             # purpose with or without fee is hereby granted, provided that the above
8             # copyright notice and this permission notice appear in all copies.
9             #
10             # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11             # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12             # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13             # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14             # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15             # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16             # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17             ##########################################################################
18              
19 2     2   3336251 use strict;
  2         18  
  2         101  
20 2     2   17 use warnings;
  2         4  
  2         130  
21 2     2   1422 use Getopt::Long qw(:config posix_default bundling);
  2         20364  
  2         10  
22 2     2   1523 use OSPF::LSDB::YAML;
  2         8  
  2         436  
23              
24             sub usage(@) {
25 1 50   1   4 print STDERR "Error: @_\n" if @_;
26 1         44 print STDERR <
27             Convert OSPF LSDB in YAML format from old verion to current.
28              
29             Usage: $0 [-h] [oldospf.yaml] [ospf.yaml]
30             -h help, print usage
31             oldospf.yaml input file, default stdin
32             ospf.yaml output file, default stdout
33             EOF
34 1         195 exit(2);
35             }
36              
37             sub main() {
38             GetOptions(
39 1     1   294 'h' => sub { usage() },
40 2 50   2   12 ) or usage("Bad option");
41 1 50       166 usage("Only two arguments allowed") if @ARGV > 2;
42              
43 1         8 my $yaml = OSPF::LSDB::YAML->new();
44 1 50       3 if (@ARGV > 0) {
45 1         3 $yaml->LoadFile($ARGV[0]);
46             } else {
47 0         0 local $/;
48 0         0 $yaml->Load();
49             }
50              
51 1 50       1007 if (@ARGV > 1) {
52 1         3 $yaml->DumpFile($ARGV[1]);
53             } else {
54 0           print $yaml->Dump();
55             }
56             }
57              
58             main();