Skip Menu |

This queue is for tickets about the Term-ReadLine-Zoid CPAN distribution.

Report information
The Basics
Id: 32885
Status: open
Priority: 0/
Queue: Term-ReadLine-Zoid

People
Owner: Nobody in particular
Requestors: a.r.ferreira [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: [PATCH] GetHistory always returns a list
Date: Sat, 2 Feb 2008 16:04:20 -0200
To: bug-Term-ReadLine-Zoid [...] rt.cpan.org, "Jaap Karssenberg" <pardus [...] cpan.org>
From: "Adriano Ferreira" <a.r.ferreira [...] gmail.com>
Hi, Jaap. Some days ago I submitted a patch for Shell::Base so that it is not anymore gnu-centric and works with Term::ReadLine::Perl as well as Term::ReadLine::Gnu. http://search.cpan.org/dist/Shell-Base http://rt.cpan.org/Public/Bug/Display.html?id=32816 While testing the patch, I gave a try with Term::ReadLine::Zoid which did not pass all the tests. I discovered that the outstanding issue was the behavior you gave to GetHistory. Namely, @history = $term->GetHistory(); # an array in list context $history = $term->GetHistory(); # an array ref in scalar context So this attached patch proposes a retreat of the 0.07 version behavior of GetHistory() in scalar context. So that $history_size = $term->GetHistory(); # when the array returns its size in scalar context This is coherent with the behavior of the other two Term::ReadLine::* package (Perl and Gnu) and don't break your test suite. The patch also adds tests to spec this behavior. With this change and the mentioned Shell-Base patch, T::RL::Zoid works ok with Shell::Base as well. So I leave it to your consideration. Kind regards, Adriano Ferreira diff -ru Term-ReadLine-Zoid-0.07/Changes Term-ReadLine-Zoid/Changes --- Term-ReadLine-Zoid-0.07/Changes 2004-11-22 11:09:24.000000000 -0200 +++ Term-ReadLine-Zoid/Changes 2008-02-02 15:52:24.000000000 -0200 @@ -1,5 +1,10 @@ Revision history for Term-ReadLine-Zoid - another ReadLine package +? + - GetHistory() now returns a list always + (like T::RL::Perl and T::RL::Gnu). Thus + scalar GetHistory() is the history size. + 0.07 Mon Nov 22 2004 Maintenance release, just one bugfix Only in Term-ReadLine-Zoid: Makefile diff -ru Term-ReadLine-Zoid-0.07/lib/Term/ReadLine/Zoid.pm Term-ReadLine-Zoid/lib/Term/ReadLine/Zoid.pm --- Term-ReadLine-Zoid-0.07/lib/Term/ReadLine/Zoid.pm 2004-11-22 11:09:24.000000000 -0200 +++ Term-ReadLine-Zoid/lib/Term/ReadLine/Zoid.pm 2008-02-02 15:53:14.000000000 -0200 @@ -7,7 +7,7 @@ no warnings; # undef == '' down here our @ISA = qw/Term::ReadLine::Zoid::Base Term::ReadLine::Stub/; # explicitly not use'ing T:RL::Stub -our $VERSION = '0.07'; +our $VERSION = '0.07_01'; sub import { # terrible hack - Term::ReadLine in perl 5.6.x is defective return unless (caller())[0] eq 'Term::ReadLine' and $] < 5.008 ; @@ -204,7 +204,7 @@ sub Features { { ( map {($_ => 1)} qw/appname minline attribs - addhistory addHistory getHistory getHistory TermSize/ ), + addhistory addHistory gethistory getHistory TermSize/ ), ( map {($_ => $_[0]{config}{$_})} qw/autohistory autoenv automultiline/ ), } } @@ -214,9 +214,8 @@ # ############ # sub GetHistory { - return wantarray - ? ( reverse @{$_[0]{history}} ) - : [ reverse @{$_[0]{history}} ] ; + my @h = ( reverse @{$_[0]{history}} ); + return @h; } sub SetHistory { @@ -1168,8 +1167,8 @@ =item C<GetHistory()> -Simple acces to the history arry, the "set" function supports both a list -and a reference, the "get" function uses "wantarray". +Simple access to the history array. The "set" function supports both a list +and a reference. The "get" function always returns a list. Not sure which behaviour is compatible with T:RL::Gnu. =item C<TermSize()> diff -ru Term-ReadLine-Zoid-0.07/t/10_zoid.t Term-ReadLine-Zoid/t/10_zoid.t --- Term-ReadLine-Zoid-0.07/t/10_zoid.t 2004-11-22 11:09:24.000000000 -0200 +++ Term-ReadLine-Zoid/t/10_zoid.t 2008-02-02 15:43:20.000000000 -0200 @@ -1,5 +1,5 @@ use strict; -use Test::More tests => 48; +use Test::More tests => 52; use Term::ReadLine::Zoid; $|++; @@ -195,3 +195,21 @@ ok $t->backward_line, 'up 3'; ok ! $t->backward_line, 'up 4'; is_deeply $t->{pos}, [5, 0], 'pos 2'; + +print "# set/get history\n"; + +test_reset $t; +$t->SetHistory(qw(foo bar cuz)); # SetHistory(@list) +is $t->GetHistory, 3, 'scalar GetHistory = history size'; +{ + my @h = $t->GetHistory; + is_deeply \@h, [qw(foo bar cuz)], 'GetHistory works'; +} + +test_reset $t; +$t->SetHistory([qw(foo bar cuz)]); # SetHistory(\@list) +is $t->GetHistory, 3, 'scalar GetHistory = history size'; +{ + my @h = $t->GetHistory; + is_deeply \@h, [qw(foo bar cuz)], 'GetHistory works'; +}

Message body is not shown because sender requested not to inline it.

Subject: Re: [rt.cpan.org #32885] [PATCH] GetHistory always returns a list
Date: Tue, 05 Feb 2008 21:53:50 +0000
To: bug-Term-ReadLine-Zoid [...] rt.cpan.org
From: Jaap Karssenberg <jaap.karssenberg [...] gmail.com>
Hi Adriano, Thanks for the patch. I will use it next time I roll a few releases for CPAN. May take a while though, real life taking up most of my days lately. Regards, Jaap <pardus@cpan.org> a.r.ferreira@gmail.com via RT wrote: Show quoted text
> Hi, Jaap. > > Some days ago I submitted a patch for Shell::Base so that it is not > anymore gnu-centric and works with Term::ReadLine::Perl as well as > Term::ReadLine::Gnu. > > http://search.cpan.org/dist/Shell-Base > http://rt.cpan.org/Public/Bug/Display.html?id=32816 > > While testing the patch, I gave a try with Term::ReadLine::Zoid which > did not pass all the tests. I discovered that the outstanding issue > was the behavior you gave to GetHistory. Namely, > > @history = $term->GetHistory(); # an array in list context > $history = $term->GetHistory(); # an array ref in scalar context > > So this attached patch proposes a retreat of the 0.07 version behavior > of GetHistory() in scalar context. So that > > $history_size = $term->GetHistory(); # when the array returns its > size in scalar context > > This is coherent with the behavior of the other two Term::ReadLine::* > package (Perl and Gnu) and don't break your test suite. The patch also > adds tests to spec this behavior. > > With this change and the mentioned Shell-Base patch, T::RL::Zoid works > ok with Shell::Base as well. > > So I leave it to your consideration. > > Kind regards, > Adriano Ferreira > >