Skip Menu |

This queue is for tickets about the Text-Banner CPAN distribution.

Report information
The Basics
Id: 39431
Status: resolved
Priority: 0/
Queue: Text-Banner

People
Owner: gsullivan [...] cpan.org
Requestors: gstide [...] Hotmail.com
Cc:
AdminCc:

Bug Information
Severity: Critical
Broken in: 1.00
Fixed in: 2.00



Subject: can't create Banner object multiple times
If you 'new' multiple instances, you will find only one instance works. The others output blanks.
Subject: [rt.cpan.org #39431] multiple object fix
Date: Fri, 17 May 2013 15:55:12 -0400
To: <bug-Text-Banner [...] rt.cpan.org>
From: Joshua Nekl <josh.nekl [...] analog.com>
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 }
Thanks for the patch. The patch has been applied, and a new test was created.