| 1 | package Text::Orientation; | ||||||||||||||||||||
| 2 | 1 | ▶ | use 5.006; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 3 | 1 | ▶ | use String::Multibyte; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 1 | ▶ | use Text::Orientation::StringOperation; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 1 | our $VERSION = '0.04'; | |||||||||||||||||||
| 6 | |||||||||||||||||||||
| 7 | # | ||||||||||||||||||||
| 8 | # O_O;; | ||||||||||||||||||||
| 9 | # | ||||||||||||||||||||
| 10 | |||||||||||||||||||||
| 11 | 1 | ▶ | sub new{ | ||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||
| 12 | 1 | my $pkg = shift;; | |||||||||||||||||||
| 13 | 1 | my %arg = @_; | |||||||||||||||||||
| 14 | bless { | ||||||||||||||||||||
| 15 | _TEXTREF => ref($arg{TEXT}) eq "ARRAY" ? $arg{TEXT} : [ split("\n", $arg{TEXT}) ], | ||||||||||||||||||||
| 16 | _CHARSET => $arg{CHARSET}, | ||||||||||||||||||||
| 17 | 1 | ▶ | }, $pkg; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 18 | } | ||||||||||||||||||||
| 19 | |||||||||||||||||||||
| 20 | 0 | ▶ | sub text { $_[0]->{_TEXTREF} = ref($_[1]) eq "ARRAY" ? $_[1] : [ split("\n", $_[1])] } | ||||||||||||||||||
|
Subroutine
text: not called CC=2 SCAR=17.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||
| 21 | 0 | ▶ | sub charset { $_[0]->{_CHARSET} = $_[1] } | ||||||||||||||||||
|
Subroutine
charset: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 22 | |||||||||||||||||||||
| 23 | 7 | ▶ | sub maxlen { | ||||||||||||||||||
|
Subroutine
maxlen: called CC=6 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 24 | 7 | my $maxlen = 0; | |||||||||||||||||||
| 25 | 7 | ▶ | if($_[1]){ | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 26 | 5 | my $mb = Text::Orientation::StringOperation->new($_[1]); | |||||||||||||||||||
| 27 | 5 | ▶ | for my $t (@{$_[0]}){ $maxlen = $mb->length($t) if $mb->length($t) > $maxlen } | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 28 | } | ||||||||||||||||||||
| 29 | else{ | ||||||||||||||||||||
| 30 | 2 | ▶ | for my $t (@{$_[0]}){ $maxlen = length($t) if length($t) > $maxlen } | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 31 | } | ||||||||||||||||||||
| 32 | 7 | $maxlen; | |||||||||||||||||||
| 33 | } | ||||||||||||||||||||
| 34 | |||||||||||||||||||||
| 35 | |||||||||||||||||||||
| 36 | 1 | ▶ | sub transpose { $_[0]->manip('transpose') } | ||||||||||||||||||
|
Subroutine
transpose: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 37 | 1 | ▶ | sub anti_transpose { $_[0]->manip('anti_transpose') } | ||||||||||||||||||
|
Subroutine
anti_transpose: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 38 | 2 | ▶ | sub mirror { $_[0]->manip('mirror', $_[1]) } | ||||||||||||||||||
|
Subroutine
mirror: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 39 | 3 | ▶ | sub rotate { $_[0]->manip('rotate', $_[1]) } | ||||||||||||||||||
|
Subroutine
rotate: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 40 | |||||||||||||||||||||
| 41 | 7 | ▶ | sub manip { | ||||||||||||||||||
|
Subroutine
manip: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||
| 42 | 7 | my ($pkg, $method, $options) = @_; | |||||||||||||||||||
| 43 | { | ||||||||||||||||||||
| 44 | transpose => \&_transpose, | ||||||||||||||||||||
| 45 | anti_transpose => \&_transpose, | ||||||||||||||||||||
| 46 | rotate => \&_rotate, | ||||||||||||||||||||
| 47 | mirror => \&_mirror, | ||||||||||||||||||||
| 48 | }->{$method}->( | ||||||||||||||||||||
| 49 | $pkg->{_TEXTREF}, | ||||||||||||||||||||
| 50 | $pkg->{_CHARSET}, | ||||||||||||||||||||
| 51 | { | ||||||||||||||||||||
| 52 | transpose => 1, | ||||||||||||||||||||
| 53 | anti_transpose => 2, | ||||||||||||||||||||
| 54 | 7 | ▶ | }->{$method} || $options | ||||||||||||||||||
|
Condition66%2/3
{'transpose', 1, 'anti_transpose', 2}->{$method} || $options
MC/DC0%0/2
{'transpose', 1, 'anti_transpose', 2}->{$method} || $options
{'transpose', 1, 'anti_transpose', 2}->{$method}
$options
Truth table66%2/3
A || B
A= {'transpose', 1, 'anti_transpose', 2}->{$method}B= $options
| |||||||||||||||||||||
| 55 | ); | ||||||||||||||||||||
| 56 | } | ||||||||||||||||||||
| 57 | |||||||||||||||||||||
| 58 | 2 | ▶ | sub _transpose{ | ||||||||||||||||||
|
Subroutine
_transpose: called CC=6 SCAR=17.9
| |||||||||||||||||||||
| 59 | 2 | my ($textref, $charset, $options) = @_; | |||||||||||||||||||
| 60 | 2 | my $mb = Text::Orientation::StringOperation->new($charset); | |||||||||||||||||||
| 61 | 2 | my ($core, $text, $ml); | |||||||||||||||||||
| 62 | 2 | my ($row, $col); | |||||||||||||||||||
| 63 | 2 | $ml = maxlen($textref, $charset); | |||||||||||||||||||
| 64 | 2 | for my $i (0..$#{$textref}){ | |||||||||||||||||||
| 65 | 8 | for my $k (0..$mb->length($textref->[$i])-1){ | |||||||||||||||||||
| 66 | ($row, $col) = $options == 2? | ||||||||||||||||||||
| 67 | 40 | ▶ | ($mb->length($textref->[$i])-1- $k, $#{$textref}-$i) : ($k, $i); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 68 | 40 | $core->[$row]->[$col] = $mb->substr($textref->[$i], $k, 1); | |||||||||||||||||||
| 69 | } | ||||||||||||||||||||
| 70 | } | ||||||||||||||||||||
| 71 | 2 | for my $i (0..$#{$core}){ | |||||||||||||||||||
| 72 | 10 | ▶ | $text .= join('', @{$core->[$i]}).($i!=$#{$core}?"\n":''); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 73 | } | ||||||||||||||||||||
| 74 | 2 | $text; | |||||||||||||||||||
| 75 | } | ||||||||||||||||||||
| 76 | |||||||||||||||||||||
| 77 | 4 | ▶ | sub _mirror { | ||||||||||||||||||
|
Subroutine
_mirror: called CC=3 SCAR=11.0
| |||||||||||||||||||||
| 78 | 4 | my ($textref, $charset, $options) = @_; | |||||||||||||||||||
| 79 | 4 | my $mb = Text::Orientation::StringOperation->new($charset); | |||||||||||||||||||
| 80 | 4 | my $text; | |||||||||||||||||||
| 81 | 4 | ▶ | if($options =~ /vertical/io){ | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 82 | 2 | $text = join( "\n", reverse @{$textref}), "\n"; | |||||||||||||||||||
| 83 | } | ||||||||||||||||||||
| 84 | elsif($options =~ /horizontal/io){ | ||||||||||||||||||||
| 85 | 2 | my $ml = maxlen($textref, ''); | |||||||||||||||||||
| 86 | 2 | $text = join( "\n", map { ' 'x($ml-length$_).$mb->reverse($_) } @{$textref}); | |||||||||||||||||||
| 87 | } | ||||||||||||||||||||
| 88 | 4 | $text; | |||||||||||||||||||
| 89 | } | ||||||||||||||||||||
| 90 | |||||||||||||||||||||
| 91 | 3 | ▶ | sub _rotate { | ||||||||||||||||||
|
Subroutine
_rotate: called CC=11 SCAR=24.1
| |||||||||||||||||||||
| 92 | 3 | my ($textref, $charset, $dir) = @_; | |||||||||||||||||||
| 93 | 3 | $dir %= 4; | |||||||||||||||||||
| 94 | 3 | my $mb = Text::Orientation::StringOperation->new($charset); | |||||||||||||||||||
| 95 | 3 | my ($core, $text, $ml); | |||||||||||||||||||
| 96 | 3 | $ml = maxlen($textref, $charset); | |||||||||||||||||||
| 97 | 3 | ▶ | if($dir == 1){ | ||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||
| 98 | 1 | for my $i (0..$#{$textref}){ | |||||||||||||||||||
| 99 | 4 | for my $k (0..$mb->length($textref->[$i])-1){ | |||||||||||||||||||
| 100 | 20 | $core->[$k]->[$#{$textref} - $i] = | |||||||||||||||||||
| 101 | $mb->substr($textref->[$i], $k, 1); | ||||||||||||||||||||
| 102 | } | ||||||||||||||||||||
| 103 | 4 | for my $k ($mb->length($textref->[$i])..$ml-1){ | |||||||||||||||||||
| 104 | 0 | $core->[$k]->[$#{$textref} - $i] = ' '; | |||||||||||||||||||
| 105 | } | ||||||||||||||||||||
| 106 | } | ||||||||||||||||||||
| 107 | } | ||||||||||||||||||||
| 108 | elsif($dir == 2){ | ||||||||||||||||||||
| 109 | 1 | return _mirror( | |||||||||||||||||||
| 110 | [ split "\n",_mirror($textref, $charset, 'horizontal') ], | ||||||||||||||||||||
| 111 | $charset, 'vertical' | ||||||||||||||||||||
| 112 | ); | ||||||||||||||||||||
| 113 | } | ||||||||||||||||||||
| 114 | elsif($dir == 3){ | ||||||||||||||||||||
| 115 | 1 | for my $i (0..$#{$textref}){ | |||||||||||||||||||
| 116 | 4 | for my $k (0..$mb->length($textref->[$i])-1){ | |||||||||||||||||||
| 117 | 20 | $core->[$mb->length($textref->[$i])-1 - $k]->[$i] = | |||||||||||||||||||
| 118 | $mb->substr($textref->[$i], $k, 1); | ||||||||||||||||||||
| 119 | } | ||||||||||||||||||||
| 120 | } | ||||||||||||||||||||
| 121 | } | ||||||||||||||||||||
| 122 | 2 | for my $i (0..$#{$core}){ | |||||||||||||||||||
| 123 | 10 | ▶ | $text .= join('', @{$core->[$i]}).($i!=$#{$core}?"\n":''); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 124 | } | ||||||||||||||||||||
| 125 | 2 | $text; | |||||||||||||||||||
| 126 | } | ||||||||||||||||||||
| 127 | |||||||||||||||||||||
| 128 | |||||||||||||||||||||
| 129 | # | ||||||||||||||||||||
| 130 | # PerlIO layer | ||||||||||||||||||||
| 131 | # | ||||||||||||||||||||
| 132 | |||||||||||||||||||||
| 133 | 1 | our $method; | |||||||||||||||||||
| 134 | 1 | our $param; | |||||||||||||||||||
| 135 | 1 | our $charset; | |||||||||||||||||||
| 136 | |||||||||||||||||||||
| 137 | 1 | ▶ | sub import { | ||||||||||||||||||
|
Subroutine
import: called CC=3 SCAR=11.3
| |||||||||||||||||||||
| 138 | 1 | shift; | |||||||||||||||||||
| 139 | 1 | my %arg = @_; | |||||||||||||||||||
| 140 | 1 | $method = lc $arg{method}; | |||||||||||||||||||
| 141 | 1 | ▶ | $param = $method ? lc $arg{param} : undef; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 142 | 1 | ▶ | $charset = $method ? $arg{charset} : undef; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 143 | } | ||||||||||||||||||||
| 144 | |||||||||||||||||||||
| 145 | 0 | ▶ | sub PUSHED { | ||||||||||||||||||
|
Subroutine
PUSHED: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 146 | 0 | ▶ | die "Lacking method\n" unless $method; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 147 | 0 | $_[0]->new( TEXT => undef, CHARSET => $charset ); | |||||||||||||||||||
| 148 | } | ||||||||||||||||||||
| 149 | 0 | ▶ | sub FILL { my $line = <$_[1]>; $line ? $line : "\n" } | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=1.7
Subroutine
FILL: not called CC=2 SCAR=10.1
Pod
undocumented
Branch: 1 branch
| |||||||||||||||||||||
| 150 | 0 | ▶ | sub WRITE { | ||||||||||||||||||
|
Subroutine
WRITE: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 151 | 0 | $_[0]->{_TEXT} .= $_[1]; | |||||||||||||||||||
| 152 | 0 | return length($_[1]); | |||||||||||||||||||
| 153 | } | ||||||||||||||||||||
| 154 | 0 | ▶ | sub FLUSH { | ||||||||||||||||||
|
Subroutine
FLUSH: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 155 | 0 | my ($obj,$fh) = @_; | |||||||||||||||||||
| 156 | 0 | $obj->text($obj->{_TEXT}); | |||||||||||||||||||
| 157 | 0 | ▶ | print $fh $obj->manip($method, $param) or return -1; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 158 | 0 | $obj->{_TEXT} = ''; | |||||||||||||||||||
| 159 | 0 | return 0; | |||||||||||||||||||
| 160 | } | ||||||||||||||||||||
| 161 | |||||||||||||||||||||
| 162 | |||||||||||||||||||||
| 163 | 1 | 1; | |||||||||||||||||||
| 164 | __END__ | ||||||||||||||||||||