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