blib/lib/Term/Fabulous/Event/TextClick.pm untested

filter: Statementstmt 0.0% 0 / 55 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 0.0% 0 / 8 Podpod n/a totaltotal 0.0% 0 / 82 CC 1 SCAR 6.9
CC
1
Cov
0%
BEGIN
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 package Term::Fabulous::Event::TextClick;
2  
3 use v5.32;
4 use warnings;
5 use feature 'signatures';
6 no warnings 'experimental::signatures';
7  
8 our $VERSION = '0.05';
9  
10 use Object::Pad 0.825;
11  
12 use Clay::UI::Events::Event;
13  
14 class Term::Fabulous::Event::TextClick :isa(Clay::UI::Events::Event) :strict(params) {
15 use Term::Fabulous::Check qw(describe non_negative_integer);
16 use Term::Fabulous::Termbox qw(TB_KEY_MOUSE_LEFT TB_KEY_MOUSE_MIDDLE TB_KEY_MOUSE_RIGHT);
17  
18 my %IS_BUTTON = map { $_ => 1 } TB_KEY_MOUSE_LEFT, TB_KEY_MOUSE_MIDDLE, TB_KEY_MOUSE_RIGHT;
19  
20 field $button :param :reader;
21 field $x :param :reader;
22 field $y :param :reader;
23 field $offset :param :reader;
24 field $word :param :reader = undef;
25 field $word_start :param :reader = undef;
26 field $word_end :param :reader = undef;
27 field $spans :param = [];
28 field $link :param :reader = undef;
29 field $link_index :param :reader = undef;
30  
31 ADJUST {
32 die "Term::Fabulous::Event::TextClick: button must be TB_KEY_MOUSE_LEFT, TB_KEY_MOUSE_MIDDLE or TB_KEY_MOUSE_RIGHT, got " . describe($button)
33 unless defined $button && !ref $button && $IS_BUTTON{$button};
34 $x = non_negative_integer( $self, x => $x );
35 $y = non_negative_integer( $self, y => $y );
36 $offset = non_negative_integer( $self, offset => $offset );
37 die "Term::Fabulous::Event::TextClick: word, word_start and word_end are given together or not at all"
38 unless ( grep { defined } $word, $word_start, $word_end ) % 3 == 0;
39 die "Term::Fabulous::Event::TextClick: spans must be an array reference, got " . describe($spans) unless ref $spans eq 'ARRAY';
40 die "Term::Fabulous::Event::TextClick: link and link_index are given together or not at all" unless defined $link == defined $link_index;
41 $link_index = non_negative_integer( $self, link_index => $link_index ) if defined $link_index;
42 }
43  
44 method event_name :common () {
45 return 'TextClick';
46 }
47  
48 method spans () {
49 return [ map { [ $_->[0], $_->[1], { %{ $_->[2] } } ] } @$spans ];
50 }
51 }
52  
53 1;
54  
55 __END__