Once <DATA> is read for first object, it is not available for following
objects, the <DATA> file position pointer is at end of __DATA__. This
data is common to all objects and should be a package/class variable.
Example code which demonstrates bug.
#! /usr/bin/env perl
use Text::Banner;
my $a = Text::Banner->new;
$a->set('First');
$a->fill('reset');
print $a->get;
my $b = Text::Banner->new;
$b->set('Second');
print $b->get;
Patch follows.
--- Banner.pm.orig 2013-05-17 11:51:11.000000000 -0400
+++ Banner.pm 2013-05-17 15:36:21.000000000 -0400
@@ -13,16 +13,22 @@
*Banner::VERSION=*Banner::version=\'$Revision: 1.2 $';
*Banner::ID=*Banner::id=\'$Id: Banner.pm,v 1.2 1999/12/19 18:28:23
stuart Exp $';
}
+
+our $XL;
+$XL = undef;
+
sub new {
my $proto=shift; my $class=ref($proto)||$proto;
- my $self={}; my $save=$/; undef $/; my ($byte,$var,$num,$pic);
- foreach $byte (split //,unpack("u*",<DATA>)) {
- $var=ord $byte;
- foreach $num (128,64,32,16,8,4,2,1) {
- if (($var&$num)==$num) { $pic .=1; } else { $pic .=0; }
- }
+ my $self={}; my $save=$/; undef $/; my ($byte,$var,$num);
+ unless(defined($XL)) {
+ foreach $byte (split //,unpack("u*",<DATA>)) {
+ $var=ord $byte;
+ foreach $num (128,64,32,16,8,4,2,1) {
+ if (($var&$num)==$num) { $XL .=1; } else { $XL .=0; }
+ }
+ }
}
- $self->{XL}=$pic; $self->{ORIENTATION}="H"; $self->{SIZE}=1; $/=$save;
+ $self->{ORIENTATION}="H"; $self->{SIZE}=1; $/=$save;
return bless $self,$class;
}
sub rotate {
@@ -81,7 +87,7 @@
foreach (@{$self->{STRING}}) { $map{$_}=1 };
foreach $char (keys %map) {
$var=ord $char; $var-=32; $pos=$var*49;
- $temp=substr($self->{XL},$pos,49);
+ $temp=substr($XL,$pos,49);
foreach (0,7,14,21,28,35,42,49) { push @{$self->{PIC}->{$char}},
substr($temp,$_,7); }
push @{$self->{PIC}->{$char}},"0000000"; # this is spacing
between lines
}