File Coverage

blib/lib/Filesys/Type/Plugin/Unix.pm
Criterion Covered Total %
statement 21 21 100.0
branch 9 12 75.0
condition 2 4 50.0
subroutine 4 4 100.0
pod 0 3 0.0
total 36 44 81.8


line stmt bran cond sub pod time code
1             package Filesys::Type::Plugin::Unix;
2 1     1   1666 use strict;
  1         2  
  1         409  
3              
4             our $VERSION = 0.02;
5             our ($df,$mounted,$err);
6              
7             sub new {
8 1     1 0 1475 my $pkg = shift;
9              
10             #Check we really are on a Unix type operating system
11 1 50       22 return undef unless -d '/etc';
12              
13 1         4 bless {}, $pkg;
14             }
15              
16             sub fstype {
17 5     5 0 38 my ($self,$path) = @_;
18 5         29 $err = '';
19              
20 5         76557 $df = `df $path 2>/dev/null`;
21 5 100       120 $err = 'df command failed' unless $df;
22 5         86734 $mounted = `mount 2>/dev/null`; # Does not need root
23 5 100       146 $err = 'mount command failed' unless $df;
24 5 100       111 return undef if $err;
25              
26 3         169 my ($mounted_fs) = $df =~ /\d\%\s(\S+)/;
27 3 50       35 $err = 'df output did not parse' unless $mounted_fs;
28 3 50       39 return undef if $err;
29            
30 3         301 my ($fstype) = $mounted =~ /on\s$mounted_fs\stype\s(\w+)/;
31 3         855 $fstype;
32             }
33              
34             sub diagnose {
35 1   50 1 0 27 $df ||= 'undef';
36 1   50     201 $mounted ||= 'undef';
37 1         121 <
38             $err
39              
40             df command returned: $df
41              
42             mount command returned: $mounted
43              
44             END
45             }
46             1;
47