File Coverage

lib/Ixchel/functions/serial.pm
Criterion Covered Total %
statement 14 19 73.6
branch 0 2 0.0
condition n/a
subroutine 5 6 83.3
pod 1 1 100.0
total 20 28 71.4


line stmt bran cond sub pod time code
1             package Ixchel::functions::serial;
2              
3 5     5   90140 use 5.006;
  5         17  
4 5     5   24 use strict;
  5         10  
  5         149  
5 5     5   19 use warnings;
  5         5  
  5         229  
6 5     5   441 use File::Slurp;
  5         33871  
  5         370  
7 5     5   30 use Exporter 'import';
  5         12  
  5         837  
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 0     0 1   my $output = `dmidecode --string=system-serial-number 2> /dev/null`;
43 0 0         if ( $output =~ /To be/ ) {
44 0           $output = `dmidecode --string=baseboard-serial-number 2> /dev/null`;
45             }
46              
47 0           chomp($output);
48              
49 0           return $output;
50             }
51              
52             1;