blib/lib/Ixchel/functions/serial.pm untested

filter: Statementstmt 0.0% 0 / 22 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 31 CC 2 SCAR 11.5
CC
2
Cov
0%
serial_num
6.0
BEGIN
2.0
BEGIN
2.0
CRAP 3.1
1 package Ixchel::functions::serial;
2  
3 use 5.006;
4 use strict;
5 use warnings;
6 use File::Slurp;
7 use Exporter 'import';
8 our @EXPORT = qw(serial_num);
9  
10 =head1 NAME
11  
12 Ixchel::functions::serial - Returns either system serial or baseboard serial found via dmidecode.
13  
14 =head1 VERSION
15  
16 Version 0.0.1
17  
18 =cut
19  
20 our $VERSION = '0.0.1';
21  
22 =head1 SYNOPSIS
23  
24 use Ixchel::functions::serial;
25  
26 print 'Serial: '.serial_num."\n";
27  
28 =head1 Functions
29  
30 =head2 serial_num
31  
32 Fetches either system-product-name or baseboard-serial-number via dmidecode.
33  
34 First system-serial-number is tried and if that matches /To be/, then
35 baseboard-serial-number is used.
36  
37 If not ran as root, this will return blank.
38  
39 =cut
40  
41 sub serial_num {
42 my $output = `dmidecode --string=system-serial-number 2> /dev/null`;
43 if ( $output =~ /To be/ ) {
44 $output = `dmidecode --string=baseboard-serial-number 2> /dev/null`;
45 }
46  
47 chomp($output);
48  
49 return $output;
50 }
51  
52 1;