Choose/Opt/Mouse.pm untested

filter: Statementstmt 0.0% 0 / 63 Branchbran 0.0% 0 / 28 Conditioncond 0.0% 0 / 12 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 0.0% 0 / 5 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 117 CC 15 SCAR 52.5
CC
15
Cov
0%
__mouse_info_to_key
240.0
BEGIN
2.0
BEGIN
2.0
CRAP 189.9
1 package Term::Choose::Opt::Mouse;
2  
3 use warnings;
4 use strict;
5 use 5.10.1;
6  
7 our $VERSION = '1.783';
8  
9 use Term::Choose::Constants qw( :all );
10  
11  
12 sub __mouse_info_to_key {
13 my ( $self, $button, $mouse_x, $mouse_y ) = @_;
14 if ( $button == 4 ) {
15 return VK_PAGE_UP;
16 }
17 elsif ( $button == 5 ) {
18 return VK_PAGE_DOWN;
19 }
20 # ..._y, ..._x: absolute position, one-based index
21 my $mouse_row = $mouse_y - 1 - $self->{offset_rows};
22 my $mouse_col = $mouse_x - 1;
23 if ( $self->{margin_left} ) {
24 $mouse_col -= $self->{margin_left};
25 }
26 if ( $mouse_row < 0 || $mouse_row > $#{$self->{rc2idx}} ) {
27 return NEXT_get_key;
28 }
29 my $matched_col;
30 my $begin_this_col = 0;
31 my $row = $mouse_row + $self->{first_page_row};
32  
33 COL: for my $col ( 0 .. $#{$self->{rc2idx}[$row]} ) {
34 my $begin_next_col;
35 if ( $self->{current_layout} == -1 ) {
36 my $idx = $self->{rc2idx}[$row][$col];
37 $begin_next_col = $begin_this_col + $self->{width_elements}[$idx] + $self->{pad};
38 }
39 else {
40 $begin_next_col = $begin_this_col + $self->{col_width_plus};
41 }
42 if ( $col == 0 ) {
43 $begin_next_col -= int( $self->{pad} / 2 );
44 }
45 if ( $col == $#{$self->{rc2idx}[$row]} && $begin_next_col > $self->{avail_width} ) {
46 $begin_next_col = $self->{avail_width};
47 }
48 if ( $mouse_col >= $begin_this_col && $mouse_col < $begin_next_col ) {
49 $matched_col = $col;
50 last COL;
51 }
52 $begin_this_col = $begin_next_col;
53 }
54 if ( ! defined $matched_col ) {
55 return NEXT_get_key;
56 }
57 if ( defined $self->{skip_items} ) {
58 my $idx = $self->{rc2idx}[$row][$matched_col];
59 if ( $self->{list}[$idx] =~ /$self->{skip_items}/ ) {
60 return NEXT_get_key;
61 }
62 }
63 if ( $button == 1 ) {
64 $self->{pos}[ROW] = $row; # writes to $self
65 $self->{pos}[COL] = $matched_col; # writes to $self
66 return LINE_FEED;
67 }
68 if ( $row != $self->{pos}[ROW] || $matched_col != $self->{pos}[COL] ) {
69 my $not_pos = $self->{pos};
70 $self->{pos} = [ $row, $matched_col ]; # writes to $self
71 $self->__wr_cell( $not_pos->[0], $not_pos->[1] );
72 $self->__wr_cell( $self->{pos}[ROW], $self->{pos}[COL] );
73 }
74 if ( $button == 3 ) {
75 return KEY_SPACE;
76 }
77 else {
78 return NEXT_get_key;
79 }
80 }
81  
82  
83  
84  
85  
86  
87  
88 1;
89  
90 __END__