script/ospfconvert

filter: Statementstmt 88.8% 24 / 27 Branchbran 50.0% 5 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 7 / 7 Podpod n/a totaltotal 81.8% 36 / 44 CC 6 SCAR 12.4
CC
6
Cov
78%
main
6.5
usage
2.0
BEGIN
1.0
CRAP 3.5
« blib/lib/OSPF/LSDB.pm ↑ Summary script/gated2yaml »
1 #!/usr/bin/perl
2  
3 ##########################################################################
4 # Copyright (c) 2010 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::YAML;
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 sub usage(@) {
25 1 ▶ print STDERR "Error: @_\n" if @_;
Subroutine usage: called CC=2 SCAR=7.1
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 1 1
26 1 print STDERR <<EOF;
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 exit(2);
35 }
36  
37 sub main() {
38 GetOptions(
39 1 ▶ 'h' => sub { usage() },
Subroutine __ANON__: called CC=1 SCAR=0.0
40 2 ▶ ) or usage("Bad option");
Subroutine main: called CC=5 SCAR=18.7
Branch: 1 branch
BranchTrueFalseTotal
&GetOptions("h", sub { &usage(); } ) or &usage("Bad option") 0 1 1
41 1 ▶ usage("Only two arguments allowed") if @ARGV > 2;
Branch: 1 branch
BranchTrueFalseTotal
if @ARGV > 2 0 1 1
42  
43 1 my $yaml = OSPF::LSDB::YAML->new();
44 1 ▶ if (@ARGV > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (@ARGV > 0) { } 1 0 1
45 1 $yaml->LoadFile($ARGV[0]);
46 } else {
47 0 local $/;
48 0 $yaml->Load(<STDIN>);
49 }
50  
51 1 ▶ if (@ARGV > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@ARGV > 1) { } 1 0 1
52 1 $yaml->DumpFile($ARGV[1]);
53 } else {
54 0 print $yaml->Dump();
55 }
56 }
57  
58 1 main();
« blib/lib/OSPF/LSDB.pm ↑ Summary script/gated2yaml »