File Coverage

blib/lib/Device/USB/DevInterface.pm
Criterion Covered Total %
statement 11 28 39.2
branch 0 2 0.0
condition n/a
subroutine 4 12 33.3
pod 8 8 100.0
total 23 50 46.0


line stmt bran cond sub pod time code
1             package Device::USB::DevInterface;
2              
3             require 5.006;
4 19     19   112 use warnings;
  19         36  
  19         588  
5 19     19   100 use strict;
  19         34  
  19         703  
6 19     19   120 use Carp;
  19         37  
  19         4880  
7              
8             =head1 Device::USB::DevInterface
9              
10             This class encapsulates a USB Device Interface and the methods that object
11             would support.
12              
13             =head1 NAME
14              
15             Device::USB::DevInterface - Access a device interface returned by libusb.
16              
17             =head1 VERSION
18              
19             Version 0.36
20              
21             =cut
22              
23             our $VERSION=0.36;
24              
25             =head1 SYNOPSIS
26              
27             Device::USB:DevInterface provides a Perl object for accessing an
28             interface of a configuration of a USB device using the libusb library.
29              
30             use Device::USB;
31              
32             my $usb = Device::USB->new();
33             my $dev = $usb->find_device( $VENDOR, $PRODUCT );
34              
35             printf "Device: %04X:%04X\n", $dev->idVendor(), $dev->idProduct();
36             $dev->open();
37              
38             my $cfg = $dev->config()->[0];
39             my $inter = $cfg->interfaces()->[0];
40             print "Interface:", $inter->bInterfaceNumber(),
41             " name: ", $dev->get_string_simple($iter->iInterface()),
42             ": endpoint count: ", $inter->nNumEndpoints(), "\n";
43              
44             See USB specification for an explanation of the attributes of an
45             interface.
46              
47             =head1 DESCRIPTION
48              
49             This module defines a Perl object that represents the data associated with
50             a USB device configuration's interface. The object provides read-only access
51             to the important data associated with the interface.
52              
53             =head2 METHODS
54              
55             There are several accessor methods that return data from the interface.
56             Each is named after the field that they return. These accessors include:
57              
58             =cut
59              
60             # I need to build a lot of accessors
61             sub _make_descr_accessor
62             {
63 133     133   207 my $name = shift;
64             ## no critic (ProhibitStringyEval)
65              
66 133     0 1 6239 return eval <<"EOE";
  0     0 1    
  0     0 1    
  0     0 1    
  0     0 1    
  0     0 1    
  0     0 1    
  0            
  0            
  0            
  0            
  0            
  0            
  0            
  0            
67             sub $name
68             {
69             my \$self = shift;
70             return \$self->{$name};
71             }
72             EOE
73             }
74              
75             =over 4
76              
77             =item bInterfaceNumber
78              
79             The 0-based number of this interface.
80              
81             =item bAlternateSetting
82              
83             Value used to select this alternate setting for the interface specified
84             in bInterfaceNumber.
85              
86             =item bNumEndpoints
87              
88             Number of endpoints (excluding endpoint 0) available on this interface.
89             If the value is 0, only the control interface is supported.
90              
91             =item bInterfaceClass
92              
93             Class code as specified by the USB-IF. A value of 0xff is a vendor-specific
94             interface class.
95              
96             =item bInterfaceSubClass
97              
98             Subclass code specified by the USB-IF. If bInterfaceClass is not 0xff,
99             this field must use only subclasses specified by the USB-IF.
100              
101             =item bInterfaceProtocol
102              
103             The InterfaceProtocol as specified by the USB-IF. A value of 0xff uses
104             a vendor-specific protocol.
105              
106             =item iInterface
107              
108             Returns the index of the string descriptor describing this interface.
109             The string can be retrieved using the method
110             C.
111              
112             =cut
113              
114             _make_descr_accessor( 'bInterfaceNumber' );
115             _make_descr_accessor( 'bAlternateSetting' );
116             _make_descr_accessor( 'bNumEndpoints' );
117             _make_descr_accessor( 'bInterfaceClass' );
118             _make_descr_accessor( 'bInterfaceSubClass' );
119             _make_descr_accessor( 'bInterfaceProtocol' );
120             _make_descr_accessor( 'iInterface' );
121              
122             =item endpoints
123              
124             Returns a list of endpoint objects associated with this interface.
125              
126             =cut
127              
128             sub endpoints
129             {
130 0     0 1   my $self = shift;
131 0 0         return wantarray ? @{$self->{endpoints}} : $self->{endpoints};
  0            
132             }
133              
134             =back
135              
136             =head1 DIAGNOSTICS
137              
138             This is an explanation of the diagnostic and error messages this module
139             can generate.
140              
141             =head1 DEPENDENCIES
142              
143             This module depends on the Carp, Inline and Inline::C modules, as well as
144             the strict and warnings pragmas. Obviously, libusb must be available since
145             that is the entire reason for the module's existence.
146              
147             =head1 AUTHOR
148              
149             G. Wade Johnson (gwadej at cpan dot org)
150             Paul Archer (paul at paularcher dot org)
151              
152             Houston Perl Mongers Group
153              
154             =head1 BUGS
155              
156             Please report any bugs or feature requests to
157             C, or through the web interface at
158             L.
159             I will be notified, and then you'll automatically be notified of progress on
160             your bug as I make changes.
161              
162             =head1 ACKNOWLEDGEMENTS
163              
164             Thanks go to various members of the Houston Perl Mongers group for input
165             on the module. But thanks mostly go to Paul Archer who proposed the project
166             and helped with the development.
167              
168             =head1 COPYRIGHT & LICENSE
169              
170             Copyright 2006-2013 Houston Perl Mongers
171              
172             This program is free software; you can redistribute it and/or modify it
173             under the same terms as Perl itself.
174              
175             =cut
176              
177             1;