lib/TUI/ColorSel/ColorDisplay.pm

filter: Statementstmt 41.2% 61 / 148 Branchbran 0.0% 0 / 28 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 56.6% 17 / 30 Podpod 63.6% 7 / 11 totaltotal 39.1% 85 / 217 CC 16 SCAR 24.8
CC
16
Cov
35%
handleEvent
45.5
build
20.0
BUILD
12.0
CRAP 12.0
« lib/TUI/Dialogs/Util.pm ↑ Summary lib/TUI/ColorSel/ColorDialog.pm »
1 package TUI::ColorSel::ColorDisplay;
2 # ABSTRACT: color preview view for the color selection dialog
3
4 6 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7
8 6 our $VERSION = '2.000003';
9 6 $VERSION =~ tr/_//d;
10 6 our $AUTHORITY = 'cpan:BRICKPOOL';
11
12 6 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
13 6 our @EXPORT = qw(
14 TColorDisplay
15 new_TColorDisplay
16 );
17
18 6 ▶use Storable;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 6 ▶use TUI::toolkit;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 6 ▶use TUI::toolkit::Types qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
21 :is
22 :types
23 6 );
24
25 6 ▶use TUI::Drivers::Const qw( evBroadcast );
Subroutine BEGIN: called CC=1 SCAR=0.0
26 6 ▶use TUI::Drivers::ColorAttr;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 6 ▶use TUI::Objects::Rect;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 6 ▶use TUI::ColorSel::Const qw( :cmXXXX );
Subroutine BEGIN: called CC=1 SCAR=0.0
29 6 ▶use TUI::Views::DrawBuffer;
Subroutine BEGIN: called CC=1 SCAR=0.0
30 6 ▶use TUI::Views::View;
Subroutine BEGIN: called CC=1 SCAR=0.0
31 6 ▶use TUI::Views::Util qw( message );
Subroutine BEGIN: called CC=1 SCAR=0.0
32
33 sub TColorDisplay() { __PACKAGE__ }
34 sub name() { 'TColorDisplay' }
35 0 ▶sub new_TColorDisplay { __PACKAGE__->from(@_) }
Subroutine new_TColorDisplay: not called CC=1 SCAR=6.9
Pod documented
36
37 6 extends TView;
38
39 # import global variables
40 6 ▶use vars qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
41 $errorAttr
42 6 );
43 {
44 6 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
45 6 *errorAttr = \${ TView . '::errorAttr' };
46 }
47
48 # protected attributes
49 0 ▶has color => ( is => 'ro', default => sub { my $color = 0; \$color } );
Subroutine __ANON__: not called CC=1 SCAR=2.6
50 0 ▶has text => ( is => 'ro', default => sub { die 'required' } );
Subroutine __ANON__: not called CC=1 SCAR=1.2
51
52 0 ▶sub BUILDARGS { # \%args (%args)
Subroutine BUILDARGS: not called CC=1 SCAR=6.9
Pod documented
53 0 state $sig = signature(
54 method => 1,
55 named => [
56 bounds => Object,
57 text => Str, { alias => 'aText' },
58 ],
59 caller_level => +1,
60 );
61 0 my ( $class, $args ) = $sig->( @_ );
62 0 return { %$args };
63 }
64
65 0 ▶sub BUILD { # void (\%args)
Subroutine BUILD: not called CC=3 SCAR=24.8
Pod documented
66 0 my ( $self, $args ) = @_;
67 0 ▶ assert ( @_ == 2 );
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 2 0 0 0
68 0 ▶ assert ( is_Object $self );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_Object($self) 0 0 0
69 0 $self->{eventMask} |= evBroadcast;
70 0 return;
71 }
72
73 0 ▶sub from { # $obj ($bounds, $aText)
Subroutine from: not called CC=1 SCAR=6.9
Pod undocumented
74 0 state $sig = signature(
75 method => 1,
76 pos => [Object, Str],
77 );
78 0 my ( $class, @args ) = $sig->( @_ );
79 0 return $class->new( bounds => $args[0], text => $args[1] );
80 }
81
82 0 ▶sub DEMOLISH { # void ($in_global_destruction)
Subroutine DEMOLISH: not called CC=3 SCAR=24.8
Pod documented
83 0 my ( $self, $in_global_destruction ) = @_;
84 0 ▶ assert ( @_ == 2 );
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 2 0 0 0
85 0 ▶ assert ( is_Object $self );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_Object($self) 0 0 0
86 0 $self->{text} = undef;
87 0 return;
88 }
89
90 0 ▶sub draw { # void ()
Subroutine draw: not called CC=3 SCAR=24.8
Pod documented
91 0 state $sig = signature(
92 method => Object,
93 pos => [],
94 );
95 0 my ( $self ) = $sig->( @_ );
96 0 my $c = 0 + ${ $self->{color} };
97 0 my $b = TDrawBuffer->new();
98 0 ▶ $c = $errorAttr
Branch: 1 branch
BranchTrueFalseTotal
if $c == 0 0 0 0
99 if $c == 0;
100 0 my $len = length( $self->{text} );
101 0 ▶ for ( my $i = 0; $i <= int( $self->{size}{x} / $len ); $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= int $self->{"size"}{"x"} / $len) 0 0 0
102 0 $b->moveStr( $i * $len, $self->{text}, $c );
103 }
104 0 $self->writeLine( 0, 0, $self->{size}{x}, $self->{size}{y}, $b );
105 0 return;
106 }
107
108 0 ▶sub handleEvent { # void ($event)
Subroutine handleEvent: not called CC=7 SCAR=38.2
Pod documented
109 6 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
110 0 state $sig = signature(
111 method => Object,
112 pos => [Object],
113 );
114 0 my ( $self, $event ) = $sig->( @_ );
115 0 $self->SUPER::handleEvent( $event );
116 0 ▶ if ( $event->{what} == evBroadcast ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($event->{"what"} == 512) 0 0 0
117 0 SWITCH: for ( $event->{message}{command} ) {
118 0 ▶ cmColorBackgroundChanged == $_ and do {
Branch: 1 branch
BranchTrueFalseTotal
72 == $_ and do { if (ref ${$self->{"color"};}) { ${$$self{"color"};}->setBackground($event->{"message"}{"infoByte"} & 15); } else { ${$$self{"color"};} = ${$self->{"color"};} & 15 | ($event->{"message"}{"infoByte"} & 15) << 4; } ; $self->drawView; last } 0 0 0
119 0 ▶ if ( ref ${ $self->{color} } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref ${$self->{'color'};}) { } 0 0 0
120 0 ${ $self->{color} }->setBackground(
121 0 $event->{message}{infoByte} & 0xf
122 );
123 }
124 else {
125 0 ${ $self->{color} } = ( ${ $self->{color} } & 0x0f )
126 0 | ( ( $event->{message}{infoByte} & 0xf ) << 4 );
127 }
128 0 $self->drawView();
129 0 last;
130 };
131 0 ▶ cmColorForegroundChanged == $_ and do {
Branch: 1 branch
BranchTrueFalseTotal
71 == $_ and do { if (ref ${$self->{"color"};}) { ${$$self{"color"};}->setForeground($event->{"message"}{"infoByte"} & 15); } else { ${$$self{"color"};} = ${$self->{"color"};} & 240 | $event->{"message"}{"infoByte"} & 15; } ; $self->drawView; last } 0 0 0
132 0 ▶ if ( ref ${ $self->{color} } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref ${$self->{'color'};}) { } 0 0 0
133 0 ${ $self->{color} }->setForeground(
134 0 $event->{message}{infoByte} & 0xf
135 );
136 }
137 else {
138 0 ${ $self->{color} } = ( ${ $self->{color} } & 0xf0 )
139 0 | ( $event->{message}{infoByte} & 0xf );
140 }
141 0 $self->drawView();
142 0 last;
143 };
144 }
145 }
146 0 return;
147 }
148
149 0 ▶sub setColor { # void (\$aColor)
Subroutine setColor: not called CC=1 SCAR=6.9
Pod documented
150 0 state $sig = signature(
151 method => Object,
152 pos => [ScalarRef],
153 );
154 0 my ( $self, $aColor ) = $sig->( @_ );
155 0 $self->{color} = $aColor;
156 0 message( $self->{owner}, evBroadcast, cmColorSet, 0 + $$aColor );
157 0 $self->drawView();
158 0 return;
159 }
160
161 0 ▶sub write :method { # void ($os)
Subroutine write: not called CC=1 SCAR=6.9
Pod undocumented
162 0 state $sig = signature(
163 method => Object,
164 pos => [Object],
165 );
166 0 my ( $self, $os ) = $sig->( @_ );
167 0 $self->SUPER::write( $os );
168 0 $os->put( $self->{text} );
169 0 return;
170 }
171
172 0 ▶sub read :method { # $self ($is)
Subroutine read: not called CC=1 SCAR=6.9
Pod undocumented
173 0 state $sig = signature(
174 method => Object,
175 pos => [Object],
176 );
177 0 my ( $self, $is ) = $sig->( @_ );
178 0 $self->SUPER::read( $is );
179 0 $self->{text} = $is->get();
180 0 my $color = 0;
181 0 $self->{color} = \$color;
182 0 return $self;
183 }
184
185 0 ▶sub build { # $obj ()
Subroutine build: not called CC=4 SCAR=30.0
Pod undocumented
186 0 my ( $class ) = @_;
187 0 ▶ assert ( @_ == 1 );
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 1 0 0 0
188 0 ▶ assert ( is_Str $class );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_Str($class) 0 0 0
189 0 ▶ assert ( Storable::is_retrieving );
Branch: 1 branch
BranchTrueFalseTotal
unless &Storable::is_retrieving() 0 0 0
190 0 return $class->new(
191 bounds => TRect->new(),
192 text => '',
193 );
194 }
195
196 6 1
197
198 __END__
« lib/TUI/Dialogs/Util.pm ↑ Summary lib/TUI/ColorSel/ColorDialog.pm »