lib/TUI/Drivers/AttrPair.pm

filter: Statementstmt 83.3% 65 / 78 Branchbran 72.2% 13 / 18 Conditioncond 47.6% 10 / 21 MC/DCmcdc 14.2% 2 / 14 Subroutinesub 86.6% 13 / 15 Podpod 100% 6 / 6 totaltotal 71.7% 109 / 152 CC 17 SCAR 20.5
CC
17
Cov
75%
new
16.2
setLo
3.2
__ANON__
2.1
CRAP 7.8
« lib/TUI/StdDlg/FindFirstRec/Unix.pm ↑ Summary lib/TUI/toolkit.pm »
1 package TUI::Drivers::AttrPair;
2 # ABSTRACT: pair of color attributes value type
3
4 105 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 105 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 105 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7
8 105 our $VERSION = '2.000002';
9 105 $VERSION =~ tr/_//d;
10 105 our $AUTHORITY = 'cpan:BRICKPOOL';
11
12 105 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
13 105 our @EXPORT = qw(
14 TAttrPair
15 );
16
17 105 ▶use PerlX::Assert::PP;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 105 ▶use Scalar::Util qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
19 blessed
20 looks_like_number
21 105 );
22
23 105 ▶use TUI::Drivers::ColorAttr;
Subroutine BEGIN: called CC=1 SCAR=0.0
24
25 sub TAttrPair() { __PACKAGE__ }
26
27 # macro for coercing a value into a TColorAttr object
28 1 ▶my $coerceAttr = sub {
Subroutine __ANON__: called CC=2 SCAR=7.6
29 1 ▶ return ref $_[0] ? $_[0] : TColorAttr->new( bios => $_[0] );
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 1 0 1
30 105 };
31
32 # TAttrPair can be used as a 2-element array ([0]: low, [1]: high).
33 # Instead of the operator '@{}' Perl's internal array reference access is
34 # used, since it is resolved at compile time.
35
36 12 ▶sub new { # $obj (|%args)
Subroutine new: called CC=13 SCAR=27.8
Pod documented
37 12 my ( $class, @args ) = @_;
38 12 ▶ assert ( $class and !ref $class );
Condition33%1/3
$class && !ref($class)
!ll&&!rl&&r
0012
MC/DC0%0/2
$class && !ref($class)
$class !ref($class)
Truth table33%1/3
A && not(B)
A= $classB= !ref($class)
ABresult
0X0
100
111
39
40 12 my ( $lo, $hi );
41
42 # TAttrPair->new()
43 12 ▶ if ( !@args ) {
Branch: 3 branches
BranchTrueFalseTotal
if (not @args) { } 3 9 12
elsif (@args == 2 and $args[0] eq 'bios') { } 4 5 9
elsif (@args % 2 == 0) { } 5 0 5
44 3 $lo = TColorAttr->new();
45 3 $hi = TColorAttr->new();
46 }
47
48 # TAttrPair->new( bios => Int )
49 ▶ elsif ( @args == 2 && $args[0] eq 'bios' ) {
Condition100%3/3
@args == 2 and $args[0] eq "bios"
!ll&&!rl&&r
324
MC/DC100%2/2
@args == 2 and $args[0] eq "bios"
@args == 2 $args[0] eq "bios"
Truth table100%3/3
A and B
A= @args == 2B= $args[0] eq "bios"
ABresult
0X0
100
111
50 4 my $bios = $args[1];
51 4 assert ( looks_like_number $bios );
52 4 $lo = TColorAttr->new( bios => $bios );
53 4 $hi = TColorAttr->new( bios => $bios >> 8 );
54 }
55
56 # TAttrPair->new( lo => TColorAttr, | hi => TColorAttr )
57 elsif ( @args % 2 == 0 ) {
58 5 my %args = @args;
59 5 ▶ assert ( blessed $args{lo} or looks_like_number $args{lo} );
Condition33%1/3
builtin::blessed($args{'lo'}) || &looks_like_number($args{'lo'})
l!l&&r!l&&!r
500
MC/DC0%0/2
builtin::blessed($args{'lo'}) || &looks_like_number($args{'lo'})
builtin::blessed($args{'lo'}) &looks_like_number($args{'lo'})
Truth table33%1/3
A || B
A= builtin::blessed($args{'lo'})B= &looks_like_number($args{'lo'})
ABresult
1X1
011
000
60 5 ▶ assert ( !exists $args{hi} or defined $args{hi} );
Condition66%2/3
!exists $args{'hi'} || defined $args{'hi'}
l!l&&r!l&&!r
230
MC/DC0%0/2
!exists $args{'hi'} || defined $args{'hi'}
!exists $args{'hi'} defined $args{'hi'}
Truth table66%2/3
not(A) || B
A= !exists $args{'hi'}B= defined $args{'hi'}
ABresult
1X1
011
000
61
62 5 ▶ $lo = ref $args{lo} ? $args{lo}->clone() : $args{lo}->$coerceAttr();
Branch: 1 branch
BranchTrueFalseTotal
ref $args{'lo'} ? : 5 0 5
63 $hi = exists $args{hi}
64 5 ▶ ? ref $args{hi} ? $args{hi}->clone() : $args{hi}->$coerceAttr()
Branch: 2 branches
BranchTrueFalseTotal
exists $args{'hi'} ? : 3 2 5
ref $args{'hi'} ? : 3 0 3
65 : TColorAttr->new( bios => 0 );
66 }
67
68 else {
69 0 return;
70 }
71
72 12 ▶ assert ( blessed $lo and $lo->isa( TColorAttr ) );
Condition33%1/3
builtin::blessed($lo) && $lo->isa('TUI::Drivers::ColorAttr')
!ll&&!rl&&r
0012
MC/DC0%0/2
builtin::blessed($lo) && $lo->isa('TUI::Drivers::ColorAttr')
builtin::blessed($lo) $lo->isa('TUI::Drivers::ColorAttr')
Truth table33%1/3
A && B
A= builtin::blessed($lo)B= $lo->isa('TUI::Drivers::ColorAttr')
ABresult
0X0
100
111
73 12 ▶ assert ( blessed $hi and $hi->isa( TColorAttr ) );
Condition33%1/3
builtin::blessed($hi) && $hi->isa('TUI::Drivers::ColorAttr')
!ll&&!rl&&r
0012
MC/DC0%0/2
builtin::blessed($hi) && $hi->isa('TUI::Drivers::ColorAttr')
builtin::blessed($hi) $hi->isa('TUI::Drivers::ColorAttr')
Truth table33%1/3
A && B
A= builtin::blessed($hi)B= $hi->isa('TUI::Drivers::ColorAttr')
ABresult
0X0
100
111
74
75 12 return bless [ $lo, $hi ], $class;
76 } #/ sub new
77
78 0 ▶sub assign { # void ($other)
Subroutine assign: not called CC=1 SCAR=6.9
Pod documented
79 0 my ( $self, $other ) = @_;
80 0 assert ( blessed $self );
81 0 assert ( blessed $other );
82 0 $self->[0]->assign( $other->[0] );
83 0 $self->[1]->assign( $other->[1] );
84 0 return;
85 }
86
87 0 ▶sub clone { # $obj ()
Subroutine clone: not called CC=1 SCAR=6.9
Pod documented
88 0 my ( $self ) = @_;
89 0 assert ( blessed $self );
90 0 my $lo = $self->[0]->clone();
91 0 my $hi = $self->[1]->clone();
92 0 return bless [ $lo, $hi ], ref $self;
93 }
94
95 # Backward-compatibility functions:
96 #
97 # Return the corresponding pair of BIOS color attributes. Only works
98 # properly if both attributes are actually BIOS color attributes:
99 # see TColorAttr overload '0+'.
100
101 6 ▶sub asBIOS { # $bios ()
Subroutine asBIOS: called CC=1 SCAR=0.0
Pod documented
102 6 my ( $self ) = @_;
103 6 assert ( blessed $self );
104 6 return ( $self->[0]->asBIOS & 0xff ) | ( ( $self->[1]->asBIOS & 0xff ) << 8 );
105 }
106
107 # Used to compose attribute pairs in legacy code.
108
109 2 ▶sub rshift { # $result ($shift)
Subroutine rshift: called CC=2 SCAR=6.9
Pod documented
110 2 my ( $self, $shift ) = @_;
111 2 assert ( blessed $self );
112 2 assert ( looks_like_number $shift );
113
114 # Legacy code may use '>> 8' on an attribute pair to get the higher attribute.
115 2 ▶ return TAttrPair->new( lo => $self->[1] )
Branch: 1 branch
BranchTrueFalseTotal
if $shift == 8 1 1 2
116 if $shift == 8;
117 1 return TAttrPair->new( bios => $self->asBIOS >> $shift );
118 }
119
120 1 ▶sub setLo { # $self ($attr)
Subroutine setLo: called CC=3 SCAR=11.5
Pod documented
121 1 my ( $self, $attr ) = @_;
122 1 assert ( blessed $self );
123 1 ▶ assert ( blessed $attr or looks_like_number $attr );
Condition33%1/3
builtin::blessed($attr) || &looks_like_number($attr)
l!l&&r!l&&!r
100
MC/DC0%0/2
builtin::blessed($attr) || &looks_like_number($attr)
builtin::blessed($attr) &looks_like_number($attr)
Truth table33%1/3
A || B
A= builtin::blessed($attr)B= &looks_like_number($attr)
ABresult
1X1
011
000
124
125 # Legacy code may use '|=' on an attribute pair to set the lower attribute.
126 # However, that's only if the lower attribute is equivalent to the BIOS
127 # color attribute 0x00. Otherwise, this is just an arithmetic operation.
128 1 $attr = $coerceAttr->( $attr );
129 1 my $lo = $self->[0];
130 1 my $bios = $lo->asBIOS;
131 1 ▶ if ( $bios == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($bios == 0) { } 1 0 1
132 1 $lo->assign( $attr );
133 }
134 else {
135 0 $lo->assign( TColor->new( bios => $bios | $attr->asBIOS ) );
136 }
137 1 return $self;
138 }
139
140 use overload
141 105 ▶ '0+' => \&asBIOS,
Subroutine BEGIN: called CC=1 SCAR=0.0
142 '>>' => \&rshift,
143 '|=' => \&setLo,
144 105 fallback => 1;
145
146 105 1;
147
148 __END__
« lib/TUI/StdDlg/FindFirstRec/Unix.pm ↑ Summary lib/TUI/toolkit.pm »