map users by name instead of id
[scpubgit/System-Introspector.git] / lib / System / Introspector / MountPoints.pm
CommitLineData
b99ec451 1package System::Introspector::MountPoints;
2use Moo;
3
579b73f0 4use System::Introspector::Util qw(
5 handle_from_file
6 transform_exceptions
7);
8
b99ec451 9sub gather {
10 my ($self) = @_;
11 return {
579b73f0 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 },
b99ec451 20 };
21}
22
23sub _open_fh {
24 my ($self, $file) = @_;
579b73f0 25 return handle_from_file $file;
b99ec451 26}
27
28sub _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,
46a24787 39 mount_point => $point,
b99ec451 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
561;
535e84b6 57
58__END__
59
60=head1 NAME
61
62System::Introspector::MountPoints - Gather moint point information
63
64=head1 DESCRIPTION
65
66Reads 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