<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">package GLPI::Agent::Task::Inventory::Generic::Softwares::Gentoo;

use strict;
use warnings;

use parent 'GLPI::Agent::Task::Inventory::Module';

use English qw(-no_match_vars);

use GLPI::Agent::Tools;

sub isEnabled {
    return canRun('equery');
}

sub doInventory {
    my (%params) = @_;

    my $inventory = $params{inventory};
    my $logger    = $params{logger};

    my $command = _equeryNeedsWildcard() ?
        "equery list -i '*'" : "equery list -i";

    my $packages = _getPackagesList(
        logger =&gt; $logger, command =&gt; $command
    );

    foreach my $package (@$packages) {
        $inventory-&gt;addEntry(
            section =&gt; 'SOFTWARES',
            entry   =&gt; $package
        );
    }
}

sub _getPackagesList {
    my $handle = getFileHandle(@_);

    my @packages;
    while (my $line = &lt;$handle&gt;) {
        chomp $line;
        next unless $line =~ /^(.*)-([0-9]+.*)/;
        push @packages, {
            NAME    =&gt; $1,
            VERSION =&gt; $2,
        };
    }
    close $handle;

    return \@packages;
}

# http://forge.fusioninventory.org/issues/852
sub _equeryNeedsWildcard {
    my ($major, $minor) = getFirstMatch(
        command =&gt; 'equery -V',
        pattern =&gt; qr/^equery ?\((\d+)\.(\d+)\.\d+\)/,
        @_
    );

    # true starting from version 0.3
    return compareVersion($major, $minor, 0, 3);
}

1;
</pre></body></html>