| 1 | package Linux::Input; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 1 | $VERSION = '1.03'; | |||||||||||||||||||
| 4 | |||||||||||||||||||||
| 5 | 1 | ▶ | use base 'Class::Data::Inheritable'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 1 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | 1 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | 1 | ▶ | use Config; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | 1 | ▶ | use IO::File; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | 1 | ▶ | use IO::Select; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | # class data | ||||||||||||||||||||
| 14 | 1 | Linux::Input->mk_classdata('event_bytes'); | |||||||||||||||||||
| 15 | Linux::Input->event_bytes( | ||||||||||||||||||||
| 16 | ($Config{longsize} * 2) + # input_event.time (struct timeval) | ||||||||||||||||||||
| 17 | ($Config{i16size} * 2) + # input_event.type, input_event.code | ||||||||||||||||||||
| 18 | ($Config{i32size}) # input_event.value | ||||||||||||||||||||
| 19 | 1 | ); | |||||||||||||||||||
| 20 | 1 | Linux::Input->mk_classdata('timeout'); | |||||||||||||||||||
| 21 | 1 | Linux::Input->timeout(0.01); | |||||||||||||||||||
| 22 | |||||||||||||||||||||
| 23 | # instaniate a new input device | ||||||||||||||||||||
| 24 | 0 | ▶ | sub new { | ||||||||||||||||||
|
Subroutine
new: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||
| 25 | 0 | my $class = shift; | |||||||||||||||||||
| 26 | 0 | my $filename = shift; | |||||||||||||||||||
| 27 | 0 | my $self = { }; | |||||||||||||||||||
| 28 | 0 | bless ($self => $class); | |||||||||||||||||||
| 29 | |||||||||||||||||||||
| 30 | 0 | $self->{fh} = IO::File->new("< $filename"); | |||||||||||||||||||
| 31 | 0 | ▶ | die($!) unless ($self->{fh}); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 32 | |||||||||||||||||||||
| 33 | 0 | return $self; | |||||||||||||||||||
| 34 | } | ||||||||||||||||||||
| 35 | |||||||||||||||||||||
| 36 | # get filehandle of device | ||||||||||||||||||||
| 37 | 0 | ▶ | sub fh { | ||||||||||||||||||
|
Subroutine
fh: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 38 | 0 | my $self = shift; | |||||||||||||||||||
| 39 | 0 | return $self->{fh}; | |||||||||||||||||||
| 40 | } | ||||||||||||||||||||
| 41 | |||||||||||||||||||||
| 42 | # $self's IO::Select object | ||||||||||||||||||||
| 43 | 0 | ▶ | sub selector { | ||||||||||||||||||
|
Subroutine
selector: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||
| 44 | 0 | my $self = shift; | |||||||||||||||||||
| 45 | 0 | ▶ | unless ($self->{__io_select}) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 46 | 0 | $self->{__io_select} = IO::Select->new($self->fh()); | |||||||||||||||||||
| 47 | } | ||||||||||||||||||||
| 48 | 0 | return $self->{__io_select}; | |||||||||||||||||||
| 49 | } | ||||||||||||||||||||
| 50 | |||||||||||||||||||||
| 51 | # poll for all pending events | ||||||||||||||||||||
| 52 | 0 | ▶ | sub poll { | ||||||||||||||||||
|
Subroutine
poll: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||
| 53 | 0 | my $self = shift; | |||||||||||||||||||
| 54 | 0 | ▶ | my $timeout = shift || ref($self)->timeout(); | ||||||||||||||||||
|
Condition0%0/3
shift() || ref($self)->timeout
MC/DC0%0/2
shift() || ref($self)->timeout
shift()
ref($self)->timeout
Truth table0%0/3
A || B
A= shift()B= ref($self)->timeout
| |||||||||||||||||||||
| 55 | 0 | my $selector = $self->selector(); | |||||||||||||||||||
| 56 | 0 | my @ev; | |||||||||||||||||||
| 57 | |||||||||||||||||||||
| 58 | 0 | my $struct_len = Linux::Input->event_bytes(); | |||||||||||||||||||
| 59 | 0 | ▶ | while (my ($fh) = $selector->can_read($timeout)) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 60 | 0 | my $buffer; | |||||||||||||||||||
| 61 | 0 | my $len = sysread($fh, $buffer, $struct_len); | |||||||||||||||||||
| 62 | 0 | my ($sec, $usec, $type, $code, $value) = | |||||||||||||||||||
| 63 | unpack('L!L!S!S!i!', $buffer); | ||||||||||||||||||||
| 64 | 0 | my $event = { | |||||||||||||||||||
| 65 | tv_sec => $sec, | ||||||||||||||||||||
| 66 | tv_usec => $usec, | ||||||||||||||||||||
| 67 | type => $type, | ||||||||||||||||||||
| 68 | code => $code, | ||||||||||||||||||||
| 69 | value => $value, | ||||||||||||||||||||
| 70 | }; | ||||||||||||||||||||
| 71 | 0 | ▶ | push @ev, $event if (defined($type)); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 72 | } | ||||||||||||||||||||
| 73 | 0 | return @ev; | |||||||||||||||||||
| 74 | } | ||||||||||||||||||||
| 75 | |||||||||||||||||||||
| 76 | 1 | 1; | |||||||||||||||||||
| 77 | |||||||||||||||||||||
| 78 | __END__ | ||||||||||||||||||||