package Ocsinventory::Agent::Backend::OS::Generic::Packaging::BSDpkg;

sub check {can_run("pkg_info")}

sub run {
  my $params = shift;
  my $inventory = $params->{inventory};

  my $from = 'BSDpkg';
  if (can_run("pkg_admin") && `pkg_admin config-var PKG_REFCOUNT_DBDIR` =~ m{^/}) {
    $from = 'pkgsrc';
  }

  foreach(`pkg_info`){
      /^(\S+)-(\d+\S*)\s+(.*)/;
      my $name = $1;
      my $version = $2;
      my $comments = $3;
      
      $inventory->addSoftware({
	  'COMMENTS' => $comments,
	  'NAME' => $name,
	  'VERSION' => $version,
	  'FROM' => $from
      });
  }
}

1;
