File Coverage

blib/lib/Linux/Input/Info.pm
Criterion Covered Total %
statement 39 56 69.6
branch 0 2 0.0
condition n/a
subroutine 13 23 56.5
pod 10 10 100.0
total 62 91 68.1


line stmt bran cond sub pod time code
1             package Linux::Input::Info;
2              
3 1     1   816 use strict;
  1         3  
  1         77  
4             require DynaLoader;
5             require Exporter;
6              
7             our @ISA = qw(Exporter DynaLoader);
8             our $VERSION = '0.2';
9              
10 1     1   6 use constant EV_SYN => 0x00;
  1         1  
  1         71  
11 1     1   5 use constant EV_KEY => 0x01;
  1         2  
  1         51  
12 1     1   5 use constant EV_REL => 0x02;
  1         2  
  1         47  
13 1     1   5 use constant EV_ABS => 0x03;
  1         2  
  1         43  
14 1     1   5 use constant EV_MSC => 0x04;
  1         2  
  1         45  
15 1     1   5 use constant EV_LED => 0x11;
  1         2  
  1         40  
16 1     1   5 use constant EV_SND => 0x12;
  1         1  
  1         46  
17 1     1   5 use constant EV_REP => 0x14;
  1         1  
  1         39  
18 1     1   5 use constant EV_FF => 0x15;
  1         3  
  1         58  
19 1     1   6 use constant EV_PWR => 0x16;
  1         1  
  1         43  
20 1     1   5 use constant EV_FF_STATUS => 0x17;
  1         1  
  1         39  
21 1     1   5 use constant EV_MAX => 0x1f;
  1         2  
  1         583  
22              
23             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             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             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
72              
73             Returns undef if the device does not exist.
74              
75             =cut
76              
77             sub new {
78 0     0 1   my $class = shift;
79 0           my $num = shift;
80              
81 0           my $fd = device_open($num);
82 0 0         return undef unless defined $fd;
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             sub bustype {
98 0     0 1   return $_[0]->{bustype};
99             }
100              
101             =head2 vendor
102              
103             get vendor id
104              
105             =cut
106              
107             sub vendor {
108 0     0 1   return $_[0]->{vendor};
109             }
110              
111             =head2 product
112              
113             get the product id
114              
115             =cut
116              
117             sub product {
118 0     0 1   return $_[0]->{product};
119             }
120              
121             =head2 version
122              
123             get driver version
124              
125             =cut
126              
127             sub version {
128 0     0 1   return $_[0]->{version};
129             }
130              
131              
132             =head2 name
133              
134             get device name
135              
136             =cut
137              
138             sub name {
139 0     0 1   return $_[0]->{name};
140             }
141              
142              
143             =head2 uniq
144              
145             get unique identifier
146              
147             =cut
148              
149             sub uniq {
150 0     0 1   return $_[0]->{uniq};
151             }
152              
153              
154             =head2 phys
155              
156             get physical location
157              
158             =cut
159              
160             sub phys {
161 0     0 1   return $_[0]->{phys};
162             }
163              
164             =head2 bits
165              
166             get event bits
167              
168             =cut
169              
170             sub bits {
171 0     0 1   return @{$_[0]->{bits}};
  0            
172             }
173              
174             =head2 ev_name
175              
176             map event bit to event name
177              
178             =cut
179              
180             sub ev_name {
181 0     0 1   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
192              
193             =head1 COPYRIGHT
194              
195             Copyright 2005, Simon Wistow
196              
197             =head1 SEE ALSO
198              
199             L
200              
201             Gerd Knorr's input utils - http://dl.bytesex.org/cvs-snapshots/
202              
203             =cut
204              
205              
206             bootstrap Linux::Input::Info $VERSION;
207              
208             1;
209             __END__