HID/Descriptor/Interface.pm

filter: Statementstmt 26.9% 14 / 52 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 26.6% 4 / 15 Podpod 100% 11 / 11 totaltotal 26.6% 29 / 109 CC 12 SCAR 19.6
CC
12
Cov
18%
convert
20.0
new
6.0
country
6.0
CRAP 7.1
« HID/Report/Field.pm ↑ Summary Descriptor.pm »
1 package USB::HID::Descriptor::Interface;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use base 'USB::Descriptor::Interface';
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 2 ▶use USB::HID::Descriptor::Class;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 2 our $VERSION = '1';
10  
11 =head1 NAME
12  
13 USB::HID::Descriptor::Interface - USB HID Interface Descriptor
14  
15 =head1 SYNOPSIS
16  
17 An object representation of a USB HID interface descriptor. Subclass of
18 L<USB::Descriptor::Interface>.
19  
20 use USB::HID::Descriptor::Interface;
21  
22 my $interface = USB::HID::Descriptor::Interface->new( description => 'My First Interface' );
23 $interface->protocol(0);
24 $interface->subclass(0);
25 $interface->endpoints( [ USB::Descriptor::Endpoint->new() ] );
26 ...
27  
28 =head1 DESCRIPTION
29  
30 L<USB::HID::Descriptor::Interface> represents a USB interface descriptor for a
31 HID class device. When added to the descriptor tree of a
32 L<USB::Descriptor::Device> object it can be used to generate the data structures
33 needed to compile the firmware for a USB device.
34  
35 =head1 CONSTRUCTOR
36  
37 =over
38  
39 =item $interface = USB::HID::Descriptor::Interface->new(description=>$description, ...);
40  
41 Constructs and returns a new L<USB::HID::Descriptor::Interface> object using the
42 passed options. Each option key is the name of an accessor method. The C<class>
43 option is overriden.
44  
45 =item $interface = USB::HID::Descriptor::Interface->convert($another_interface)
46  
47 Converts a L<USB::Descriptor::Interface> object into a
48 L<USB::HID::Descriptor::Interface> object and returns it.
49  
50 =back
51  
52 =cut
53  
54 sub new
55 0 ▶{
Subroutine new: not called CC=2 SCAR=17.9
Pod documented
56 0 my ($this, %options) = @_;
57 0 ▶ my $class = ref($this) || $this;
Condition0%0/3
ref $this || $this
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $this || $this
ref $this $this
Truth table0%0/3
A || B
A= ref $thisB= $this
ABresult
1X1
011
000
58 0 my $self = $class->SUPER::new(%options);
59  
60 # Force the interface class to HID
61 0 $self->SUPER::class(0x03);
62  
63 0 return $self;
64 }
65  
66 # Convert a USB::Descriptor::Interface object
67 sub convert
68 0 ▶{
Subroutine convert: not called CC=4 SCAR=30.0
Pod documented
69 0 my ($this, $interface) = @_;
70 0 ▶ my $class = ref($this) || $this;
Condition0%0/3
ref $this || $this
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $this || $this
ref $this $this
Truth table0%0/3
A || B
A= ref $thisB= $this
ABresult
1X1
011
000
71 0 ▶ if( ref($interface) && $interface->isa('USB::Descriptor::Interface') )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $interface and $interface->isa("USB::Descriptor::Interface")) 0 0 0
Condition0%0/3
ref $interface and $interface->isa("USB::Descriptor::Interface")
!ll&&!rl&&r
000
MC/DC0%0/2
ref $interface and $interface->isa("USB::Descriptor::Interface")
ref $interface $interface->isa("USB::Descriptor::Interface")
Truth table0%0/3
A and B
A= ref $interfaceB= $interface->isa("USB::Descriptor::Interface")
ABresult
0X0
100
111
72 {
73 0 bless $interface, $class;
74  
75 # Force the interface class to HID
76 0 $interface->SUPER::class(0x03);
77  
78 0 return $interface;
79 }
80 0 undef;
81 }
82  
83 =head1 ATTRIBUTES
84  
85 =over
86  
87 =item $interface->class
88  
89 Returns the interface's class (bInterfaceClass). No setting allowed.
90  
91 =item $interface->class_descriptor
92  
93 Returns the current class descriptor object. No setting allowed.
94  
95 =item $interface->country
96  
97 Get/Set the country code for localized hardware (bCountryCode). Defaults to 0.
98  
99 =item $class->report_bytes
100  
101 Returns an array of bytes containing the report descriptor.
102  
103 =item $interface->report
104  
105 A convenience method that wraps a single hash reference in an array and passes
106 it to C<reports()>.
107  
108 =item $interface->reports
109  
110 Get/Set the array of C<USB::HID::Descriptor::Report> objects.
111  
112 =item $interface->version
113  
114 Get/Set the HID specification release number (bcdHID). Defaults to '1.1.0'.
115  
116 =back
117  
118 =cut
119  
120 # Forward the call to the Class descriptor
121 sub country
122 0 ▶{
Subroutine country: not called CC=2 SCAR=17.9
Pod documented
123 0 my $s = shift;
124 0 ▶ $s->class_descriptor->country = shift if scalar @_;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @_ 0 0 0
125 0 $s->class_descriptor->country;
126 }
127  
128 # Override class to prevent setting
129 sub class
130 0 ▶{
Subroutine class: not called CC=1 SCAR=6.9
Pod documented
131 0 my $s = shift;
132 0 $s->SUPER::class;
133 }
134  
135 # Override class_descriptor to prevent setting
136 # Create a new default Class descriptor if one doesn't already exist
137 sub class_descriptor
138 0 ▶{
Subroutine class_descriptor: not called CC=2 SCAR=17.9
Pod documented
139 0 my $s = shift;
140 0 my $c = $s->SUPER::class_descriptor;
141 0 ▶ return $c if ref($c);
Branch: 1 branch
BranchTrueFalseTotal
if ref $c 0 0 0
142 0 $s->SUPER::class_descriptor(USB::HID::Descriptor::Class->new);
143 }
144  
145 sub report_bytes
146 0 ▶{
Subroutine report_bytes: not called CC=1 SCAR=6.9
Pod documented
147 0 my $s = shift;
148 0 $s->class_descriptor->report_bytes;
149 }
150  
151 sub report
152 0 ▶{
Subroutine report: not called CC=2 SCAR=17.9
Pod documented
153 0 my $s = shift;
154 0 ▶ $s->class_descriptor->report(@_) if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
155 0 $s->class_descriptor->report;
156 }
157  
158 # Forward the call to the Class descriptor
159 sub reports
160 0 ▶{
Subroutine reports: not called CC=2 SCAR=17.9
Pod documented
161 0 my $s = shift;
162 0 ▶ $s->class_descriptor->reports(@_) if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
163 0 $s->class_descriptor->reports;
164 }
165  
166 # Forward the call to the Class descriptor
167 sub version
168 0 ▶{
Subroutine version: not called CC=2 SCAR=17.9
Pod documented
169 0 my $s = shift;
170 0 ▶ $s->class_descriptor->version(shift) if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
171 0 $s->class_descriptor->version;
172 }
173  
174 =head1 REPORT DESCRIPTOR ATTRIBUTES
175  
176 =over
177  
178 =item $interface->page
179  
180 Get/Set the B<Usage Page> of the interface's report descriptor.
181  
182 =item $interface->usage
183  
184 Get/Set the B<Usage> of the interface's report descriptor.
185  
186 =back
187  
188 =cut
189  
190 sub page
191 0 ▶{
Subroutine page: not called CC=2 SCAR=17.9
Pod documented
192 0 my $s = shift;
193 0 ▶ $s->class_descriptor->page(@_) if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
194 0 $s->class_descriptor->page;
195 }
196  
197 sub usage
198 0 ▶{
Subroutine usage: not called CC=2 SCAR=17.9
Pod documented
199 0 my $s = shift;
200 0 ▶ $s->class_descriptor->usage(shift) if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
201 0 $s->class_descriptor->usage;
202 }
203  
204 2 1;
205  
206 =head1 AUTHOR
207  
208 Brandon Fosdick, C<< <bfoz at bfoz.net> >>
209  
210 =head1 BUGS
211  
212 Please report any bugs or feature requests to C<bug-usb-hid-descriptor-interface at rt.cpan.org>, or through
213 the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=USB-HID-Descriptor-Interface>. I will be notified, and then you'll
214 automatically be notified of progress on your bug as I make changes.
215  
216 =head1 SUPPORT
217  
218 You can find documentation for this module with the perldoc command.
219  
220 perldoc USB::HID::Descriptor::Interface
221  
222  
223 You can also look for information at:
224  
225 =over 4
226  
227 =item * RT: CPAN's request tracker (report bugs here)
228  
229 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=USB-HID-Descriptor-Interface>
230  
231 =item * AnnoCPAN: Annotated CPAN documentation
232  
233 L<http://annocpan.org/dist/USB-HID-Descriptor-Interface>
234  
235 =item * CPAN Ratings
236  
237 L<http://cpanratings.perl.org/d/USB-HID-Descriptor-Interface>
238  
239 =item * Search CPAN
240  
241 L<http://search.cpan.org/dist/USB-HID-Descriptor-Interface/>
242  
243 =back
244  
245  
246 =head1 ACKNOWLEDGEMENTS
247  
248  
249 =head1 LICENSE AND COPYRIGHT
250  
251 Copyright 2011 Brandon Fosdick.
252  
253 This program is released under the terms of the BSD License.
254  
255 =cut
« HID/Report/Field.pm ↑ Summary Descriptor.pm »