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