line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Acme::Cow::TextBalloon; |
2
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
6461
|
use strict; |
|
4
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
179
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
my $rcs_id = q$Id: TextBalloon.pm,v 1.1 2001/09/10 23:31:09 tony Exp $; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=pod |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 NAME |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
Acme::Cow::TextBalloon - A balloon of text |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 SYNOPSIS |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
use Acme::Cow::TextBalloon; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
$x = new Acme::Cow::TextBalloon; |
18
|
|
|
|
|
|
|
$x->add("bunch of text"); |
19
|
|
|
|
|
|
|
$x->wrapcolumn(29); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
$y = new Acme::Cow::TextBalloon; |
22
|
|
|
|
|
|
|
$y->adjust(0); |
23
|
|
|
|
|
|
|
$y->add("more text"); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=head1 DESCRIPTION |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
C Creates and manipulates balloons of text, |
28
|
|
|
|
|
|
|
optionally printing them. One may notice that the methods in this |
29
|
|
|
|
|
|
|
module are named very similarly to those in C; that's |
30
|
|
|
|
|
|
|
because most of them have to do with the balloon rather than the |
31
|
|
|
|
|
|
|
cow. |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=cut |
34
|
|
|
|
|
|
|
|
35
|
4
|
|
|
4
|
|
2276
|
use Text::Tabs; |
|
4
|
|
|
|
|
3376
|
|
|
4
|
|
|
|
|
478
|
|
36
|
4
|
|
|
4
|
|
1981
|
use Text::Wrap; |
|
4
|
|
|
|
|
6801
|
|
|
4
|
|
|
|
|
4106
|
|
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub new |
40
|
|
|
|
|
|
|
{ |
41
|
11
|
|
|
11
|
0
|
153
|
my $proto = shift; |
42
|
11
|
|
33
|
|
|
45
|
my $class = ref $proto || $proto; |
43
|
11
|
|
|
|
|
56
|
my $self = { |
44
|
|
|
|
|
|
|
fill => 1, |
45
|
|
|
|
|
|
|
mode => 'say', |
46
|
|
|
|
|
|
|
over => 0, |
47
|
|
|
|
|
|
|
text => [ ], |
48
|
|
|
|
|
|
|
wrap => 40, |
49
|
|
|
|
|
|
|
}; |
50
|
11
|
|
|
|
|
36
|
return bless $self, $class; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub wrapcolumn |
54
|
|
|
|
|
|
|
{ |
55
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
56
|
0
|
0
|
|
|
|
0
|
if (@_) { |
57
|
0
|
|
|
|
|
0
|
$self->{'wrap'} = $_[0]; |
58
|
|
|
|
|
|
|
} |
59
|
0
|
|
|
|
|
0
|
return $self->{'wrap'}; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub mode |
63
|
|
|
|
|
|
|
{ |
64
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
65
|
0
|
|
|
|
|
0
|
return $self->{'mode'}; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub think |
69
|
|
|
|
|
|
|
{ |
70
|
14
|
|
|
14
|
0
|
23
|
my $self = shift; |
71
|
14
|
|
|
|
|
84
|
$self->{'mode'} = "think"; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub say |
75
|
|
|
|
|
|
|
{ |
76
|
1
|
|
|
1
|
0
|
2
|
my $self = shift; |
77
|
1
|
|
|
|
|
3
|
$self->{'mode'} = "say"; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub print |
81
|
|
|
|
|
|
|
{ |
82
|
3
|
|
|
3
|
0
|
7
|
my $self = shift; |
83
|
3
|
|
|
|
|
133
|
$self->{'mode'} = "think"; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub adjust |
87
|
|
|
|
|
|
|
{ |
88
|
2
|
|
|
2
|
0
|
5
|
my $self = shift; |
89
|
2
|
50
|
|
|
|
5
|
if (@_) { |
90
|
2
|
|
|
|
|
5
|
$self->{'fill'} = $_[0]; |
91
|
|
|
|
|
|
|
} |
92
|
2
|
|
|
|
|
3
|
return $self->{'fill'}; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub over |
96
|
|
|
|
|
|
|
{ |
97
|
2
|
|
|
2
|
0
|
4
|
my $self = shift; |
98
|
2
|
50
|
|
|
|
5
|
if (@_) { |
99
|
2
|
|
|
|
|
5
|
$self->{'over'} = $_[0]; |
100
|
|
|
|
|
|
|
} |
101
|
2
|
|
|
|
|
3
|
return $self->{'over'}; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
sub as_list |
105
|
|
|
|
|
|
|
{ |
106
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
107
|
0
|
|
|
|
|
0
|
return $self->_construct(); |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
sub as_string |
111
|
|
|
|
|
|
|
{ |
112
|
13
|
|
|
13
|
0
|
22
|
my $self = shift; |
113
|
13
|
|
|
|
|
34
|
return join('', $self->_construct()); |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
sub add |
117
|
|
|
|
|
|
|
{ |
118
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
119
|
0
|
|
|
|
|
0
|
push @{$self->{'text'}}, @_; |
|
0
|
|
|
|
|
0
|
|
120
|
0
|
|
|
|
|
0
|
return $self->{'text'}; |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
sub text |
124
|
|
|
|
|
|
|
{ |
125
|
3
|
|
|
3
|
0
|
9
|
my $self = shift; |
126
|
3
|
50
|
|
|
|
9
|
if (@_) { |
127
|
3
|
|
|
|
|
10
|
my @l = @_; |
128
|
3
|
|
|
|
|
13
|
$self->{'text'} = \@l; |
129
|
|
|
|
|
|
|
} |
130
|
3
|
|
|
|
|
7
|
return $self->{'text'}; |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
sub _maxlength |
134
|
|
|
|
|
|
|
{ |
135
|
13
|
|
|
13
|
|
26
|
my ($len, $max); |
136
|
13
|
|
|
|
|
19
|
$max = -1; |
137
|
13
|
|
|
|
|
27
|
for my $i (@_) { |
138
|
17
|
|
|
|
|
21
|
$len = length $i; |
139
|
17
|
100
|
|
|
|
67
|
$max = $len if ($len > $max); |
140
|
|
|
|
|
|
|
} |
141
|
13
|
|
|
|
|
37
|
return $max; |
142
|
|
|
|
|
|
|
} |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
sub _fill_text |
145
|
|
|
|
|
|
|
{ |
146
|
13
|
|
|
13
|
|
23
|
my $self = shift; |
147
|
13
|
|
|
|
|
18
|
for my $i (@{$self->{'text'}}) { |
|
13
|
|
|
|
|
30
|
|
148
|
17
|
|
|
|
|
71
|
$i =~ s/\s+$//; |
149
|
|
|
|
|
|
|
} |
150
|
13
|
|
|
|
|
35
|
$Text::Tabs::tabstop = 8; |
151
|
13
|
|
|
|
|
19
|
my @expanded = Text::Tabs::expand(@{$self->{'text'}}); |
|
13
|
|
|
|
|
42
|
|
152
|
13
|
100
|
|
|
|
315
|
unless ($self->{'fill'}) { |
153
|
2
|
|
|
|
|
7
|
return @expanded; |
154
|
|
|
|
|
|
|
} |
155
|
11
|
|
|
|
|
25
|
$Text::Wrap::columns = $self->{'wrap'}; |
156
|
11
|
|
|
|
|
35
|
my @filled = split("\n", Text::Wrap::wrap("", "", @expanded)); |
157
|
11
|
|
|
|
|
1871
|
$Text::Tabs::tabstop = 1; # Defeat a dumb heuristic. |
158
|
11
|
|
|
|
|
50
|
my @final = expand(@filled); |
159
|
11
|
|
|
|
|
170
|
return @final; |
160
|
|
|
|
|
|
|
} |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
sub _construct |
163
|
|
|
|
|
|
|
{ |
164
|
13
|
|
|
13
|
|
21
|
my $self = shift; |
165
|
13
|
|
|
|
|
25
|
my $mode = $self->{'mode'}; |
166
|
13
|
|
|
|
|
29
|
my @message = $self->_fill_text(); |
167
|
13
|
|
|
|
|
44
|
my $max = _maxlength(@message); |
168
|
13
|
|
|
|
|
35
|
my $max2 = $max + 2; ## border space fudge. |
169
|
13
|
|
|
|
|
23
|
my @border; ## up-left, up-right, down-left, down-right, left, right |
170
|
13
|
|
|
|
|
31
|
my @balloon_lines = (); |
171
|
13
|
|
|
|
|
38
|
my $shove = " " x $self->{'over'}; |
172
|
13
|
|
|
|
|
38
|
my $format = "$shove%s %-${max}s %s\n"; |
173
|
13
|
100
|
|
|
|
32
|
if ($mode eq think) { |
|
|
100
|
|
|
|
|
|
174
|
5
|
|
|
|
|
15
|
@border = qw[ ( ) ( ) ( ) ]; |
175
|
|
|
|
|
|
|
} elsif (@message < 2) { |
176
|
7
|
|
|
|
|
21
|
@border = qw[ < > ]; |
177
|
|
|
|
|
|
|
} else { |
178
|
1
|
|
|
|
|
4
|
@border = ( "/", "\\", "\\", "/", "|", "|" ); |
179
|
|
|
|
|
|
|
} |
180
|
|
|
|
|
|
|
push(@balloon_lines, |
181
|
|
|
|
|
|
|
"$shove " . ("_" x $max2) . "\n" , |
182
|
|
|
|
|
|
|
sprintf($format, $border[0], $message[0], $border[1]), |
183
|
|
|
|
|
|
|
(@message < 2 ? "" : |
184
|
13
|
100
|
|
|
|
135
|
map { sprintf($format, $border[4], $_, $border[5]) } |
|
3
|
100
|
|
|
|
14
|
|
185
|
|
|
|
|
|
|
@message[1 .. $#message - 1]), |
186
|
|
|
|
|
|
|
(@message < 2 ? "" : |
187
|
|
|
|
|
|
|
sprintf($format, $border[2], $message[$#message], $border[3])), |
188
|
|
|
|
|
|
|
"$shove " . ("-" x $max2) . "\n" |
189
|
|
|
|
|
|
|
); |
190
|
13
|
|
|
|
|
111
|
return @balloon_lines; |
191
|
|
|
|
|
|
|
} |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
=pod |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
=head1 AUTHOR |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
Tony Monroe Etmonroe plus perl at nog dot netE |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
=head1 SEE ALSO |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
L |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
=cut |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
1; |
207
|
|
|
|
|
|
|
__END__ |