Kit/Frame.pm

filter: Statementstmt 100% 46 / 46 Branchbran 100% 6 / 6 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 11 / 11 Podpod 100% 7 / 7 totaltotal 100% 75 / 75 CC 6 SCAR 6.3
CC
6
Cov
100%
known
3.0
strongest
3.0
box
2.0
CRAP 1.9
« Kit/Ticker.pm ↑ Summary Kit/Test/Handle.pm »
1 package Game::Terminal::Kit::Frame;
2  
3 5 ▶use 5.014;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 5 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 5 our $VERSION = '0.02';
9  
10 5 my @PARTS = qw/tl t tr l r bl b br/;
11  
12 5 my %LINE = (
13 light => [ split //, '┌─┐││└─┘' ],
14 double => [ split //, '╔═╗║║╚═╝' ],
15 heavy => [ split //, '┏━┓┃┃┗━┛' ],
16 );
17  
18 5 my %PLAIN = (
19 light => [ split //, '+-+||+-+' ],
20 double => [ split //, '#=#||#=#' ],
21 heavy => [ split //, '+=+||+=+' ],
22 );
23  
24 5 my @MARKS = qw/cursor from target recent plain/;
25  
26 5 my %WEIGHT = (
27 plain => 'light',
28 recent => 'double',
29 cursor => 'heavy',
30 from => 'light',
31 target => 'light',
32 );
33  
34 5 my %BRACKET = (
35 plain => [ ' ', ' ' ],
36 recent => [ '{', '}' ],
37 cursor => [ '[', ']' ],
38 from => [ '(', ')' ],
39 target => [ '<', '>' ],
40 );
41  
42 2 ▶sub marks { return @MARKS }
Subroutine marks: called CC=1 SCAR=0.0
Pod documented
43  
44 26 ▶sub parts { return @PARTS }
Subroutine parts: called CC=1 SCAR=0.0
Pod documented
45  
46 116 ▶sub known {
Subroutine known: called CC=3 SCAR=11.0
Pod documented
47 116 my ($mark) = @_;
48 116 ▶ return defined $mark && $WEIGHT{$mark} ? $mark : 'plain';
Branch: 1 branch
BranchTrueFalseTotal
defined $mark && $WEIGHT{$mark} ? : 110 6 116
Condition100%3/3
defined $mark and $WEIGHT{$mark}
!ll&&!rl&&r
24110
MC/DC100%2/2
defined $mark and $WEIGHT{$mark}
defined $mark $WEIGHT{$mark}
Truth table100%3/3
A and B
A= defined $markB= $WEIGHT{$mark}
ABresult
0X0
100
111
49 }
50  
51 89 ▶sub box {
Subroutine box: called CC=2 SCAR=6.9
Pod documented
52 89 my ($mark, $ascii) = @_;
53 89 my $weight = $WEIGHT{ known($mark) };
54 89 ▶ my $glyphs = ($ascii ? \%PLAIN : \%LINE)->{$weight};
Branch: 1 branch
BranchTrueFalseTotal
$ascii ? : 64 25 89
55 89 my %box;
56 89 @box{@PARTS} = @{$glyphs};
57 89 return \%box;
58 }
59  
60 12 ▶sub brackets {
Subroutine brackets: called CC=1 SCAR=0.0
Pod documented
61 12 my ($mark) = @_;
62 12 return @{ $BRACKET{ known($mark) } };
63 }
64  
65 7 ▶sub strongest {
Subroutine strongest: called CC=3 SCAR=11.0
Pod documented
66 7 my (@given) = @_;
67 7 my %given = map { known($_) => 1 } @given;
68 7 for my $mark (@MARKS) {
69 21 ▶ return $mark if $given{$mark};
Branch: 1 branch
BranchTrueFalseTotal
if $given{$mark} 6 15 21
70 }
71 1 return 'plain';
72 }
73  
74 8 ▶sub around {
Subroutine around: called CC=1 SCAR=0.0
Pod documented
75 8 my ($mark, $ascii, @lines) = @_;
76 8 my $box = box($mark, $ascii);
77 8 my ($width) = sort { $b <=> $a } map { length } @lines, '';
78 return (
79 $box->{tl} . ($box->{t} x $width) . $box->{tr},
80 14 (map { $box->{l} . $_ . (' ' x ($width - length)) . $box->{r} } @lines),
81 $box->{bl} . ($box->{b} x $width) . $box->{br},
82 8 );
83 }
84  
85 5 1;
86  
87 __END__
« Kit/Ticker.pm ↑ Summary Kit/Test/Handle.pm »