script/gated2yaml

filter: Statementstmt 96.5% 28 / 29 Branchbran 50.0% 4 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 8 / 8 Podpod n/a totaltotal 88.8% 40 / 45 CC 5 SCAR 8.1
CC
5
Cov
86%
main
4.2
usage
2.0
BEGIN
1.0
CRAP 2.3
« script/ospfconvert ↑ Summary blib/lib/OSPF/LSDB/YAML.pm »
1 #!/usr/bin/perl
2  
3 ##########################################################################
4 # Copyright (c) 2010-2012 Alexander Bluhm <alexander.bluhm@gmx.net>
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 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 2 ▶use Getopt::Long qw(:config posix_default bundling);
Subroutine BEGIN: called CC=1 SCAR=0.0
22 2 ▶use OSPF::LSDB::gated;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 2 ▶use OSPF::LSDB::YAML;
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 sub usage(@) {
26 1 ▶ print STDERR "Error: @_\n" if @_;
Subroutine usage: called CC=2 SCAR=7.1
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 1 1
27 1 print STDERR <<EOF;
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 exit(2);
40 }
41  
42 sub main() {
43 2 ▶ my($file, $ssh, $skip);
Subroutine main: called CC=4 SCAR=14.5
44 GetOptions(
45 1 ▶ 'h' => sub { usage() },
Subroutine __ANON__: called CC=1 SCAR=0.0
46 2 ▶ 'D=s' => \$file,
Branch: 1 branch
BranchTrueFalseTotal
&GetOptions("h", sub { &usage(); } , "D=s", \$file, "H=s", \$ssh, "S=i", \$skip) or &usage("Bad option") 0 1 1
47 'H=s' => \$ssh,
48 'S=i' => \$skip,
49 ) or usage("Bad option");
50 1 ▶ usage("Only one argument allowed") if @ARGV > 1;
Branch: 1 branch
BranchTrueFalseTotal
if @ARGV > 1 0 1 1
51  
52 1 my $gated = OSPF::LSDB::gated->new(ssh => $ssh);
53 1 my $ospf = $gated->parse(dump => !$file, file => $file, skip => $skip);
54  
55 1 my $yaml = OSPF::LSDB::YAML->new($gated);
56 1 ▶ if (@ARGV > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (@ARGV > 0) { } 1 0 1
57 1 $yaml->DumpFile($ARGV[0]);
58 } else {
59 0 print $yaml->Dump();
60 }
61 }
62  
63 1 main();
« script/ospfconvert ↑ Summary blib/lib/OSPF/LSDB/YAML.pm »