File Coverage

blib/lib/Device/USB/DevConfig.pm
Criterion Covered Total %
statement 11 26 42.3
branch 0 2 0.0
condition n/a
subroutine 4 11 36.3
pod 7 7 100.0
total 22 46 47.8


line stmt bran cond sub pod time code
1             package Device::USB::DevConfig;
2              
3             require 5.006;
4 19     19   109 use warnings;
  19         35  
  19         860  
5 19     19   113 use strict;
  19         31  
  19         593  
6 19     19   105 use Carp;
  19         34  
  19         4802  
7              
8             =head1 Device::USB::DevConfig
9              
10             This class encapsulates a USB Device Configuration and the methods that
11             object would support.
12              
13             =head1 NAME
14              
15             Device::USB::DevConfig - Access the device configuration 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:DevConfig provides a Perl object for accessing a configuration
28             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             print "Config:", $cfg->iConfiguration(), ": interface count: ",
40             $cfg->nNumInterfaces(), "\n";
41              
42             See USB specification for an explanation of the attributes of a
43             configuration.
44              
45             =head1 DESCRIPTION
46              
47             This module defines a Perl object that represents the data associated with
48             a USB device's configuration. The object provides read-only access to the
49             important data associated with the configuration.
50              
51             =head2 METHODS
52              
53             There are several accessor methods that return data from the configuration.
54             Each is named after the field that they return. These accessors include:
55              
56             =cut
57              
58             # I need to build a lot of accessors
59             sub _make_descr_accessor
60             {
61 114     114   247 my $name = shift;
62             ## no critic (ProhibitStringyEval)
63              
64 114     0 1 5077 return eval <<"EOE";
  0     0 1    
  0     0 1    
  0     0 1    
  0     0 1    
  0     0 1    
  0            
  0            
  0            
  0            
  0            
  0            
  0            
65             sub $name
66             {
67             my \$self = shift;
68             return \$self->{$name};
69             }
70             EOE
71             }
72              
73             =over 4
74              
75             =item wTotalLength
76              
77             Returns the total length of the data returned for this configuration.
78              
79             =item bNumInterfaces
80              
81             Returns the number of interfaces supported by this configuration.
82              
83             =item interfaces
84              
85             Returns a list of lists of interface objects associated with this
86             configuration. Each of the inner lists is a set of alternate versions
87             of that interface.
88              
89             =cut
90              
91             sub interfaces
92             {
93 0     0 1   my $self = shift;
94 0 0         return wantarray ? @{$self->{interfaces}} : $self->{interfaces};
  0            
95             }
96              
97             =item bConfigurationValue
98              
99             Returns the value passed to SetConfiguration to select this configuration.
100              
101             =item iConfiguration
102              
103             Returns the index of the string descriptor describing this configuration.
104             The string can be retrieved using the method
105             C.
106              
107             =item bmAttributes
108              
109             Returns a bitmap listing the attributes. The bits a number starting with
110             the LSB as 0. Bit 6 is 1 if the device is self-powered. Bit 5 is 1 if the
111             device supports Remote Wakeup.
112              
113             =item MaxPower
114              
115             Returns the Maximum power consumption in mA. This value is not in units of
116             2mA as in the spec, but in actual mA.
117              
118             =back
119              
120             =cut
121              
122             _make_descr_accessor( 'wTotalLength' );
123             _make_descr_accessor( 'bNumInterfaces' );
124             _make_descr_accessor( 'bConfigurationValue' );
125             _make_descr_accessor( 'iConfiguration' );
126             _make_descr_accessor( 'bmAttributes' );
127             _make_descr_accessor( 'MaxPower' );
128              
129              
130             =head1 DIAGNOSTICS
131              
132             This is an explanation of the diagnostic and error messages this module
133             can generate.
134              
135             =head1 DEPENDENCIES
136              
137             This module depends on the Carp, Inline and Inline::C modules, as well as
138             the strict and warnings pragmas. Obviously, libusb must be available since
139             that is the entire reason for the module's existence.
140              
141             =head1 AUTHOR
142              
143             G. Wade Johnson (gwadej at cpan dot org)
144             Paul Archer (paul at paularcher dot org)
145              
146             Houston Perl Mongers Group
147              
148             =head1 BUGS
149              
150             Please report any bugs or feature requests to
151             C, or through the web interface at
152             L.
153             I will be notified, and then you'll automatically be notified of progress on
154             your bug as I make changes.
155              
156             =head1 ACKNOWLEDGEMENTS
157              
158             Thanks go to various members of the Houston Perl Mongers group for input
159             on the module. But thanks mostly go to Paul Archer who proposed the project
160             and helped with the development.
161              
162             =head1 COPYRIGHT & LICENSE
163              
164             Copyright 2006-2013 Houston Perl Mongers
165              
166             This program is free software; you can redistribute it and/or modify it
167             under the same terms as Perl itself.
168              
169             =cut
170              
171             1;