blib/lib/Linux/Input/Info.pm

filter: Statementstmt 73.8% 48 / 65 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 56.5% 13 / 23 Podpod 100% 10 / 10 totaltotal 71.0% 71 / 100 CC 2 SCAR 5.8
CC
2
Cov
72%
new
6.0
bustype
2.0
vendor
2.0
CRAP 1.8
↑ Summary Info.xs »
1 package Linux::Input::Info;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 require DynaLoader;
5 1 require Exporter;
6  
7 1 our @ISA = qw(Exporter DynaLoader);
8 1 our $VERSION = '0.2';
9  
10 1 ▶use constant EV_SYN => 0x00;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use constant EV_KEY => 0x01;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use constant EV_REL => 0x02;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use constant EV_ABS => 0x03;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use constant EV_MSC => 0x04;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use constant EV_LED => 0x11;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use constant EV_SND => 0x12;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use constant EV_REP => 0x14;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 ▶use constant EV_FF => 0x15;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 1 ▶use constant EV_PWR => 0x16;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 1 ▶use constant EV_FF_STATUS => 0x17;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 1 ▶use constant EV_MAX => 0x1f;
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 1 our %EV_NAME = (
24 EV_SYN , "EV_SYN",
25 EV_KEY , "EV_KEY",
26 EV_REL , "EV_REL",
27 EV_ABS , "EV_ABS",
28 EV_MSC , "EV_MSC",
29 EV_LED , "EV_LED",
30 EV_SND , "EV_SND",
31 EV_REP , "EV_REP",
32 EV_FF , "EV_FF",
33 EV_PWR , "EV_PWR",
34 EV_FF_STATUS , "EV_FF_STATUS",
35 );
36  
37  
38 1 our @EXPORT_OK = qw(EV_SYN EV_KEY EV_REL EV_ABS
39 EV_MSC EV_LED EV_SND EV_REP
40 EV_FF EV_PWR EV_FF_STATUS);
41 1 our %EXPORT_TAGS = ( all => [@EXPORT_OK] );
42  
43 =head1 NAME
44  
45 Linux::Input::Info - get information about /dev/input/event* devices under Linux
46  
47 =head1 SYNOPSIS
48  
49 use Linux::Input::Info qw(:all); # optionally export EV_* constants
50  
51 for (0..32) {
52 my $i = Linux::Input::Info->new($_);
53 printf "/dev/input/event%d\n", $_;
54  
55 printf "\tbustype : %s\n", $i->bustype;
56 printf "\tvendor : 0x%x\n", $i->vendor;
57 printf "\tproduct : 0x%x\n", $i->product;
58 printf "\tversion : %d\n", $i->version;
59 printf "\tname : %s\n", $i->name;
60 printf "\tuniq : %s\n", $i->uniq;
61 printf "\tphys : %s\n", $i->phys;
62 printf "\tbits ev :";
63 printf " %s", $i->ev_name($_) for $i->bits;
64 printf "\n";
65 }
66  
67 =head1 DESCRIPTION
68  
69 =head1 METHODS
70
71 =head2 new <event number>
72  
73 Returns undef if the device does not exist.
74  
75 =cut
76  
77 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
Pod documented
78 0 my $class = shift;
79 0 my $num = shift;
80  
81 0 my $fd = device_open($num);
82 0 ▶ return undef unless defined $fd;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $fd 0 0 0
83  
84 0 my $self = device_info($fd);
85
86 0 return bless $self, $class;
87 }
88  
89  
90  
91 =head2 bustype
92  
93 get the bus type
94  
95 =cut
96  
97 0 ▶sub bustype {
Subroutine bustype: not called CC=1 SCAR=6.9
Pod documented
98 0 return $_[0]->{bustype};
99 }
100  
101 =head2 vendor
102  
103 get vendor id
104  
105 =cut
106  
107 0 ▶sub vendor {
Subroutine vendor: not called CC=1 SCAR=6.9
Pod documented
108 0 return $_[0]->{vendor};
109 }
110  
111 =head2 product
112  
113 get the product id
114  
115 =cut
116  
117 0 ▶sub product {
Subroutine product: not called CC=1 SCAR=6.9
Pod documented
118 0 return $_[0]->{product};
119 }
120  
121 =head2 version
122  
123 get driver version
124  
125 =cut
126  
127 0 ▶sub version {
Subroutine version: not called CC=1 SCAR=6.9
Pod documented
128 0 return $_[0]->{version};
129 }
130  
131  
132 =head2 name
133  
134 get device name
135  
136 =cut
137  
138 0 ▶sub name {
Subroutine name: not called CC=1 SCAR=6.9
Pod documented
139 0 return $_[0]->{name};
140 }
141  
142  
143 =head2 uniq
144  
145 get unique identifier
146  
147 =cut
148  
149 0 ▶sub uniq {
Subroutine uniq: not called CC=1 SCAR=6.9
Pod documented
150 0 return $_[0]->{uniq};
151 }
152  
153  
154 =head2 phys
155  
156 get physical location
157  
158 =cut
159  
160 0 ▶sub phys {
Subroutine phys: not called CC=1 SCAR=6.9
Pod documented
161 0 return $_[0]->{phys};
162 }
163  
164 =head2 bits
165  
166 get event bits
167  
168 =cut
169  
170 0 ▶sub bits {
Subroutine bits: not called CC=1 SCAR=6.9
Pod documented
171 0 return @{$_[0]->{bits}};
172 }
173  
174 =head2 ev_name
175  
176 map event bit to event name
177  
178 =cut
179  
180 0 ▶sub ev_name {
Subroutine ev_name: not called CC=1 SCAR=6.9
Pod documented
181 0 my ($self, $bit) = @_;
182 0 return $EV_NAME{$bit};
183 }
184  
185 =head1 BUGS
186  
187 Make sure it doesn't leak memory.
188  
189 =head1 AUTHOR
190  
191 Simon Wistow <simon@thegestalt.org>
192  
193 =head1 COPYRIGHT
194  
195 Copyright 2005, Simon Wistow
196  
197 =head1 SEE ALSO
198  
199 L<Linux::Input>
200  
201 Gerd Knorr's input utils - http://dl.bytesex.org/cvs-snapshots/
202  
203 =cut
204  
205  
206 1 bootstrap Linux::Input::Info $VERSION;
207  
208 1 1;
209 __END__
↑ Summary Info.xs »