File Coverage

blib/lib/BorderStyleBase.pm
Criterion Covered Total %
statement 22 33 66.6
branch 9 24 37.5
condition 0 6 0.0
subroutine 5 5 100.0
pod 0 3 0.0
total 36 71 50.7


line stmt bran cond sub pod time code
1             package BorderStyleBase;
2              
3             our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
4             our $DATE = '2021-02-06'; # DATE
5             our $DIST = 'BorderStyleBase'; # DIST
6             our $VERSION = '0.009'; # VERSION
7              
8 1     1   444 use strict 'subs', 'vars';
  1         2  
  1         35  
9             #use warnings;
10 1     1   6 use parent 'BorderStyleBase::Constructor';
  1         1  
  1         6  
11              
12             sub get_struct {
13 3     3 0 9 my $self_or_class = shift;
14 3 50       8 if (ref $self_or_class) {
15 3         6 \%{"$self_or_class->{orig_class}::BORDER"};
  3         14  
16             } else {
17 0         0 \%{"$self_or_class\::BORDER"};
  0         0  
18             }
19             }
20              
21             sub get_args {
22 1     1 0 9 my $self = shift;
23 1         6 $self->{args};
24             }
25              
26             sub get_border_char {
27 2     2 0 11 my ($self, $y, $x, $n, $args) = @_;
28 2 100       7 $n = 1 unless defined $n;
29              
30 2         7 my $bs_struct = $self->get_struct;
31              
32 2         5 my $c = $bs_struct->{chars}[$y][$x];
33 2 50       7 if (!defined($c)) {
34 0 0 0     0 if ($y == 4 && $x == 6) { $c = $bs_struct->{chars}[4][0] }
  0 0 0     0  
    0          
    0          
35 0         0 elsif ($y == 4 && $x == 7) { $c = $bs_struct->{chars}[4][3] }
36 0         0 elsif ($y == 6) { $c = $bs_struct->{chars}[0][$x] }
37 0         0 elsif ($y == 7) { $c = $bs_struct->{chars}[5][$x] }
38             }
39 2 50       5 return unless defined $c;
40              
41 2 50       6 if (ref $c eq 'CODE') {
42 0         0 my $c2 = $c->($self, $y, $x, $n, $args);
43 0 0       0 if (ref $c2 eq 'CODE') {
44 0         0 die "Border character ($y, $x) of style $self->{orig_class} returns coderef, ".
45             "which after called still returns a coderef";
46             }
47 0         0 return $c2;
48             } else {
49 2 100       7 $c = $c x $n if $n != 1;
50 2 50       6 $c = "\e(0$c\e(B" if $bs_struct->{box_chars};
51             }
52 2         9 $c;
53             }
54              
55             1;
56             # ABSTRACT: A suitable base class for most BorderStyle::* modules
57              
58             __END__