File-Find-Rule-DMIDecode

 view release on metacpan or  search on metacpan

DMIDecode.pm  view on Meta::CPAN

	});
}

sub File::Find::Rule::dmidecode_handle {
	my ($file_find_rule, $handle) = @_;
	my $self = $file_find_rule->_force_object;
	return $self->file->exec(sub{
		my $file = shift;

		my $data = slurp($file);
		my $dmidecode = Parse::DMIDecode->new;
		$dmidecode->parse($data);

		return any { $_->handle eq $handle } $dmidecode->get_handles;
	});
}

sub File::Find::Rule::dmidecode_type {
	my ($file_find_rule, $dmi_type) = @_;
	my $self = $file_find_rule->_force_object;
	return $self->file->exec(sub{
		my $file = shift;

		my $data = slurp($file);
		my $dmidecode = Parse::DMIDecode->new;
		$dmidecode->parse($data);

		return $dmidecode->get_handles(dmitype => $dmi_type);
	});
}

1;

__END__

=pod

=encoding utf8

=head1 NAME

File::Find::Rule::DMIDecode - Common rules for searching for dmidecode files.

=head1 SYNOPSIS

 use File::Find::Rule;
 use File::Find::Rule::DMIDecode;

 my @files = File::Find::Rule->dmidecode_file->in($dir);
 my @files = File::Find::Rule->dmidecode_handle($handle)->in($dir);
 my @files = File::Find::Rule->dmidecode_type($dmi_type)->in($dir);

=head1 DESCRIPTION

This Perl module contains File::Find::Rule rules for detecting dmidecode files.

dmidecode text file is output of dmidecode tool, which prints information about
DMI.

DMI (Desktop Management Interface) generates a standard framework for managing
and tracking components in a desktop, notebook or server computer, by
abstracting these components from the software that manages them.
See L<DMI on Wikipedia|https://en.wikipedia.org/wiki/Desktop_Management_Interface>.

=head1 SUBROUTINES

=head2 C<dmidecode_file>

 my @files = File::Find::Rule->dmidecode_file->in($dir);

The C<dmidecode_file()> rule detect dmidecode files by parsing of structure.

=head2 C<dmidecode_handle>

 my @files = File::Find::Rule->dmidecode_handle($handle)->in($dir);

The C<dmidecode_handle($handle)> rule detect dmidecode handle in file.

=head2 C<dmidecode_type>

 my @files = File::Find::Rule->dmidecode_type($dmi_type)->in($dir);

The C<dmidecode_type($dmi_type)> rule detect dmidecode DMI type in file.

=head1 EXAMPLE1

 use strict;
 use warnings;

 use File::Find::Rule;
 use File::Find::Rule::DMIDecode;

 # Arguments.
 if (@ARGV < 1) {
         print STDERR "Usage: $0 dir\n";
         exit 1;
 }
 my $dir = $ARGV[0];

 # Print all dmidecode files in directory.
 foreach my $file (File::Find::Rule->dmidecode_file->in($dir)) {
         print "$file\n";
 }

 # Output like:
 # Usage: qr{[\w\/]+} dir

=head1 EXAMPLE2

 use strict;
 use warnings;

 use File::Find::Rule;
 use File::Find::Rule::DMIDecode;

 # Arguments.
 if (@ARGV < 2) {
         print STDERR "Usage: $0 dir handle\n";
         exit 1;
 }
 my $dir = $ARGV[0];



( run in 0.674 second using v1.01-cache-2.11-cpan-df04353d9ac )