blib/lib/App/Asciio/Boxes.pm untested

filter: Statementstmt 0.0% 0 / 209 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 0.0% 0 / 17 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 236 CC 4 SCAR 17.2
CC
4
Cov
0%
change_type
20.0
BEGIN
2.0
BEGIN
2.0
CRAP 5.6
1  
2 package App::Asciio::Boxes ;
3  
4 use strict ; use warnings ;
5 use utf8 ;
6  
7 use Clone ;
8  
9 #----------------------------------------------------------------------------------------------
10  
11 use Exporter qw( import ) ;
12  
13 use constant TOP => 0 ;
14 use constant TITLE_SEPARATOR => 1 ;
15 use constant BODY_SEPARATOR => 2 ;
16 use constant BOTTOM => 3 ;
17  
18 use constant DISPLAY => 0 ;
19 use constant NAME => 1 ;
20 use constant LEFT => 2 ;
21 use constant BODY => 3 ;
22 use constant RIGHT => 4 ;
23  
24 our @EXPORT_OK = qw(TOP TITLE_SEPARATOR BODY_SEPARATOR BOTTOM DISPLAY NAME LEFT BODY RIGHT) ;
25 our %EXPORT_TAGS = ( const => [ qw(TOP TITLE_SEPARATOR BODY_SEPARATOR BOTTOM DISPLAY NAME LEFT BODY RIGHT) ] );
26  
27 #----------------------------------------------------------------------------------------------
28  
29 {
30  
31 use Clone ;
32  
33 use Readonly ;
34  
35 my %box_types =
36 (
37 dash =>
38 [
39 [1, 'top', '.', '-', '.', 1, ],
40 [0, 'title separator', '|', '-', '|', 1, ],
41 [1, 'body separator', '| ', '|', ' |', 1, ],
42 [1, 'bottom', '\'', '-', '\'', 1, ],
43 [1, 'fill-character', '', ' ', '', 1, ],
44 ],
45 dot =>
46 [
47 [1, 'top', '.', '.', '.', 1, ],
48 [0, 'title separator', '.', '.', '.', 1, ],
49 [1, 'body separator', '. ', '.', ' .', 1, ],
50 [1, 'bottom', '.', '.', '.', 1, ],
51 [1, 'fill-character', '', ' ', '', 1, ],
52 ],
53 star =>
54 [
55 [1, 'top', '*', '*', '*', 1, ],
56 [0, 'title separator', '*', '*', '*', 1, ],
57 [1, 'body separator', '* ', '*', ' *', 1, ],
58 [1, 'bottom', '*', '*', '*', 1, ],
59 [1, 'fill-character', '', ' ', '', 1, ],
60 ],
61 unicode =>
62 [
63 [1, 'top', '╭', '─', '╮', 1, ],
64 [0, 'title separator', '│', '─', '│', 1, ],
65 [1, 'body separator', '│ ', '│', ' │', 1, ],
66 [1, 'bottom', '╰', '─', '╯', 1, ],
67 [1, 'fill-character', '', ' ', '', 1, ],
68 ],
69 unicode_with_filler_type1 =>
70 [
71 [1, 'top', '╭', '─', '╮', 1, ],
72 [0, 'title separator', '│', '─', '│', 1, ],
73 [1, 'body separator', '│ ', '│', ' │', 1, ],
74 [1, 'bottom', '╰', '─', '╯', 1, ],
75 [1, 'fill-character', '', '█', '', 1, ],
76 ],
77 unicode_with_filler_type2 =>
78 [
79 [1, 'top', '╭', '─', '╮', 1, ],
80 [0, 'title separator', '│', '─', '│', 1, ],
81 [1, 'body separator', '│ ', '│', ' │', 1, ],
82 [1, 'bottom', '╰', '─', '╯', 1, ],
83 [1, 'fill-character', '', '▒', '', 1, ],
84 ],
85 unicode_with_filler_type3 =>
86 [
87 [1, 'top', '╭', '─', '╮', 1, ],
88 [0, 'title separator', '│', '─', '│', 1, ],
89 [1, 'body separator', '│ ', '│', ' │', 1, ],
90 [1, 'bottom', '╰', '─', '╯', 1, ],
91 [1, 'fill-character', '', '░', '', 1, ],
92 ],
93 unicode_with_filler_type4 =>
94 [
95 [1, 'top', '╭', '─', '╮', 1, ],
96 [0, 'title separator', '│', '─', '│', 1, ],
97 [1, 'body separator', '│ ', '│', ' │', 1, ],
98 [1, 'bottom', '╰', '─', '╯', 1, ],
99 [1, 'fill-character', '', '▚', '', 1, ],
100 ],
101 unicode_bold =>
102 [
103 [1, 'top', '┏', '━', '┓', 1, ],
104 [0, 'title separator', '┃', '━', '┃', 1, ],
105 [1, 'body separator', '┃ ', '┃', ' ┃', 1, ],
106 [1, 'bottom', '┗', '━', '┛', 1, ],
107 [1, 'fill-character', '', ' ', '', 1, ],
108 ],
109 unicode_double_line =>
110 [
111 [1, 'top', '╔', '═', '╗', 1, ],
112 [0, 'title separator', '║', '═', '║', 1, ],
113 [1, 'body separator', '║ ', '║', ' ║', 1, ],
114 [1, 'bottom', '╚', '═', '╝', 1, ],
115 [1, 'fill-character', '', ' ', '', 1, ],
116 ],
117 unicode_hollow_dot =>
118 [
119 [1, 'top', '∘', '∘', '∘', 1, ],
120 [0, 'title separator', '∘', '∘', '∘', 1, ],
121 [1, 'body separator', '∘ ', '∘', ' ∘', 1, ],
122 [1, 'bottom', '∘', '∘', '∘', 1, ],
123 [1, 'fill-character', '', ' ', '', 1, ],
124 ],
125 unicode_math_parantheses =>
126 [
127 [1, 'top', '⎛', ' ', '⎞', 1, ],
128 [0, 'title separator', '│', '─', '│', 1, ],
129 [1, 'body separator', '⎜ ', '│', ' ⎟', 1, ],
130 [1, 'bottom', '⎝', ' ', '⎠', 1, ],
131 [1, 'fill-character', '', ' ', '', 1, ],
132 ],
133 math_parantheses =>
134 [
135 [1, 'top', '/', ' ', '\\', 1, ],
136 [0, 'title separator', '│', '─', '│', 1, ],
137 [1, 'body separator', '│ ', '│', ' │', 1, ],
138 [1, 'bottom', '\\', ' ', '/', 1, ],
139 [1, 'fill-character', '', ' ', '', 1, ],
140 ],
141 rhombus_normal =>
142 [
143 [1, 'top', ',', '\'', ',', 1, ],
144 [1, 'top-middle', ',\'', '', '\',', 1, ],
145 [1, 'middle', ':', '', ':', 1, ],
146 [1, 'middle-bottom', '\',', '', ',\'', 1, ],
147 [1, 'bottom', '\'', ',', '\'', 1, ] ,
148 [1, 'fill-character','', ' ', '', 1, ] ,
149 ],
150 rhombus_normal_with_filler_star =>
151 [
152 [1, 'top', ',', '\'', ',', 1, ],
153 [1, 'top-middle', ',\'', '', '\',', 1, ],
154 [1, 'middle', ':', '', ':', 1, ],
155 [1, 'middle-bottom', '\',', '', ',\'', 1, ],
156 [1, 'bottom', '\'', ',', '\'', 1, ] ,
157 [1, 'fill-character','', '*', '', 1, ] ,
158 ],
159 rhombus_sparseness =>
160 [
161 [1, 'top', ',', '\'', ',', 1, ],
162 [1, 'top-middle', ', ', '', ' ,', 1, ],
163 [1, 'middle', ':', '', ':', 1, ],
164 [1, 'middle-bottom', ' ,', '', ', ', 1, ],
165 [1, 'bottom', '\'', ',', '\'', 1, ] ,
166 [1, 'fill-character','', ' ', '', 1, ] ,
167 ],
168 rhombus_unicode_slash =>
169 [
170 [1, 'top', ' ', ',', ' ', 1, ],
171 [1, 'top-middle', '/', '', '\', 1, ],
172 [1, 'middle', '❬', '', '❭', 1, ],
173 [1, 'middle-bottom', '\', '', '/', 1, ],
174 [1, 'bottom', ' ', '\'', ' ', 1, ] ,
175 [1, 'fill-character','', ' ', '', 1, ] ,
176 ],
177 ellipse_normal =>
178 [
179 #~ default bottom low middle high fix single
180 [1, 'up-center-point', '-', '', '', '', '', '_', '', 1, ],
181 [1, 'down-center-point', '.', '', '', '', '', '\'', '-', 1, ],
182 [1, 'left-center-point', '|', '', '', '', '', '(', '', 1, ],
183 [1, 'rigth-center-point', '|', '', '', '', '', ')', '', 1, ],
184 [1, 'left-up-area', '/', '_', '.', '-', '\'', ':', '!', 1, ],
185 [1, 'right-up-area', '\\', '_', '.', '-', '\'', ':', '!', 1, ],
186 [1, 'left-down-area', '\\', '_', '.', '-', '\'', ':', '!', 1, ],
187 [1, 'right-down-area', '/', '_', '.', '-', '\'', ':', '!', 1, ],
188 [1, 'fill-character', ' ', '', '', '', '', '', '', 1, ],
189 ] ,
190 ellipse_normal_with_filler_star =>
191 [
192 #~ default bottom low middle high fix single
193 [1, 'up-center-point', '-', '', '', '', '', '_', '', 1, ],
194 [1, 'down-center-point', '.', '', '', '', '', '\'', '-', 1, ],
195 [1, 'left-center-point', '|', '', '', '', '', '(', '', 1, ],
196 [1, 'rigth-center-point', '|', '', '', '', '', ')', '', 1, ],
197 [1, 'left-up-area', '/', '_', '.', '-', '\'', ':', '!', 1, ],
198 [1, 'right-up-area', '\\', '_', '.', '-', '\'', ':', '!', 1, ],
199 [1, 'left-down-area', '\\', '_', '.', '-', '\'', ':', '!', 1, ],
200 [1, 'right-down-area', '/', '_', '.', '-', '\'', ':', '!', 1, ],
201 [1, 'fill-character', '*', '', '', '', '', '', '', 1, ],
202 ] ,
203 triangle_up_normal =>
204 [
205 ['top', '.', ],
206 ['middle', '/', '\\', ],
207 ['bottom', '\'', '-', '\'', ] ,
208 ] ,
209 triangle_up_dot =>
210 [
211 ['top', '.', ],
212 ['middle', '.', '.', ],
213 ['bottom', '\'', '.', '\'', ] ,
214 ] ,
215 triangle_down_normal =>
216 [
217 ['top', '.', '-', '.', ],
218 ['middle', '\\', '/', ],
219 ['bottom', '\'', ] ,
220 ] ,
221 triangle_down_dot =>
222 [
223 ['top', '.', '.', '.', ],
224 ['middle', '.', '.', ],
225 ['bottom', '\'', ] ,
226 ] ,
227 ) ;
228  
229  
230 #----------------------------------------------------------------------------------------------
231  
232 sub change_type
233 {
234 my ($self, $data, $create_undo_snapshot) = @_ ;
235  
236 $create_undo_snapshot //= 1 ;
237  
238 if(exists $box_types{$data->{TYPE}})
239 {
240 $self->create_undo_snapshot() if $create_undo_snapshot ;
241
242 my $element_type = $data->{ELEMENT}->get_box_type() ;
243
244 my $new_type = Clone::clone($box_types{$data->{TYPE}}) ;
245
246 for (my $frame_element_index = 0 ; $frame_element_index < @{$new_type} ; $frame_element_index++)
247 {
248 $new_type->[$frame_element_index][DISPLAY] = $element_type->[$frame_element_index][DISPLAY]
249 }
250
251 $data->{ELEMENT}->set_box_type($new_type) ;
252
253 $self->update_display() if $create_undo_snapshot ;
254 }
255 }
256  
257 }
258  
259 # ------------------------------------------------------------------------------
260  
261 1 ;