Skip Menu |

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

Report information
The Basics
Id: 77697
Status: resolved
Priority: 0/
Queue: Term-Completion

People
Owner: Marek.Rouchal [...] gmx.net
Requestors: valnaipaul2 [...] gmail.com
Cc:
AdminCc:

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



Subject: Warning 'Use of uninitialized value' when scrolling if input text is not matched
Module Version ------------ Term-Completion-0.91 Perl version/platform (not exclusive) ---------------------------- 5.8.6 / Mac OS X 10.4 5.8.8 / Redhat Enterprise Linux 5, HP-UX 11i (v2, v3) Issue Description ------------- The warning 'Use of uninitialized value ...' appears upon a cursor-up/-down if the value in the input buffer does not correspond to any entries amongst the defined choices. The attached patch ("term-completion-0.91.scroll_fix.diff") would see a bell issued instead in this situation. Demo Procedure ------------- 1. Run Demo Listing 1, which prompts for input/selection of a country (named A*, B*, and a few C*, for brevity). 2. Key "A" (which would match some countries). 3. Key cursor-up or cursor-down...the previous/next country should be presented in the input buffer. 4. Key 'kill' (Ctrl-U) to clear the input buffer. 5. Key "X" (no country name begins "X"). 6. Key cursor-up or cursor-down...the 'Use of uninitialized ...' warning should appear. Demo Sample Output ----------------- -bash-2.05b$ ./eg1 Enter/select a country: AFGHANISTAN Enter/select a country: XUse of uninitialized value in length at /Library/Perl/5.8.6/Term/Completion.pm line 284, <DATA> line 249. Use of uninitialized value in substitution (s///) at /Library/Perl/5.8.6/Term/Completion.pm line 529, <DATA> line 249. Enter/select a country: Demo Listing 1 ------------ #!/usr/bin/perl use strict ; use warnings 'all' ; no warnings 'uninitialized' ; # Decomment to test the patched Completion.pm # use lib '.' ; use Term::Completion ; my $tc ; my $choice ; my @country ; chomp( @country = <DATA> ) ; $tc = Term::Completion->new( prompt => 'Enter/select a country: ', choices => \@country ) ; $choice = $tc->complete() ; print 'Country selected: ', $choice, "\n" ; exit ; __DATA__ AFGHANISTAN Ă…LAND ISLANDS ALBANIA ALGERIA AMERICAN SAMOA ANDORRA ANGOLA ANGUILLA ANTARCTICA ANTIGUA AND BARBUDA ARGENTINA ARMENIA ARUBA AUSTRALIA AUSTRIA AZERBAIJAN BAHAMAS BAHRAIN BANGLADESH BARBADOS BELARUS BELGIUM BELIZE BENIN BENIN BERMUDA BHUTAN BOLIVIA, PLURINATIONAL STATE OF BONAIRE, SINT EUSTATIUS AND SABA BOSNIA AND HERZEGOVINA BOTSWANA BOUVET ISLAND BRAZIL BRITISH INDIAN OCEAN TERRITORY BRUNEI DARUSSALAM BULGARIA BURKINA FASO BURUNDI CAMBODIA CAMEROON CANADA
Subject: term-completion-0.91.scroll_fix.diff
*** /Library/Perl/5.8.6/Term/Completion.pm Fri Feb 27 09:21:00 2009 --- Completion.pm Tue Jun 5 15:07:00 2012 *************** *** 256,262 **** --- 256,264 ---- $_ =~ $this->{up} && do { unless(defined $choice_num) { @choice_cycle = $this->get_choices($return); + if(defined $choice_cycle[$#choice_cycle]) { $choice_num = $#choice_cycle; + } } else { if($choice_num <= 0) { $choice_num = @choice_cycle; # TODO get_choices returns number in scalar context? *************** *** 270,287 **** --- 272,295 ---- $_ =~ $this->{down} && do { unless(defined $choice_num) { @choice_cycle = $this->get_choices($return); + if(defined $choice_cycle[0]) { $choice_num = 0; + } } else { if(++$choice_num >= @choice_cycle) { $choice_num = 0; } } PRINT_UPDOWN_ITEM: + unless(defined $choice_num) { + $this->{out}->print($this->{bell}); + } else { #TODO only delete/print differences, not full string $this->{out}->print($this->{del_one} x length($return)); $return = $choice_cycle[$choice_num]; $this->{out}->print($return); $r = length($return); + } last CASE; };
Fixed in Term-Completion-1.00, just uploaded to CPAN. Thanks for the bug report and/or patch!