File Coverage

blib/lib/Sys/OsPackage/Driver/Arch.pm
Criterion Covered Total %
statement 12 45 26.6
branch 0 22 0.0
condition n/a
subroutine 4 9 44.4
pod 0 5 0.0
total 16 81 19.7


line stmt bran cond sub pod time code
1             # Sys::OsPackage::Driver::Arch
2             # ABSTRACT: Arch Pacman packaging handler for Sys::OsPackage
3             # Copyright (c) 2022 by Ian Kluft
4             # Open Source license Perl's Artistic License 2.0:
5             # SPDX-License-Identifier: Artistic-2.0
6              
7             # This module is maintained for minimal dependencies so it can build systems/containers from scratch.
8              
9             ## no critic (Modules::RequireExplicitPackage)
10             # This resolves conflicting Perl::Critic rules which want package and strictures each before the other
11 2     2   930 use strict;
  2         3  
  2         63  
12 2     2   10 use warnings;
  2         4  
  2         60  
13 2     2   11 use utf8;
  2         4  
  2         9  
14             ## use critic (Modules::RequireExplicitPackage)
15              
16             package Sys::OsPackage::Driver::Arch;
17             $Sys::OsPackage::Driver::Arch::VERSION = '0.1.7';
18 2     2   117 use base "Sys::OsPackage::Driver";
  2         37  
  2         1369  
19              
20             # check if packager command found (arch)
21             sub pkgcmd
22             {
23 0     0 0   my ($class, $ospkg) = @_;
24              
25 0 0         return (defined $ospkg->sysenv("pacman") ? 1 : 0);
26             }
27              
28             # find name of package for Perl module (arch)
29             sub modpkg
30             {
31 0     0 0   my ($class, $ospkg, $args_ref) = @_;
32 0 0         return if not $class->pkgcmd($ospkg);
33              
34             # search by arch format for Perl module packages
35 0           my $pkgname = join("-", "perl", map {lc $_} @{$args_ref->{mod_parts}});
  0            
  0            
36 0           $args_ref->{pkg} = $pkgname;
37 0 0         if (not $class->find($ospkg, $args_ref)) {
38 0           return;
39             }
40 0 0         $ospkg->debug() and print STDERR "debug(".__PACKAGE__."->modpkg): $pkgname\n";
41              
42             # package was found
43 0           return $pkgname;
44             }
45              
46             # find named package in repository (arch)
47             sub find
48             {
49 0     0 0   my ($class, $ospkg, $args_ref) = @_;
50 0 0         return if not $class->pkgcmd($ospkg);
51              
52 0           my $querycmd = $ospkg->sysenv("pacman");
53             my @pkglist = sort $ospkg->capture_cmd({list=>1}, $querycmd, qw(--sync --search --quiet),
54 0           '^'.$args_ref->{pkg}.'$');
55 0 0         return if not scalar @pkglist; # empty list means nothing found
56 0           return $pkglist[-1]; # last of sorted list should be most recent version
57             }
58              
59             # install package (arch)
60             sub install
61             {
62 0     0 0   my ($class, $ospkg, $args_ref) = @_;
63 0 0         return if not $class->pkgcmd($ospkg);
64              
65             # determine packages to install
66 0           my @packages;
67 0 0         if (exists $args_ref->{pkg}) {
68 0 0         if (ref $args_ref->{pkg} eq "ARRAY") {
69 0           push @packages, @{$args_ref->{pkg}};
  0            
70             } else {
71 0           push @packages, $args_ref->{pkg};
72             }
73             }
74              
75             # install the packages
76 0           my $pkgcmd = $ospkg->sysenv("pacman");
77 0           return $ospkg->run_cmd($pkgcmd, qw(--sync --needed --noconfirm --quiet), @packages);
78             }
79              
80             # check if an OS package is installed locally
81             sub is_installed
82             {
83 0     0 0   my ($class, $ospkg, $args_ref) = @_;
84 0 0         return if not $class->pkgcmd($ospkg);
85              
86             # check if package is installed
87 0           my $querycmd = $ospkg->sysenv("pacman");
88 0           my @pkglist = $ospkg->capture_cmd({list=>1}, $querycmd, qw(--query --search --quiet), '^'.$args_ref->{pkg}.'$');
89 0 0         return (scalar @pkglist > 0) ? 1 : 0;
90             }
91              
92             1;
93              
94             =pod
95              
96             =encoding UTF-8
97              
98             =head1 NAME
99              
100             Sys::OsPackage::Driver::Arch - Arch Pacman packaging handler for Sys::OsPackage
101              
102             =head1 VERSION
103              
104             version 0.1.7
105              
106             =head1 SYNOPSIS
107              
108             my $ospkg = Sys::OsPackage->instance();
109              
110             # check if packaging commands exist for this system
111             if (not $ospkg->call_pkg_driver(op => "implemented")) {
112             return 0;
113             }
114              
115             # find OS package name for Perl module
116             my $pkgname = $ospkg->call_pkg_driver(op => "find", module => $module);
117              
118             # install a Perl module as an OS package
119             my $result1 = $ospkg->call_pkg_driver(op => "modpkg", module => $module);
120              
121             # install an OS package
122             my $result2 = $ospkg->call_pkg_driver(op => "install", pkg => $pkgname);
123              
124             =head1 DESCRIPTION
125              
126             ⛔ This is for Sys::OsPackage internal use only.
127              
128             The Sys::OsPackage method call_pkg_driver() will call the correct driver for the running platform.
129             The driver implements these methods: I, I, I, I, I and I.
130              
131             =head1 SEE ALSO
132              
133             Arch Linux docs: pacman L
134              
135             GitHub repository for Sys::OsPackage: L
136              
137             =head1 BUGS AND LIMITATIONS
138              
139             Please report bugs via GitHub at L
140              
141             Patches and enhancements may be submitted via a pull request at L
142              
143             =head1 LICENSE INFORMATION
144              
145             Copyright (c) 2022 by Ian Kluft
146              
147             This module is distributed in the hope that it will be useful, but it is provided “as is” and without any express or implied warranties. For details, see the full text of the license in the file LICENSE or at L.
148              
149             =head1 AUTHOR
150              
151             Ian Kluft
152              
153             =head1 COPYRIGHT AND LICENSE
154              
155             This software is Copyright (c) 2022 by Ian Kluft.
156              
157             This is free software, licensed under:
158              
159             The Artistic License 2.0 (GPL Compatible)
160              
161             =cut
162              
163             __END__