#!# perl:poros:dmesg

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

use Vulcan::Grep;

return sub
{
    local $/ = "\n";

    my %param = @_;
    my ( $test ) = @{ $param{argv} };

    return 0 unless $test && ref $test eq 'HASH';

    my @dmesg = `dmesg`;
    for my $key ( keys %$test )
    {
        my $grep = Vulcan::Grep->new( input => \@dmesg, rule => $test->{$key} );
        if ( my @match = $grep->eval() ) { $test->{$key} = \@match }
        else { delete $test->{$key} }
    }

    YAML::XS::DumpFile \*STDOUT, $test if %$test;
    return 0;
};
