line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Acme::Cow; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
11335
|
use strict; |
|
3
|
|
|
|
|
18
|
|
|
3
|
|
|
|
|
204
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
$Acme::Cow::VERSION = '0.2'; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
# Preloaded methods go here. |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
# Autoload methods go after =cut, and are processed by the autosplit program. |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
# Below is stub documentation for your module. You better edit it! |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 NAME |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
Acme::Cow - Talking barnyard animals (or ASCII art in general) |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 SYNOPSIS |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
use Acme::Cow; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
$cow = new Acme::Cow; |
22
|
|
|
|
|
|
|
$cow->say("Moo!"); |
23
|
|
|
|
|
|
|
$cow->print(); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
$sheep = new Acme::Cow::Sheep; # Derived from Acme::Cow |
26
|
|
|
|
|
|
|
$sheep->wrap(20); |
27
|
|
|
|
|
|
|
$sheep->think(); |
28
|
|
|
|
|
|
|
$sheep->text("Yeah, but you're taking the universe out of context."); |
29
|
|
|
|
|
|
|
$sheep->print(\*STDERR); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
$duck = new Acme::Cow(File => "duck.cow"); |
32
|
|
|
|
|
|
|
$duck->fill(0); |
33
|
|
|
|
|
|
|
$duck->say(`figlet quack`); |
34
|
|
|
|
|
|
|
$duck->print($socket); |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=head1 DESCRIPTION |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
Acme::Cow is the logical evolution of the old cowsay program. Cows |
40
|
|
|
|
|
|
|
are derived from a base class (Acme::Cow) or from external files. |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
Cows can be made to say or think many things, optionally filling |
43
|
|
|
|
|
|
|
and justifying their text out to a given margin, |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
Cows are nothing without the ability to print them, or sling them |
46
|
|
|
|
|
|
|
as strings, or what not. |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=cut |
49
|
|
|
|
|
|
|
|
50
|
3
|
|
|
3
|
|
1349
|
use Acme::Cow::TextBalloon; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
91
|
|
51
|
3
|
|
|
3
|
|
1516
|
use IO::File; |
|
3
|
|
|
|
|
27039
|
|
|
3
|
|
|
|
|
308
|
|
52
|
3
|
|
|
3
|
|
2260
|
use Text::Template; |
|
3
|
|
|
|
|
11559
|
|
|
3
|
|
|
|
|
2457
|
|
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
$Acme::Cow::default_cow = <<'EOC'; |
55
|
|
|
|
|
|
|
{$balloon} |
56
|
|
|
|
|
|
|
{$tl} ^__^ |
57
|
|
|
|
|
|
|
{$tl} ({$el}{$er})\_______ |
58
|
|
|
|
|
|
|
(__)\ )\/\ |
59
|
|
|
|
|
|
|
{$U} ||----w | |
60
|
|
|
|
|
|
|
|| || |
61
|
|
|
|
|
|
|
EOC |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=pod |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=head1 METHODS |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=head2 new |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=over 4 |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=item Parameters |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
A list of key-value pairs. If you plan to use an external file as |
74
|
|
|
|
|
|
|
the template, you probably want to say: |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
$x = new Acme::Cow(File => 'file.cow'); |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=item Returns |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
A blessed reference to an C. |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=back |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=cut |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub new |
87
|
|
|
|
|
|
|
{ |
88
|
3
|
|
|
3
|
1
|
263
|
my $proto = shift; |
89
|
3
|
|
33
|
|
|
27
|
my $class = ref $proto || $proto; |
90
|
3
|
|
|
|
|
11
|
my %args = @_; |
91
|
3
|
|
|
|
|
30
|
my $self = { |
92
|
|
|
|
|
|
|
wrap => 40, |
93
|
|
|
|
|
|
|
mode => 'say', |
94
|
|
|
|
|
|
|
fill => 1, |
95
|
|
|
|
|
|
|
over => 0, |
96
|
|
|
|
|
|
|
text => undef, |
97
|
|
|
|
|
|
|
el => 'o', |
98
|
|
|
|
|
|
|
er => 'o', |
99
|
|
|
|
|
|
|
U => ' ', |
100
|
|
|
|
|
|
|
%args, |
101
|
|
|
|
|
|
|
}; |
102
|
3
|
|
|
|
|
14
|
bless $self, $class; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=pod |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=head2 over |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
Specify (or retrieve) how far to the right (in spaces) the text |
110
|
|
|
|
|
|
|
balloon should be shoved. |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=over 4 |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=item Parameters |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
(optional) A number. |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=item Returns |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
The new value, if set; the existing value if not. |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=back |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=cut |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
sub over |
127
|
|
|
|
|
|
|
{ |
128
|
1
|
|
|
1
|
1
|
1
|
my $self = shift; |
129
|
1
|
50
|
|
|
|
4
|
if (@_) { |
130
|
1
|
|
|
|
|
5
|
$self->{'over'} = $_[0]; |
131
|
|
|
|
|
|
|
} |
132
|
1
|
|
|
|
|
2
|
return $self->{'over'}; |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=pod |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=head2 wrap |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
Specify (or retrieve) the column at which text inside the balloon |
140
|
|
|
|
|
|
|
should be wrapped. This number is relative to the balloon, not |
141
|
|
|
|
|
|
|
absolute screen position. |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=over 4 |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=item Parameters |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
(optional) A number. |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=item Returns |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
The new value, if set; the existing value if not. |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=item Notes |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
The number set here has no effect if you decline filling/adjusting |
156
|
|
|
|
|
|
|
of the balloon text. |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=back |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=cut |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
sub wrap |
163
|
|
|
|
|
|
|
{ |
164
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
165
|
0
|
0
|
|
|
|
0
|
if (@_) { |
166
|
0
|
|
|
|
|
0
|
$self->{'wrap'} = $_[0]; |
167
|
|
|
|
|
|
|
} |
168
|
0
|
|
|
|
|
0
|
return $self->{'wrap'}; |
169
|
|
|
|
|
|
|
} |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=pod |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=head2 think |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
Tell the cow to think its text instead of saying it. |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=over 4 |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=item Parameters |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
(optional) Text to think. |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=item Returns |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
None. |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
=back |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
=cut |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
sub think |
192
|
|
|
|
|
|
|
{ |
193
|
1
|
|
|
1
|
1
|
3
|
my $self = shift; |
194
|
1
|
|
|
|
|
3
|
$self->{'mode'} = 'think'; |
195
|
1
|
50
|
|
|
|
5
|
if (@_) { |
196
|
0
|
|
|
|
|
0
|
$self->text(@_); |
197
|
|
|
|
|
|
|
} |
198
|
|
|
|
|
|
|
} |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
=pod |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
=head2 SAY |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
Tell the cow to say its text instead of thinking it. |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
=over 4 |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
=item Parameters |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
(optional) Text to say. |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
=item Returns |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
None. |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
=back |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
=cut |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
sub say |
221
|
|
|
|
|
|
|
{ |
222
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
223
|
0
|
|
|
|
|
0
|
$self->{'mode'} = 'say'; |
224
|
0
|
0
|
|
|
|
0
|
if (@_) { |
225
|
0
|
|
|
|
|
0
|
$self->text(@_); |
226
|
|
|
|
|
|
|
} |
227
|
|
|
|
|
|
|
} |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
=pod |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
=head2 text |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
Set (or retrieve) the text that the cow will say or think. |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
=over 4 |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
=item Parameters |
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
A list of lines of text (optionally terminated with newlines) to |
240
|
|
|
|
|
|
|
be displayed inside the balloon. |
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
=item Returns |
243
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
The new text, if set; the current text, if not. |
245
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
=back |
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
=cut |
249
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
sub text |
251
|
|
|
|
|
|
|
{ |
252
|
4
|
|
|
4
|
1
|
20
|
my $self = shift; |
253
|
4
|
50
|
|
|
|
13
|
if (@_) { |
254
|
4
|
|
|
|
|
10
|
my @l = @_; |
255
|
4
|
|
|
|
|
18
|
$self->{'text'} = \@l; |
256
|
|
|
|
|
|
|
} |
257
|
4
|
|
|
|
|
10
|
return $self->{'text'}; |
258
|
|
|
|
|
|
|
} |
259
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
=pod |
261
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
=head2 print |
263
|
|
|
|
|
|
|
|
264
|
|
|
|
|
|
|
Print a representation of the cow to the specified filehandle |
265
|
|
|
|
|
|
|
(STDOUT by default). |
266
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
=over 4 |
268
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
=item Parameters |
270
|
|
|
|
|
|
|
|
271
|
|
|
|
|
|
|
(optional) A filehandle. |
272
|
|
|
|
|
|
|
|
273
|
|
|
|
|
|
|
=item Returns |
274
|
|
|
|
|
|
|
|
275
|
|
|
|
|
|
|
None. |
276
|
|
|
|
|
|
|
|
277
|
|
|
|
|
|
|
=back |
278
|
|
|
|
|
|
|
|
279
|
|
|
|
|
|
|
=cut |
280
|
|
|
|
|
|
|
|
281
|
|
|
|
|
|
|
sub print |
282
|
|
|
|
|
|
|
{ |
283
|
5
|
|
|
5
|
1
|
10
|
my $self = shift; |
284
|
5
|
|
50
|
|
|
31
|
my $fh = shift || \*STDOUT; |
285
|
5
|
|
|
|
|
15
|
print $fh $self->as_string(); |
286
|
|
|
|
|
|
|
} |
287
|
|
|
|
|
|
|
|
288
|
|
|
|
|
|
|
=pod |
289
|
|
|
|
|
|
|
|
290
|
|
|
|
|
|
|
=head2 fill |
291
|
|
|
|
|
|
|
|
292
|
|
|
|
|
|
|
Inform the cow to fill and adjust (or not) the text inside its balloon. |
293
|
|
|
|
|
|
|
By default, text inside the balloon is filled and adjusted. |
294
|
|
|
|
|
|
|
|
295
|
|
|
|
|
|
|
=over 4 |
296
|
|
|
|
|
|
|
|
297
|
|
|
|
|
|
|
=item Parameters |
298
|
|
|
|
|
|
|
|
299
|
|
|
|
|
|
|
(optional) A scalar; true if you want it to fill and adjust, false |
300
|
|
|
|
|
|
|
otherwise. |
301
|
|
|
|
|
|
|
|
302
|
|
|
|
|
|
|
=item Returns |
303
|
|
|
|
|
|
|
|
304
|
|
|
|
|
|
|
The current fill/adjust state, or the new one after setting. |
305
|
|
|
|
|
|
|
|
306
|
|
|
|
|
|
|
=back |
307
|
|
|
|
|
|
|
|
308
|
|
|
|
|
|
|
=cut |
309
|
|
|
|
|
|
|
|
310
|
|
|
|
|
|
|
sub fill |
311
|
|
|
|
|
|
|
{ |
312
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
313
|
0
|
0
|
|
|
|
0
|
if (@_) { |
314
|
0
|
|
|
|
|
0
|
$self->{'fill'} = $_[0]; |
315
|
|
|
|
|
|
|
} |
316
|
0
|
|
|
|
|
0
|
return $self->{'fill'}; |
317
|
|
|
|
|
|
|
|
318
|
|
|
|
|
|
|
} |
319
|
|
|
|
|
|
|
|
320
|
|
|
|
|
|
|
=pod |
321
|
|
|
|
|
|
|
|
322
|
|
|
|
|
|
|
=head2 as_string |
323
|
|
|
|
|
|
|
|
324
|
|
|
|
|
|
|
Render the cow as a string. |
325
|
|
|
|
|
|
|
|
326
|
|
|
|
|
|
|
=over 4 |
327
|
|
|
|
|
|
|
|
328
|
|
|
|
|
|
|
=item Parameters |
329
|
|
|
|
|
|
|
|
330
|
|
|
|
|
|
|
(optional) A scalar that can be interpreted as a C type |
331
|
|
|
|
|
|
|
for C. |
332
|
|
|
|
|
|
|
|
333
|
|
|
|
|
|
|
=item Returns |
334
|
|
|
|
|
|
|
|
335
|
|
|
|
|
|
|
An ASCII rendering of your cow. |
336
|
|
|
|
|
|
|
|
337
|
|
|
|
|
|
|
=item Notes |
338
|
|
|
|
|
|
|
|
339
|
|
|
|
|
|
|
If you're using an external file for a cow template, any difficulties |
340
|
|
|
|
|
|
|
in processing the file will occur in this method. |
341
|
|
|
|
|
|
|
|
342
|
|
|
|
|
|
|
Every time this method is called, the result is recalculated; there |
343
|
|
|
|
|
|
|
is no caching of results. |
344
|
|
|
|
|
|
|
|
345
|
|
|
|
|
|
|
=back |
346
|
|
|
|
|
|
|
|
347
|
|
|
|
|
|
|
=cut |
348
|
|
|
|
|
|
|
|
349
|
|
|
|
|
|
|
sub as_string |
350
|
|
|
|
|
|
|
{ |
351
|
10
|
|
|
10
|
1
|
22
|
my $self = shift; |
352
|
10
|
|
|
|
|
38
|
my $tmpl = shift; |
353
|
10
|
100
|
|
|
|
24
|
if (not $tmpl) { |
354
|
8
|
100
|
|
|
|
20
|
if (defined $self->{'File'}) { |
355
|
2
|
|
|
|
|
7
|
$tmpl = _slurp_file($self->{'File'}); |
356
|
|
|
|
|
|
|
} else { |
357
|
6
|
|
|
|
|
12
|
$tmpl = $Acme::Cow::default_cow; |
358
|
|
|
|
|
|
|
} |
359
|
|
|
|
|
|
|
} |
360
|
10
|
|
|
|
|
30
|
my $b = $self->_create_balloon(); |
361
|
10
|
|
|
|
|
41
|
my $template = new Text::Template(TYPE => 'STRING', SOURCE => $tmpl); |
362
|
10
|
|
|
|
|
1398
|
chomp($Acme::Cow::_private::balloon = $b->as_string()); |
363
|
10
|
|
|
|
|
23
|
$Acme::Cow::_private::el = $self->{'el'}; |
364
|
10
|
|
|
|
|
15
|
$Acme::Cow::_private::er = $self->{'er'}; |
365
|
10
|
|
|
|
|
26
|
$Acme::Cow::_private::U = $self->{'U'}; |
366
|
10
|
100
|
|
|
|
23
|
$Acme::Cow::_private::tl = ($self->{'mode'} eq 'think') ? 'o' : '\\'; |
367
|
10
|
100
|
|
|
|
21
|
$Acme::Cow::_private::tr = ($self->{'mode'} eq 'think') ? 'o' : '/'; |
368
|
10
|
|
|
|
|
44
|
my $text = $template->fill_in(PACKAGE => 'Acme::Cow::_private'); |
369
|
10
|
|
|
|
|
9504
|
return $text; |
370
|
|
|
|
|
|
|
} |
371
|
|
|
|
|
|
|
|
372
|
|
|
|
|
|
|
sub _create_balloon |
373
|
|
|
|
|
|
|
{ |
374
|
10
|
|
|
10
|
|
14
|
my $self = shift; |
375
|
10
|
|
|
|
|
50
|
my $b = new Acme::Cow::TextBalloon; |
376
|
10
|
|
|
|
|
23
|
for my $i (qw(fill text over mode wrap)) { |
377
|
50
|
|
|
|
|
92
|
$b->{$i} = $self->{$i}; |
378
|
|
|
|
|
|
|
} |
379
|
10
|
|
|
|
|
18
|
return $b; |
380
|
|
|
|
|
|
|
} |
381
|
|
|
|
|
|
|
|
382
|
|
|
|
|
|
|
sub _slurp_file |
383
|
|
|
|
|
|
|
{ |
384
|
2
|
|
|
2
|
|
4
|
my $filename = shift; |
385
|
2
|
|
|
|
|
9
|
my $fh = new IO::File($filename); |
386
|
2
|
|
|
|
|
172
|
local $/ = undef; |
387
|
2
|
|
|
|
|
63
|
my $text = $fh->getline(); |
388
|
2
|
|
|
|
|
137
|
return $text; |
389
|
|
|
|
|
|
|
} |
390
|
|
|
|
|
|
|
|
391
|
|
|
|
|
|
|
1; |
392
|
|
|
|
|
|
|
__END__ |