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   1241 use strict;
  2         4  
  2         90  
12 2     2   11 use warnings;
  2         3  
  2         91  
13 2     2   9 use utf8;
  2         3  
  2         10  
14             ## use critic (Modules::RequireExplicitPackage)
15              
16             package Sys::OsPackage::Driver::Arch;
17             $Sys::OsPackage::Driver::Arch::VERSION = '0.4.0';
18 2     2   121 use parent "Sys::OsPackage::Driver";
  2         3  
  2         15  
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(
54             { list => 1 },
55             $ospkg->sudo_cmd(), $querycmd,
56             qw(--sync --search --quiet),
57 0           '^' . $args_ref->{pkg} . '$'
58             );
59 0 0         return if not scalar @pkglist; # empty list means nothing found
60 0           return $pkglist[-1]; # last of sorted list should be most recent version
61             }
62              
63             # install package (arch)
64             sub install
65             {
66 0     0 0   my ( $class, $ospkg, $args_ref ) = @_;
67 0 0         return if not $class->pkgcmd($ospkg);
68              
69             # determine packages to install
70 0           my @packages;
71 0 0         if ( exists $args_ref->{pkg} ) {
72 0 0         if ( ref $args_ref->{pkg} eq "ARRAY" ) {
73 0           push @packages, @{ $args_ref->{pkg} };
  0            
74             } else {
75 0           push @packages, $args_ref->{pkg};
76             }
77             }
78              
79             # install the packages
80 0           my $pkgcmd = $ospkg->sysenv("pacman");
81 0           return $ospkg->run_cmd( $ospkg->sudo_cmd(), $pkgcmd, qw(--sync --needed --noconfirm --quiet), @packages );
82             }
83              
84             # check if an OS package is installed locally
85             sub is_installed
86             {
87 0     0 0   my ( $class, $ospkg, $args_ref ) = @_;
88 0 0         return if not $class->pkgcmd($ospkg);
89              
90             # check if package is installed
91 0           my $querycmd = $ospkg->sysenv("pacman");
92             my @pkglist = $ospkg->capture_cmd(
93             { list => 1 },
94             $ospkg->sudo_cmd(), $querycmd,
95             qw(--query --search --quiet),
96 0           '^' . $args_ref->{pkg} . '$'
97             );
98 0 0         return ( scalar @pkglist > 0 ) ? 1 : 0;
99             }
100              
101             1;
102              
103             =pod
104              
105             =encoding UTF-8
106              
107             =head1 NAME
108              
109             Sys::OsPackage::Driver::Arch - Arch Pacman packaging handler for Sys::OsPackage
110              
111             =head1 VERSION
112              
113             version 0.4.0
114              
115             =head1 SYNOPSIS
116              
117             my $ospkg = Sys::OsPackage->instance();
118              
119             # check if packaging commands exist for this system
120             if (not $ospkg->call_pkg_driver(op => "implemented")) {
121             return 0;
122             }
123              
124             # find OS package name for Perl module
125             my $pkgname = $ospkg->call_pkg_driver(op => "find", module => $module);
126              
127             # install a Perl module as an OS package
128             my $result1 = $ospkg->call_pkg_driver(op => "modpkg", module => $module);
129              
130             # install an OS package
131             my $result2 = $ospkg->call_pkg_driver(op => "install", pkg => $pkgname);
132              
133             =head1 DESCRIPTION
134              
135             ⛔ This is for Sys::OsPackage internal use only.
136              
137             The Sys::OsPackage method call_pkg_driver() will call the correct driver for the running platform.
138             The driver implements these methods: I, I, I, I, I and I.
139              
140             =head1 SEE ALSO
141              
142             Arch Linux docs: pacman L
143              
144             GitHub repository for Sys::OsPackage: L
145              
146             =head1 BUGS AND LIMITATIONS
147              
148             Please report bugs via GitHub at L
149              
150             Patches and enhancements may be submitted via a pull request at L
151              
152             =head1 LICENSE INFORMATION
153              
154             Copyright (c) 2022 by Ian Kluft
155              
156             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.
157              
158             =head1 AUTHOR
159              
160             Ian Kluft
161              
162             =head1 COPYRIGHT AND LICENSE
163              
164             This software is Copyright (c) 2022 by Ian Kluft.
165              
166             This is free software, licensed under:
167              
168             The Artistic License 2.0 (GPL Compatible)
169              
170             =cut
171              
172             __END__