X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FSystem%2FIntrospector%2FDiskUsage.pm;h=b2d1d9e2e53cb0f102305787b9db3799847eff08;hb=f5dff4ce7ff7705d5fbc5e8848e673eb14123c62;hp=ef7e6d9114b63d5f0a08c458a2788f6f4b4d0cac;hpb=535e84b638c44a870dff749dfbd80fc8d4b2ec50;p=scpubgit%2FSystem-Introspector.git diff --git a/lib/System/Introspector/DiskUsage.pm b/lib/System/Introspector/DiskUsage.pm index ef7e6d9..b2d1d9e 100644 --- a/lib/System/Introspector/DiskUsage.pm +++ b/lib/System/Introspector/DiskUsage.pm @@ -1,25 +1,36 @@ package System::Introspector::DiskUsage; use Moo; +use System::Introspector::Util qw( + lines_from_command + transform_exceptions +); + sub gather { my ($self) = @_; - my @lines = `df -aP`; - shift @lines; # header - chomp @lines; - my @rows; - for my $line (@lines) { - my %row; - @row{qw( - filesystem - blocks_1024 - used - available - capacity - mount_point - )} = split m{\s+}, $line; - push @rows, \%row; - } - return \@rows; + return transform_exceptions { + my @lines = lines_from_command ['df', '-aP']; + shift @lines; # header + my @rows; + for my $line (@lines) { + my %row; + @row{qw( + filesystem + blocks_1024 + used + available + capacity + mount_point + )} = split m{\s+}, $line; + push @rows, \%row; + } + no warnings 'uninitialized'; + return { disk_usage => [ sort { + ($a->{filesystem} cmp $b->{filesystem}) + || + ($a->{mount_point} cmp $b->{mount_point}) + } @rows ] }; + }; } 1;