### perl: poros/code/sysinfo

use strict;
use warnings;
use YAML::XS;

use Vulcan::SysInfo;
use constant INTERVAL => 6;

return sub
{
    my %param = @_;
    my @argv = @{ $param{argv} };
    my $interval = @argv > 1 ? shift @argv : INTERVAL;

    if ( my $test = shift @argv )
    {
        my $sar = Vulcan::SysInfo->new( interval => $interval );
        my $eval = sub
        {
            my $test = shift;
            my @test = grep { $sar->eval( $_ ) } ref $test ? @$test : $test;
            return @test ? \@test : undef;
        };

        if ( ref $test eq 'HASH' )
        {
            while ( my ( $key, $val ) = each %$test )
            {
                if ( $val = &$eval( $val ) ) { $test->{$key} = $val }
                else { delete $test->{$key} }
            }
            $test = undef unless %$test;
        }
        else { $test = &$eval( $test ) }
        YAML::XS::DumpFile \*STDOUT, $test if $test;
    }
    return 0;
};
