lib/Rex/Pkg/OpenWrt.pm

filter: Statementstmt 36.5% 19 / 52 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 50.0% 6 / 12 Podpod 0.0% 0 / 6 totaltotal 30.8% 25 / 81 CC 7 SCAR 20.5
CC
7
Cov
31%
get_installed
20.0
update_system
12.0
new
6.0
CRAP 7.8
« lib/Rex/Interface/File/SSH.pm ↑ Summary lib/Rex/Service/SunOS/svcadm.pm »
1 # OpenWrt.pm
2 #
3 # Copyright 2013 Ferenc Erki <erkiferenc@gmail.com>
4 #
5 # OpenWrt package management module for (R)?ex
6 # based on Rex::Pkg::Debian
7  
8 package Rex::Pkg::OpenWrt;
9  
10 1 ▶use v5.14.4;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 1 our $VERSION = '1.16.1'; # VERSION
14  
15 1 ▶use Rex::Helper::Run;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use Rex::Commands::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use Rex::Pkg::Base;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 ▶use base qw(Rex::Pkg::Base);
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
Pod undocumented
21 0 my $that = shift;
22 0 ▶ my $proto = ref($that) || $that;
Condition0%0/3
ref $that || $that
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $that || $that
ref $that $that
Truth table0%0/3
A || B
A= ref $thatB= $that
ABresult
1X1
011
000
23 0 my $self = $proto->SUPER::new(@_);
24  
25 0 bless( $self, $proto );
26  
27 $self->{commands} = {
28 0 install => 'opkg install %s',
29 install_version => 'opkg install %s',
30 remove => 'opkg remove %s',
31 update_package_db => 'opkg update',
32 };
33  
34 0 return $self;
35 }
36  
37 0 ▶sub bulk_install {
Subroutine bulk_install: not called CC=1 SCAR=6.9
Pod undocumented
38 0 my ( $self, $packages_aref, $option ) = @_;
39  
40 0 delete $option->{version}; # makes no sense to specify the same version for several packages
41  
42 0 $self->update( "@{$packages_aref}", $option );
43  
44 0 return 1;
45 }
46  
47 0 ▶sub update_system {
Subroutine update_system: not called CC=3 SCAR=24.8
Pod undocumented
48 0 my ($self) = @_;
49 0 my @pkgs;
50 0 my @lines = i_run("opkg list-upgradable");
51  
52 0 for my $line (@lines) {
53 0 ▶ if ( $line =~ m/^(.*) - .* - .*$/ ) { push( @pkgs, $1 ); }
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^(.*) - .* - .*$/u) 0 0 0
54 }
55  
56 0 my $packages_to_upgrade = join( " ", @pkgs );
57  
58 0 i_run( "opkg upgrade " . $packages_to_upgrade );
59 }
60  
61 0 ▶sub get_installed {
Subroutine get_installed: not called CC=4 SCAR=30.0
Pod undocumented
62 0 my ( $self, $pkg ) = @_;
63 0 my @pkgs;
64 0 my $opkg_cmd = 'opkg list-installed';
65 0 ▶ if ($pkg) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pkg) 0 0 0
66 0 $opkg_cmd .= ' | grep "^' . $pkg . ' "';
67 }
68  
69 0 my @lines = i_run $opkg_cmd;
70  
71 0 for my $line (@lines) {
72 0 ▶ if ( $line =~ m/^(.*) - (.*)$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^(.*) - (.*)$/u) 0 0 0
73 0 push(
74 @pkgs,
75 {
76 name => $1,
77 version => $2,
78 }
79 );
80 }
81 }
82  
83 0 return @pkgs;
84 }
85  
86 0 ▶sub add_repository {
Subroutine add_repository: not called CC=1 SCAR=6.9
Pod undocumented
87 0 my ( $self, %data ) = @_;
88 append_if_no_such_line "/etc/opkg.conf",
89 "src/gz " . $data{"name"} . " " . $data{"url"},
90 $data{"name"},
91 0 $data{"url"};
92 }
93  
94 0 ▶sub rm_repository {
Subroutine rm_repository: not called CC=1 SCAR=6.9
Pod undocumented
95 0 my ( $self, $name ) = @_;
96 0 delete_lines_matching "/etc/opkg.conf" => "src/gz " . $name . " ";
97 }
98  
99 1 1;
« lib/Rex/Interface/File/SSH.pm ↑ Summary lib/Rex/Service/SunOS/svcadm.pm »