File Coverage

script/gated2yaml
Criterion Covered Total %
statement 27 28 96.4
branch 4 8 50.0
condition n/a
subroutine 8 8 100.0
pod n/a
total 39 44 88.6


line stmt bran cond sub pod time code
1             #!/usr/bin/perl
2              
3             ##########################################################################
4             # Copyright (c) 2010-2012 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   670534 use strict;
  2         12  
  2         112  
20 2     2   23 use warnings;
  2         11  
  2         129  
21 2     2   1281 use Getopt::Long qw(:config posix_default bundling);
  2         17436  
  2         12  
22 2     2   1773 use OSPF::LSDB::gated;
  2         7  
  2         76  
23 2     2   841 use OSPF::LSDB::YAML;
  2         6  
  2         400  
24              
25             sub usage(@) {
26 1 50   1   4 print STDERR "Error: @_\n" if @_;
27 1         56 print STDERR <
28             Convert gated OSPF link state database to YAML file. If the gated
29             dump content file is not given on the command line, gdc is invoked
30             on the local machine.
31              
32             Usage: $0 [-h] [-D dump] [-H user\@host] [-S skip] [ospf.yaml]
33             -h help, print usage
34             -D dump file containg output of 'gdc dump'
35             -H user\@host use ssh to login into user\@host to run gdc there
36             -S skip skip first number of gated entries in dump file
37             ospf.yaml output file, default stdout
38             EOF
39 1         163 exit(2);
40             }
41              
42             sub main() {
43 2     2   4 my($file, $ssh, $skip);
44             GetOptions(
45 1     1   503 'h' => sub { usage() },
46 2 50       14 'D=s' => \$file,
47             'H=s' => \$ssh,
48             'S=i' => \$skip,
49             ) or usage("Bad option");
50 1 50       402 usage("Only one argument allowed") if @ARGV > 1;
51              
52 1         9 my $gated = OSPF::LSDB::gated->new(ssh => $ssh);
53 1         5 my $ospf = $gated->parse(dump => !$file, file => $file, skip => $skip);
54              
55 1         17 my $yaml = OSPF::LSDB::YAML->new($gated);
56 1 50       4 if (@ARGV > 0) {
57 1         4 $yaml->DumpFile($ARGV[0]);
58             } else {
59 0           print $yaml->Dump();
60             }
61             }
62              
63             main();