More/Linux.pm

filter: Statementstmt 38.4% 15 / 39 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 11 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 44.4% 4 / 9 Podpod 100% 4 / 4 totaltotal 28.7% 23 / 80 CC 11 SCAR 35.6
CC
11
Cov
25%
get_primary_adapter
72.0
__ANON__
20.0
get_remote_ips
2.0
CRAP 35.1
« More.pm ↑ Summary
1 package Net::OpenSSH::More::Linux;
2 2 $Net::OpenSSH::More::Linux::VERSION = '1.06';
3 #ABSTRACT: Useful subcommands for linux machines
4  
5 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 ▶use parent 'Net::OpenSSH::More';
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 2 ▶use File::Slurper ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12  
13 ###################
14 # PRIVATE METHODS #
15 ###################
16  
17 0 ▶my $get_addrs_for_iface = sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
18 0 my ( $self, $interface, $proto, $use_local ) = @_;
19 0 ▶ $interface ||= $self->get_primary_adapter($use_local);
Condition0%0/3
$interface ||= $self->get_primary_adapter($use_local)
l!l&&r!l&&!r
000
MC/DC0%0/2
$interface ||= $self->get_primary_adapter($use_local)
$interface $self->get_primary_adapter($use_local)
Truth table0%0/3
A ||= B
A= $interfaceB= $self->get_primary_adapter($use_local)
ABresult
1X1
011
000
20 0 $self->diag("Attempting to get $proto address for interface $interface");
21 0 ▶ my $regex = $proto eq 'inet' ? '[\d\.]+' : '[\da-f:]+'; # Close enough
Branch: 1 branch
BranchTrueFalseTotal
$proto eq 'inet' ? : 0 0 0
22  
23 0 my $cmd = "ip -f $proto addr show $interface scope global dynamic";
24 0 ▶ my $ip = $use_local ? `$cmd` : $self->cmd($cmd);
Branch: 1 branch
BranchTrueFalseTotal
$use_local ? : 0 0 0
25 0 my @matches = $ip =~ m/$proto\s+($regex)/g;
26 0 return @matches;
27 2 };
28  
29 #######################
30 # END PRIVATE METHODS #
31 #######################
32  
33  
34 0 ▶sub get_primary_adapter {
Subroutine get_primary_adapter: not called CC=8 SCAR=42.8
Pod documented
35 0 my ( $self, $use_local ) = @_;
36 0 my %interfaces;
37 0 ▶ my $proc_route_path = $use_local ? File::Slurper::read_text('/proc/net/route') : $self->sftp->get_content('/proc/net/route');
Branch: 1 branch
BranchTrueFalseTotal
$use_local ? : 0 0 0
38 0 foreach my $line ( split( /\n/, $proc_route_path ) ) {
39  
40 # Iface Destination Gateway Flags RefCt Use Metric Mask MTU Wndow IRTT
41 0 my ( $interface, $metric ) = $line =~ m/^(.+?)\s+[0-9A-F]{8}\s+[0-9A-F]{8}\s+\d+\s+\d+\s+\d+\s+(\d+)\s+[0-9A-F]{8}\s+\d+\s+\d+\s+\d+\s*$/;
42 0 ▶ push @{ $interfaces{$metric} }, $interface if ( length $interface && defined $metric );
Branch: 1 branch
BranchTrueFalseTotal
if length $interface and defined $metric 0 0 0
Condition0%0/3
length $interface and defined $metric
!ll&&!rl&&r
000
MC/DC0%0/2
length $interface and defined $metric
length $interface defined $metric
Truth table0%0/3
A and B
A= length $interfaceB= defined $metric
ABresult
0X0
100
111
43 }
44 0 my $lowest_metric = ( sort keys %interfaces )[0];
45 0 ▶ my $interface = $interfaces{$lowest_metric}->[0] if defined $lowest_metric && $interfaces{$lowest_metric};
Branch: 1 branch
BranchTrueFalseTotal
if defined $lowest_metric and $interfaces{$lowest_metric} 0 0 0
Condition0%0/3
defined $lowest_metric and $interfaces{$lowest_metric}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $lowest_metric and $interfaces{$lowest_metric}
defined $lowest_metric $interfaces{$lowest_metric}
Truth table0%0/3
A and B
A= defined $lowest_metricB= $interfaces{$lowest_metric}
ABresult
0X0
100
111
46 0 ▶ return $interface || 'eth0';
Condition0%0/2
$interface || 'eth0'
l!l
00
MC/DC0%0/1
$interface || 'eth0'
$interface
Truth table0%0/2
A
A= $interface
Aresult
11
00
47 }
48  
49  
50 0 ▶sub get_remote_ips {
Subroutine get_remote_ips: not called CC=1 SCAR=6.9
Pod documented
51 0 my ( $self, $interface ) = @_;
52 return (
53 0 'v4' => [ $get_addrs_for_iface->( $self, $interface, 'inet' ) ],
54 'v6' => [ $get_addrs_for_iface->( $self, $interface, 'inet6' ) ],
55 );
56 }
57  
58  
59 0 ▶sub get_local_ips {
Subroutine get_local_ips: not called CC=1 SCAR=6.9
Pod documented
60 0 my ( $self, $interface ) = @_;
61 return (
62 0 'v4' => [ $get_addrs_for_iface->( $self, $interface, 'inet', 1 ) ],
63 'v6' => [ $get_addrs_for_iface->( $self, $interface, 'inet6', 1 ) ],
64 );
65 }
66  
67  
68 0 ▶sub copy {
Subroutine copy: not called CC=1 SCAR=6.9
Pod documented
69 0 my ( $self, $SOURCE, $DEST ) = @_;
70 0 return $self->cmd( qw{cp -a}, $SOURCE, $DEST );
71 }
72  
73 2 1;
74  
75 __END__
« More.pm ↑ Summary