Style/Role.pm

filter: Statementstmt 22.9% 17 / 74 Branchbran 0.0% 0 / 26 Conditioncond 0.0% 0 / 10 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 44.4% 4 / 9 Podpod 100% 4 / 4 totaltotal 19.3% 25 / 129 CC 20 SCAR 35.4
CC
20
Cov
15%
border_style
72.0
list_border_styles
32.5
get_border_style
21.7
CRAP 34.5
↑ Summary Style.pm »
1 package Border::Style::Role;
2  
3 1 our $DATE = '2014-12-10'; # DATE
4 1 our $VERSION = '0.01'; # VERSION
5  
6 # currently this is still very Text::ANSITable-ish.
7  
8 1 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 with 'Term::App::Role::Attrs';
12  
13 0 ▶has border_style_args => (is => 'rw', default => sub { {} });
Subroutine __ANON__: not called CC=1 SCAR=1.2
14 1 has _all_border_styles => (is => 'rw');
15  
16 0 ▶sub get_border_char {
Subroutine get_border_char: not called CC=4 SCAR=30.0
Pod documented
17 0 my ($self, $y, $x, $n, $args) = @_;
18 0 my $bch = $self->{border_style}{chars};
19 0 ▶ $n //= 1;
Condition0%0/2
$n //= 1
l!l
00
MC/DC0%0/1
$n //= 1
$n
Truth table0%0/2
A
A= $n
Aresult
11
00
20 0 ▶ if (ref($bch) eq 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $bch eq 'CODE') { } 0 0 0
21 0 ▶ $bch->($self, y=>$y, x=>$x, n=>$n, %{$args // {}});
Condition0%0/2
$args // {}
l!l
00
MC/DC0%0/1
$args // {}
$args
Truth table0%0/2
A
A= $args
Aresult
11
00
22 } else {
23 0 $bch->[$y][$x] x $n;
24 }
25 }
26  
27 0 ▶sub border_style {
Subroutine border_style: not called CC=8 SCAR=42.8
Pod documented
28 0 my $self = shift;
29  
30 0 ▶ if (!@_) { return $self->{border_style} }
Branch: 1 branch
BranchTrueFalseTotal
unless (@_) 0 0 0
31 0 my $bs = shift;
32  
33 0 my $p2 = "";
34 0 ▶ if (!ref($bs)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $bs) 0 0 0
35 0 $p2 = " named $bs";
36 0 $bs = $self->get_border_style($bs);
37 }
38  
39 0 my $err;
40 0 ▶ if ($bs->{box_chars} && !$self->use_box_chars) {
Branch: 2 branches
BranchTrueFalseTotal
if ($bs->{'box_chars'} and not $self->use_box_chars) { } 0 0 0
elsif ($bs->{'utf8'} and not $self->use_utf8) { } 0 0 0
Condition0%0/3
$bs->{"box_chars"} and not $self->use_box_chars
!ll&&!rl&&r
000
MC/DC0%0/2
$bs->{"box_chars"} and not $self->use_box_chars
$bs->{"box_chars"} not $self->use_box_chars
Truth table0%0/3
A and not(B)
A= $bs->{"box_chars"}B= not $self->use_box_chars
ABresult
0X0
100
111
41 0 $err = "use_box_chars is set to false";
42 ▶ } elsif ($bs->{utf8} && !$self->use_utf8) {
Condition0%0/3
$bs->{"utf8"} and not $self->use_utf8
!ll&&!rl&&r
000
MC/DC0%0/2
$bs->{"utf8"} and not $self->use_utf8
$bs->{"utf8"} not $self->use_utf8
Truth table0%0/3
A and not(B)
A= $bs->{"utf8"}B= not $self->use_utf8
ABresult
0X0
100
111
43 0 $err = "use_utf8 is set to false";
44 }
45 0 ▶ die "Can't select border style$p2: $err" if $err;
Branch: 1 branch
BranchTrueFalseTotal
if $err 0 0 0
46  
47 0 $self->{border_style} = $bs;
48 }
49  
50 0 ▶sub get_border_style {
Subroutine get_border_style: not called CC=5 SCAR=30.8
Pod documented
51 0 my ($self, $bs) = @_;
52  
53 0 ▶ my $prefix = (ref($self) ? ref($self) : $self ) .
Branch: 1 branch
BranchTrueFalseTotal
ref $self ? : 0 0 0
54 '::BorderStyle'; # XXX allow override
55  
56 0 my $bss;
57 my $pkg;
58 0 ▶ if ($bs =~ s/(.+):://) {
Branch: 1 branch
BranchTrueFalseTotal
if ($bs =~ s/(.+):://) { } 0 0 0
59 0 $pkg = "$prefix\::$1";
60 0 my $pkgp = $pkg; $pkgp =~ s!::!/!g;
61 0 require "$pkgp.pm";
62 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
63 0 $bss = \%{"$pkg\::border_styles"};
64 } else {
65 #$bss = $self->list_border_styles(1);
66 0 die "Please use SubPackage::name to choose border style, ".
67 "use list_border_styles() to list available styles";
68 }
69 0 ▶ $bss->{$bs} or die "Unknown border style name '$bs'".
Branch: 2 branches
BranchTrueFalseTotal
$bss->{$bs} or die "Unknown border style name '${bs}'" . ($pkg ? " in package ${prefix}::$pkg" : "") 0 0 0
$pkg ? : 0 0 0
70 ($pkg ? " in package $prefix\::$pkg" : "");
71 0 $bss->{$bs};
72 }
73  
74 0 ▶sub list_border_styles {
Subroutine list_border_styles: not called CC=6 SCAR=34.8
Pod documented
75 0 require Module::List;
76 0 require Module::Load;
77  
78 0 my ($self, $detail) = @_;
79  
80 0 ▶ my $prefix = (ref($self) ? ref($self) : $self ) .
Branch: 1 branch
BranchTrueFalseTotal
ref $self ? : 0 0 0
81 '::BorderStyle'; # XXX allow override
82 0 my $all_bs = $self->_all_border_styles;
83  
84 0 ▶ if (!$all_bs) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($all_bs) 0 0 0
85 0 my $mods = Module::List::list_modules("$prefix\::",
86 {list_modules=>1, recurse=>1});
87 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
88 0 $all_bs = {};
89 0 for my $mod (sort keys %$mods) {
90 #$log->tracef("Loading border style module '%s' ...", $mod);
91 0 Module::Load::load($mod);
92 0 my $bs = \%{"$mod\::border_styles"};
93 0 for (keys %$bs) {
94 0 my $cutmod = $mod;
95 0 $cutmod =~ s/^\Q$prefix\E:://;
96 0 my $name = "$cutmod\::$_";
97 0 $bs->{$_}{name} = $name;
98 0 $all_bs->{$name} = $bs->{$_};
99 }
100 }
101 0 $self->_all_border_styles($all_bs);
102 }
103  
104 0 ▶ if ($detail) {
Branch: 1 branch
BranchTrueFalseTotal
if ($detail) { } 0 0 0
105 0 return $all_bs;
106 } else {
107 0 return sort keys %$all_bs;
108 }
109 }
110  
111 1 1;
112 # ABSTRACT: Role for class wanting to support border styles
113  
114 __END__
↑ Summary Style.pm »