| 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
MC/DC0%0/1
$n //= 1
$n
Truth table0%0/2
A
A= $n
| |||||||||||||||||||||||||||||||||
| 20 | 0 | ▶ | if (ref($bch) eq 'CODE') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 21 | 0 | ▶ | $bch->($self, y=>$y, x=>$x, n=>$n, %{$args // {}}); | ||||||||||||||||||||||||||||||
|
Condition0%0/2
$args // {}
MC/DC0%0/1
$args // {}
$args
Truth table0%0/2
A
A= $args
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 31 | 0 | my $bs = shift; | |||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||
| 33 | 0 | my $p2 = ""; | |||||||||||||||||||||||||||||||
| 34 | 0 | ▶ | if (!ref($bs)) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 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
Condition0%0/3
$bs->{"box_chars"} and not $self->use_box_chars
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
| |||||||||||||||||||||||||||||||||
| 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
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
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 54 | '::BorderStyle'; # XXX allow override | ||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||
| 56 | 0 | my $bss; | |||||||||||||||||||||||||||||||
| 57 | my $pkg; | ||||||||||||||||||||||||||||||||
| 58 | 0 | ▶ | if ($bs =~ s/(.+):://) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 81 | '::BorderStyle'; # XXX allow override | ||||||||||||||||||||||||||||||||
| 82 | 0 | my $all_bs = $self->_all_border_styles; | |||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||
| 84 | 0 | ▶ | if (!$all_bs) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||||||