package System::Introspector::MountPoints;
use Moo;
+use System::Introspector::Util qw(
+ handle_from_file
+ transform_exceptions
+);
+
sub gather {
my ($self) = @_;
return {
- mtab => $self->_parse_tab_fh($self->_open_fh('/etc/mtab')),
- fstab => $self->_parse_tab_fh($self->_open_fh('/etc/fstab')),
+ mtab => transform_exceptions {
+ return { entries
+ => $self->_parse_tab_fh($self->_open_fh('/etc/mtab')) };
+ },
+ fstab => transform_exceptions {
+ return { entries
+ => $self->_parse_tab_fh($self->_open_fh('/etc/fstab')) };
+ },
};
}
sub _open_fh {
my ($self, $file) = @_;
- open my $fh, '<', $file
- or die "Unable to open $file: $!\n";
- return $fh;
+ return handle_from_file $file;
}
sub _parse_tab_fh {
my $tab = shift;
return sub {
for my $field (@fields) {
- ok not(grep { not defined $_->{$field} } @$tab),
+ my @entries = @{ $tab->{entries} };
+ ok not(grep { not defined $_->{$field} } @entries),
"all have $field";
}
};