blib/lib/ios_get_interfaces.pm

filter: Statementstmt 26.9% 17 / 63 Branchbran 0.0% 0 / 32 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 50.0% 3 / 6 Podpod 0.0% 0 / 3 totaltotal 17.7% 20 / 113 CC 22 SCAR 51.3
CC
22
Cov
17%
get_info
272.0
make_report
30.0
new
12.0
CRAP 168.2
↑ Summary
1 #!/usr/bin/perl
2 package ios_get_interfaces;
3 1 ▶use 5.006001;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 require Exporter;
7 1 our @ISA = qw(Exporter);
8 1 our %EXPORT_TAGS = ('all' => [ qw(new get_info make_report)]);
9 1 our @EXPORT_OK = (@{$EXPORT_TAGS{'all'}});
10 1 our @EXPORT = qw();
11 1 our $VERSION ='1.7';
12 1 my ($class, $this, $router);
13 0 ▶sub new(){
Subroutine new: not called CC=3 SCAR=24.8
Pod undocumented
14 0 ▶ $class = shift or die $!;
Branch: 1 branch
BranchTrueFalseTotal
$class = shift() or die $! 0 0 0
15 0 ▶ $router = shift or die $!;
Branch: 1 branch
BranchTrueFalseTotal
$router = shift() or die $! 0 0 0
16 0 $this = {name=>$router->{name}, showrun_file=>$router->{showrun_file}, csv=>$router->{csv}};
17 0 bless $this,$class;
18 0 return $this;
19 }
20 ##################################################
21 0 ▶sub get_info(){
Subroutine get_info: not called CC=16 SCAR=56.1
Pod undocumented
22 0 ▶ $this = shift or die $!;
Branch: 1 branch
BranchTrueFalseTotal
$this = shift() or die $! 0 0 0
23 0 my @interfaces;
24 0 ▶ open F, $this->{showrun_file} or die "Can't find showrun file\n";
Branch: 1 branch
BranchTrueFalseTotal
open F, $this->{"showrun_file"} or die "Can't find showrun file\n" 0 0 0
25 0 my@f = <F>;
26 0 my ($interface, $address, $description, @split1, @split2, @split3);
27 0 close F;
28 0 foreach (@f){
29 0 chomp $_;
30 0 $_ =~ s/\cM//g;
31 0 $_ =~ s/\r//g;
32 0 ▶ if (/^interface/ .. /^!/){
Branch: 1 branch
BranchTrueFalseTotal
if (/^interface/ .. /^!/) 0 0 0
33 0 ▶ if ($_ =~ /^interface/){
Branch: 1 branch
BranchTrueFalseTotal
if ($_ =~ /^interface/) 0 0 0
34 0 @split1 = split " ", $_;
35 0 $interface = $split1[1];
36 0 $description = '';
37 0 $address = '';
38 }
39 0 ▶ if ($_ =~ /^ description/){
Branch: 1 branch
BranchTrueFalseTotal
if ($_ =~ /^ description/) 0 0 0
40 0 $description = $_;
41 0 $description =~ s/^ description //;
42 }
43 0 ▶ if (($_ =~ /^ ip address/) or ($_ =~ /^ no ip address/) or ($_ =~ /^ ip unnumbered/)){
Branch: 1 branch
BranchTrueFalseTotal
if ($_ =~ /^ ip address/ or $_ =~ /^ no ip address/ or $_ =~ /^ ip unnumbered/) 0 0 0
Condition0%0/6
$_ =~ /^ ip address/ or $_ =~ /^ no ip address/ or $_ =~ /^ ip unnumbered/
l!l&&r!l&&!r
000
$_ =~ /^ ip address/ or $_ =~ /^ no ip address/
l!l&&r!l&&!r
000
MC/DC0%0/3
$_ =~ /^ ip address/ or $_ =~ /^ no ip address/ or $_ =~ /^ ip unnumbered/
$_ =~ /^ ip address/ $_ =~ /^ no ip address/ $_ =~ /^ ip unnumbered/
Truth table0%0/4
A or B or C
A= $_ =~ /^ ip address/B= $_ =~ /^ no ip address/C= $_ =~ /^ ip unnumbered/
ABCresult
1XX1
01X1
0011
0000
44 0 @split2 = split " ", $_;
45 0 ▶ $address = "$split2[2]-->$split2[3]" if $split2[3];
Branch: 1 branch
BranchTrueFalseTotal
if $split2[3] 0 0 0
46 0 $address =~ s/\s//g;
47 0 ▶ $address = "No IPv4 address-->No netmask" if !$split2[3];
Branch: 1 branch
BranchTrueFalseTotal
unless $split2[3] 0 0 0
48 0 ▶ $this->{"Interface_".$interface."-->"} = "$address-->No description\n" if !$description;
Branch: 1 branch
BranchTrueFalseTotal
unless $description 0 0 0
49 0 ▶ $this->{"Interface_".$interface."-->"} = "$address-->$description\n" if $description;
Branch: 1 branch
BranchTrueFalseTotal
if $description 0 0 0
50 }
51 }
52 }
53 0 foreach my$int (sort keys %{$this}){
54 0 ▶ push @interfaces, $this->{name}."-->".$int.$this->{$int} if $int =~ /^Interface/;
Branch: 1 branch
BranchTrueFalseTotal
if $int =~ /^Interface/ 0 0 0
55 }
56 0 return \@interfaces;
57 }
58 ###################################################
59 0 ▶sub make_report(){
Subroutine make_report: not called CC=5 SCAR=34.0
Pod undocumented
60 0 ▶ $this = shift or die $!;
Branch: 1 branch
BranchTrueFalseTotal
$this = shift() or die $! 0 0 0
61 0 ▶ open CSV, ">$this->{csv}" or die "Can't find csv file\n";
Branch: 1 branch
BranchTrueFalseTotal
open CSV, qq[>$this->{"csv"}] or die "Can't find csv file\n" 0 0 0
62 0 print CSV "Name;Interface;IPv4 Address;Netmask;Description\n";
63 0 foreach my$int (sort keys %{$this}){
64 0 my $intclean = $int;
65 0 $intclean =~ s/^Interface_//;
66 0 $intclean =~ s/-->/;/g;
67 0 $this->{$int} =~ s/-->/;/g;
68 0 ▶ print CSV $this->{name}.";".$intclean.$this->{$int} if $int =~ /^Interface/;
Branch: 1 branch
BranchTrueFalseTotal
if $int =~ /^Interface/ 0 0 0
69 }
70 0 close CSV;
71 }
72 1 return 1;
73 __END__
↑ Summary