File Coverage

blib/lib/FusionInventory/Agent/Task/Inventory/MacOS/USB.pm
Criterion Covered Total %
statement 14 23 60.8
branch 0 4 0.0
condition 0 3 0.0
subroutine 5 7 71.4
pod 0 2 0.0
total 19 39 48.7


line stmt bran cond sub pod time code
1             package FusionInventory::Agent::Task::Inventory::MacOS::USB;
2              
3 2     2   62285451 use strict;
  2         9  
  2         81  
4 2     2   11 use warnings;
  2         11  
  2         113  
5              
6 2     2   559 use FusionInventory::Agent::Tools;
  2         5  
  2         270  
7 2     2   795 use FusionInventory::Agent::Tools::MacOS;
  2         4  
  2         417  
8              
9             my $seen;
10              
11             sub isEnabled {
12 0     0 0 0 my (%params) = @_;
13 0 0       0 return 0 if $params{no_category}->{usb};
14 0         0 return 1;
15             }
16              
17             sub doInventory {
18 0     0 0 0 my (%params) = @_;
19              
20 0         0 my $inventory = $params{inventory};
21 0         0 my $logger = $params{logger};
22              
23 0         0 foreach my $device (_getDevices(logger => $logger)) {
24             # avoid duplicates
25 0 0 0     0 next if $device->{SERIAL} && $seen->{$device->{SERIAL}}++;
26 0         0 $inventory->addEntry(
27             section => 'USBDEVICES',
28             entry => $device,
29             );
30             }
31             }
32              
33             sub _getDevices {
34              
35             return
36             map {
37 2     2   302 {
38             VENDORID => dec2hex($_->{'idVendor'}),
39             PRODUCTID => dec2hex($_->{'idProduct'}),
40             SERIAL => $_->{'USB Serial Number'},
41             NAME => $_->{'USB Product Name'},
42             CLASS => $_->{'bDeviceClass'},
43 11         22 SUBCLASS => $_->{'bDeviceSubClass'}
44             }
45             }
46             getIODevices(class => 'IOUSBDevice', @_);
47             }
48              
49             1;