Layout/LineSection.pm untested

filter: Statementstmt 0.0% 0 / 80 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 20 Podpod 0.0% 0 / 15 totaltotal 0.0% 0 / 117 CC 2 SCAR 8.7
CC
2
Cov
0%
_add_track
6.0
new
2.0
_init_V_or_H
2.0
CRAP 2.4
1 #_{ Encoding and name
2 =encoding utf8
3 =head1 NAME
4 Grid::Layout::LineSection
5 =cut
6 #_}
7 package Grid::Layout::LineSection;
8 #_{ use …
9 use warnings;
10 use strict;
11 use utf8;
12  
13 use Carp;
14  
15 use Grid::Layout;
16  
17 #_}
18 our $VERSION = $Grid::Layout::VERSION;
19 #_{ Synopsis
20  
21 =head1 SYNOPSIS
22  
23 C<< Grid::Layout::LineSection >>
24  
25 =cut
26 #_}
27 #_{ Description
28  
29 =head1 DESCRIPTION
30  
31 Except for those C<< Grid::Layout::LineSection >>s that make up the border of the entire Grid, each LineSection lies between
32 two adjacent L<< Grid::Layout::Cell >>s.
33  
34 A L<< Grid::Layout::Line >> is made up of C<< Grid::Layout::Line >>s
35  
36 =cut
37 #_}
38 #_{ Methods
39 #_{ POD
40 =head1 METHODS
41 =cut
42 #_}
43 sub new { #_{
44 #_{ POD
45 =head2 new
46  
47  
48 =cut
49 #_}
50  
51  
52 my $class = shift;
53 # my $grid_line = shift;
54  
55 # croak 'Grid::Layout required' unless $grid_layout->isa('Grid::Layout');
56  
57 my $self = {};
58  
59 # $self->{grid_layout} = $grid_layout;
60  
61 bless $self, $class;
62  
63  
64 } #_}
65 sub _init_V_or_H { #_{
66 #_{ POD
67 =head2 _init_V_or_H
68  
69 $self->_init_V_or_H('V');
70 $self->_init_V_or_H('H');
71  
72 This method is called by L</new> twice to initialize the vertical and the horizontal components of the layout.
73  
74 The parameter C<'V'> or C<'H'> indiciates which componenents to initialize.
75  
76 =cut
77 #_}
78  
79 my $self = shift;
80 my $V_or_H = shift;
81  
82 $self->{$V_or_H}{tracks} = [];
83 $self->{$V_or_H}{lines } = [];
84  
85 } #_}
86 sub add_vertical_track { #_{
87 #_{ POD
88 =head2 add_vertical_track
89  
90 =cut
91 #_}
92 my $self = shift;
93  
94  
95 my $x = $self->size_x();
96 for my $y (0 .. $self->size_y() -1) {
97 $self->_add_cell($x, $y);
98 }
99  
100 return $self->_add_track('V');
101  
102 } #_}
103 sub add_horizontal_track { #_{
104 #_{ POD
105 =head2 add_horizontal_track
106  
107 =cut
108 #_}
109 my $self = shift;
110  
111 my $y = $self->size_y;
112 for my $x (0 .. $self->size_x()-1) {
113 $self->_add_cell($x, $y);
114 }
115  
116 return $self->_add_track('H');
117  
118 } #_}
119 sub _add_track { #_{
120 #_{ POD
121 =head2 _add_track
122  
123 =cut
124 #_}
125  
126 my $self = shift;
127 my $V_or_H = shift;
128  
129 my $new_track = Grid::Layout::Track->new($self, $V_or_H, scalar @{$self->{$V_or_H}->{tracks}});
130  
131 $self->_add_line($V_or_H) unless @{$self->{$V_or_H}->{tracks}}; # An extra line (the first one) needs to be added for the first vertical and horizontal track.
132 $self->_add_line($V_or_H);
133  
134 push @{$self->{$V_or_H}{tracks}}, $new_track;
135  
136 return $new_track;
137  
138 } #_}
139 sub _add_line { #_{
140 #_{ POD
141 =head2 _add_line
142  
143 $self->_add_line($V_or_H);
144  
145 Internal function, called by L</_add_track>, to add a vertical or horizontal L<< Grid::Layout::Line >>.
146  
147 =cut
148 #_}
149  
150 my $self = shift;
151 my $V_or_H = shift;
152  
153 push @{$self->{$V_or_H}->{lines}}, Grid::Layout::Line->new($self);
154  
155 } #_}
156 sub size_x { #_{
157 #_{ POD
158 =head2 size_x
159  
160 my $x = $gl->size_x();
161  
162 Returns the horizontal size (x axis) in logical cell units.
163  
164 =cut
165 #_}
166 my $self = shift;
167 return scalar @{$self->{'V'}{tracks}};
168 } #_}
169 sub size_y { #_{
170 #_{ POD
171 =head2 size_y
172  
173 my $y = $gl->size_y();
174  
175 Returns the vertical size (y axis) in logical cell units.
176  
177 =cut
178 #_}
179 my $self = shift;
180 return scalar @{$self->{'H'}{tracks}};
181 } #_}
182 sub size { #_{
183 #_{ POD
184 =head2 size
185  
186 Returns size of grid (nof vertical tracks x nof horizontal tracks);
187  
188 my ($v, $h) = $gl -> size();
189  
190 =cut
191 #_}
192  
193 my $self = shift;
194  
195 return ($self->size_x, $self->size_y);
196 } #_}
197 sub _size { #_{
198 #_{ POD
199 =head2 _size
200  
201 Internal use.
202  
203  
204 =cut
205 #_}
206  
207 my $self = shift;
208 my $V_or_H = shift;
209  
210 return scalar @{$self->{$V_or_H}{tracks}},
211  
212 } #_}
213 sub cell { #_{
214 #_{ POD
215 =head2 cell
216  
217 my $cell = $gl->cell($v, $x);
218  
219 Return the L<< Grid::Layout::Cell >> at horizontal position C<$x> and vertical position C<$y>.
220  
221 =cut
222 #_}
223  
224 my $self = shift;
225 my $x = shift;
226 my $y = shift;
227  
228 return $self->{cells}->[$x][$y];
229  
230 } #_}
231 sub _add_cell { #_{
232 #_{ POD
233 =head2 _add_cell
234  
235 Internal use.
236  
237 =cut
238 #_}
239  
240 my $self = shift;
241 my $x = shift;
242 my $y = shift;
243  
244 $self->{cells}->[$x][$y] = Grid::Layout::Cell->new($self);
245  
246 } #_}
247 sub line_x { #_{
248 #_{ POD
249 =head2 line_x
250  
251 my $line = $gl->line_x($postition);
252  
253 Returns the C<< $position >>th line in horizontal direction.
254  
255 =cut
256 #_}
257  
258 my $self = shift;
259 my $position = shift;
260 return $self->_line('V', $position);
261  
262 } #_}
263 sub line_y { #_{
264 #_{ POD
265 =head2 line_y
266  
267 my $line = $gl->line_y($postition);
268  
269 Returns the C<< $position >>th line in vertical direction.
270  
271 =cut
272 #_}
273  
274 my $self = shift;
275 my $position = shift;
276  
277 return $self->_line('H', $position);
278  
279 } #_}
280 sub _line { #_{
281 #_{ POD
282 =head2 _line
283  
284 my $line = $gl->_line($V_or_H, $position)
285  
286 Returns the C<< $position >>th line in vertical or horizontal direction.
287  
288 =cut
289 #_}
290  
291 my $self = shift;
292 my $V_or_H = shift;
293 my $position = shift;
294  
295 return ${$self->{$V_or_H}->{lines}}[$position];
296  
297 } #_}
298 #_}
299 #_{ POD: Copyright
300  
301 =head1 Copyright
302  
303 Copyright © 2017 René Nyffenegger, Switzerland. All rights reserved.
304 This program is free software; you can redistribute it and/or modify it
305 under the terms of the the Artistic License (2.0). You may obtain a
306 copy of the full license at: L<http://www.perlfoundation.org/artistic_license_2_0>
307  
308 =cut
309  
310 #_}
311  
312 'tq84';
313