File Coverage

blib/lib/Sys/OsPackage/Driver.pm
Criterion Covered Total %
statement 15 16 93.7
branch 1 2 50.0
condition n/a
subroutine 5 5 100.0
pod 0 2 0.0
total 21 25 84.0


line stmt bran cond sub pod time code
1             # Sys::OsPackage::Driver
2             # ABSTRACT: parent class for packaging handler drivers 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   1100 use strict;
  2         4  
  2         69  
12 2     2   21 use warnings;
  2         34  
  2         63  
13 2     2   10 use utf8;
  2         4  
  2         14  
14             ## use critic (Modules::RequireExplicitPackage)
15              
16             package Sys::OsPackage::Driver;
17             $Sys::OsPackage::Driver::VERSION = '0.3.1';
18             # demonstrate module is accessible without launching packaging commands
19             # all drivers inherit this to respond to ping for testing
20             sub ping
21             {
22 5     5 0 11 my $class = shift;
23              
24             # enforce class lineage
25 5 50       25 if (not $class->isa(__PACKAGE__)) {
26 0         0 return __PACKAGE__;
27             }
28              
29 5         23 return $class;
30             }
31              
32             # demonstrate modules are able to read the sudo flag via Sys::OsPackage's class interface
33             # returns "sudo" if the sudo flag is set and user is not already root, otherwise an empty list
34             sub sudo_check
35             {
36 10     10 0 21 my ($class, $ospkg ) = @_;
37              
38 10         26 my $cmd = $ospkg->sudo_cmd();
39 10         39 return $cmd;
40             }
41              
42             1;
43              
44             =pod
45              
46             =encoding UTF-8
47              
48             =head1 NAME
49              
50             Sys::OsPackage::Driver - parent class for packaging handler drivers for Sys::OsPackage
51              
52             =head1 VERSION
53              
54             version 0.3.1
55              
56             =head1 SYNOPSIS
57              
58             my $ospkg = Sys::OsPackage->instance();
59              
60             # check if packaging commands exist for this system
61             if (not $ospkg->call_pkg_driver(op => "implemented")) {
62             return 0;
63             }
64              
65             # find OS package name for Perl module
66             my $pkgname = $ospkg->call_pkg_driver(op => "find", module => $module);
67              
68             # install a Perl module as an OS package
69             my $result1 = $ospkg->call_pkg_driver(op => "modpkg", module => $module);
70              
71             # install an OS package
72             my $result2 = $ospkg->call_pkg_driver(op => "install", pkg => $pkgname);
73              
74             =head1 DESCRIPTION
75              
76             ⛔ This is for Sys::OsPackage internal use only.
77              
78             The Sys::OsPackage method call_pkg_driver() will call the correct driver for the running platform.
79              
80             All the platforms' packaging drivers must use this class as their parent class.
81              
82             =head1 SEE ALSO
83              
84             "pacman/Rosetta" at Arch Linux Wiki compares commands of 5 Linux packaging systems L
85              
86             GitHub repository for Sys::OsPackage: L
87              
88             =head1 BUGS AND LIMITATIONS
89              
90             Please report bugs via GitHub at L
91              
92             Patches and enhancements may be submitted via a pull request at L
93              
94             =head1 LICENSE INFORMATION
95              
96             Copyright (c) 2022 by Ian Kluft
97              
98             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.
99              
100             =head1 AUTHOR
101              
102             Ian Kluft
103              
104             =head1 COPYRIGHT AND LICENSE
105              
106             This software is Copyright (c) 2022 by Ian Kluft.
107              
108             This is free software, licensed under:
109              
110             The Artistic License 2.0 (GPL Compatible)
111              
112             =cut
113              
114             __END__