lib/App/FuguSeed/Text.pm

filter: Statementstmt 100% 60 / 60 Branchbran 100% 8 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 15 / 15 Podpod 100% 2 / 2 totaltotal 100% 85 / 85 CC 10 SCAR 8.8
CC
10
Cov
100%
grid
5.0
zones
3.0
_zone
3.0
CRAP 2.4
« blib/lib/App/FuguSeed/Sheet.pm ↑ Summary blib/lib/App/FuguSeed/ListFile.pm »
1 # ex:ts=8 sw=4:
2 # $OpenBSD$
3 #
4 # Copyright (c) 2026 Dick Olsson <hi@senzilla.io>
5 #
6 # Permission to use, copy, modify, and distribute this software for any
7 # purpose with or without fee is hereby granted, provided that the above
8 # copyright notice and this permission notice appear in all copies.
9 #
10 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17  
18 package App::FuguSeed::Text;
19 2 our $VERSION = '0.2.0';
20  
21 2 ▶use v5.34;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 2 ▶use experimental 'signatures';
Subroutine BEGIN: called CC=1 SCAR=0.0
24 2 ▶no feature qw(indirect multidimensional bareword_filehandles);
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26 # App::FuguSeed::Text - the views of a Standard SeedQR.
27 #
28 # The module renders the matrix of App::FuguSeed::Matrix as the grid
29 # view and the 25 zone views of QR-TEXT. A person draws one zone at a
30 # time, and the count of the dark modules of a zone proves the work.
31 #
32 # Every method is a class method, and every method is pure: it takes
33 # values and it returns values. The module touches no stream, and it
34 # loads no module. Each view ends with a line feed, and no line
35 # carries a trailing space.
36  
37 # DARK and LIGHT:
38 # The two characters of one module (QR-TEXT-1).
39 2 ▶use constant DARK => '#';
Subroutine BEGIN: called CC=1 SCAR=0.0
40 2 ▶use constant LIGHT => '.';
Subroutine BEGIN: called CC=1 SCAR=0.0
41  
42 # ZONE and ZONES:
43 # A zone is 5 x 5 modules, and the matrix holds 5 zones in each
44 # direction (QR-TEXT-3).
45 2 ▶use constant ZONE => 5;
Subroutine BEGIN: called CC=1 SCAR=0.0
46 2 ▶use constant ZONES => 5;
Subroutine BEGIN: called CC=1 SCAR=0.0
47  
48 # ROWS:
49 # The letter of each row of zones, from the top (QR-TEXT-3).
50 2 ▶use constant ROWS => [qw(A B C D E)];
Subroutine BEGIN: called CC=1 SCAR=0.0
51  
52 # GUTTER:
53 # The width of the label column of the grid view.
54 2 ▶use constant GUTTER => 3;
Subroutine BEGIN: called CC=1 SCAR=0.0
55  
56 # $class->grid($matrix):
57 # The grid view of QR-TEXT-2: the 25 rows, with one space
58 # between the zone columns and one empty line between the zone
59 # rows. The letters A to E and the numbers 1 to 5 label it. The
60 # view starts with one empty line, so it stands apart from the
61 # digit string.
62 2 ▶sub grid ( $, $matrix )
Subroutine grid: called CC=5 SCAR=16.1
Pod documented
63 {
64 2 my @lines = ( q{}, _header() );
65  
66 2 for my $band ( 0 .. ZONES - 1 ) {
67 10 for my $line ( 0 .. ZONE - 1 ) {
68 50 ▶ my $label =
Branch: 1 branch
BranchTrueFalseTotal
$line == 2.0 ? : 10 40 50
69 $line == ( ZONE - 1 ) / 2
70 ? ROWS->[$band]
71 : q{};
72 50 push @lines,
73 sprintf( '%-*s', GUTTER, $label )
74 . join( q{ },
75 _chunks( $matrix, $band * ZONE + $line ) );
76 }
77 10 ▶ push @lines, q{} if $band < ZONES - 1;
Branch: 1 branch
BranchTrueFalseTotal
if $band < 4 8 2 10
78 }
79  
80 2 return join( "\n", @lines ) . "\n";
81 }
82  
83 # $class->zones($matrix):
84 # The 25 zone views of QR-TEXT-4, in the order A-1 to E-5. A
85 # zone view holds the zone name, the 5 rows of the zone, and
86 # the count of the dark modules of the zone. Each view starts
87 # with one empty line.
88 2 ▶sub zones ( $class, $matrix )
Subroutine zones: called CC=3 SCAR=11.0
Pod documented
89 {
90 2 my @views;
91  
92 2 for my $band ( 0 .. ZONES - 1 ) {
93 10 for my $stack ( 0 .. ZONES - 1 ) {
94 50 push @views, $class->_zone( $matrix, $band, $stack );
95 }
96 }
97  
98 2 return @views;
99 }
100  
101 # $class->_zone($matrix, $band, $stack):
102 # The view of the zone in the row of zones $band and the column
103 # of zones $stack, both 0-based.
104 50 ▶sub _zone ( $, $matrix, $band, $stack )
Subroutine _zone: called CC=3 SCAR=11.0
105 {
106 50 my @lines = ( q{}, ROWS->[$band] . '-' . ( $stack + 1 ) );
107 50 my $dark = 0;
108  
109 50 for my $line ( 0 .. ZONE - 1 ) {
110 250 my @modules = @{ $matrix->[ $band * ZONE + $line ] }
111 [ $stack * ZONE .. $stack * ZONE + ZONE - 1 ];
112 250 $dark += grep { $_ } @modules;
113 250 ▶ push @lines, join q{}, map { $_ ? DARK : LIGHT } @modules;
Branch: 1 branch
BranchTrueFalseTotal
$_ ? : 684 566 1250
114 }
115  
116 50 push @lines, "dark $dark";
117  
118 50 return join( "\n", @lines ) . "\n";
119 }
120  
121 # _header():
122 # The label line of the zone columns. Each number sits over the
123 # middle of its zone.
124 sub _header
125 2 ▶{
Subroutine _header: called CC=1 SCAR=0.0
126 2 return ( q{ } x ( GUTTER + ( ZONE - 1 ) / 2 ) )
127 . join( q{ } x ZONE, 1 .. ZONES );
128 }
129  
130 # _chunks($matrix, $row):
131 # The row $row of the matrix as ZONES strings of ZONE
132 # characters.
133 50 ▶sub _chunks ( $matrix, $row )
Subroutine _chunks: called CC=2 SCAR=6.9
134 {
135 50 ▶ my @modules = map { $_ ? DARK : LIGHT } @{ $matrix->[$row] };
Branch: 1 branch
BranchTrueFalseTotal
$_ ? : 684 566 1250
136  
137 return
138 50 map { join q{}, @modules[ $_ * ZONE .. $_ * ZONE + ZONE - 1 ] }
139 0 .. ZONES - 1;
140 }
141  
142 2 1;
« blib/lib/App/FuguSeed/Sheet.pm ↑ Summary blib/lib/App/FuguSeed/ListFile.pm »