map users by name instead of id
[scpubgit/System-Introspector.git] / lib / System / Introspector / MountPoints.pm
1 package System::Introspector::MountPoints;
2 use Moo;
3
4 use System::Introspector::Util qw(
5     handle_from_file
6     transform_exceptions
7 );
8
9 sub gather {
10     my ($self) = @_;
11     return {
12         mtab => transform_exceptions {
13             return { entries
14                 => $self->_parse_tab_fh($self->_open_fh('/etc/mtab')) };
15         },
16         fstab => transform_exceptions {
17             return { entries
18                 => $self->_parse_tab_fh($self->_open_fh('/etc/fstab')) };
19         },
20     };
21 }
22
23 sub _open_fh {
24     my ($self, $file) = @_;
25     return handle_from_file $file;
26 }
27
28 sub _parse_tab_fh {
29     my ($self, $fh) = @_;
30     my @mounts;
31     while (defined( my $line = <$fh> )) {
32         chomp $line;
33         next if $line =~ m{^\s*$}
34              or $line =~ m{^\s*#};
35         my ($device, $point, $type, $opt, $dump, $pass)
36             = split m{\s+}, $line;
37         push @mounts, {
38             device_name => $device,
39             mount_point => $point,
40             fs_type     => $type,
41             dump_freq   => $dump,
42             pass_num    => $pass,
43             options     => {
44                 map {
45                     my ($name, $value) = split m{=}, $_, 2;
46                     $value = 1
47                         unless defined $value;
48                     ($name => $value);
49                 } split m{,}, $opt,
50             },
51         };
52     }
53     return \@mounts;
54 }
55
56 1;
57
58 __END__
59
60 =head1 NAME
61
62 System::Introspector::MountPoints - Gather moint point information
63
64 =head1 DESCRIPTION
65
66 Reads C<fstab> and C<mtab> files to provide mount point information.
67
68 =head1 SEE ALSO
69
70 =over
71
72 =item L<System::Introspector>
73
74 =back
75
76 =cut
77