Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: about Term::ReadLine and it's imported function

by LanX (Saint)
on Nov 24, 2014 at 13:31 UTC ( [id://1108256]=note: print w/replies, xml ) Need Help??


in reply to about Term::ReadLine and it's imported function

rl_basic_commands seems to be a Term::ReadLine::Perl or Term::ReadLine::Perl5 only thing.

You'll need to install one of them and according to Term::ReadLine doku's last paragraph set $ENV{PERL_RL}="Perl" prior² to use Term::ReadLine¹

As a side note: I had no problems yet just using Term::ReadLine::Gnu with tab completion.

Cheers Rolf

(addicted to the Perl Programming Language and ☆☆☆☆ :)

¹) Term::ReadLine is kind of a wrapper module proxying to other Term::ReadLine:* modules

edit
s/Term::ReadLine::Perl/Term::ReadLine::Perl5/ ³

update

²) since use happens very early in compilation you'll most likely need to set the ENV within a BEGIN block.

(That's for sure a silly interface, Term::ReadLine should have a config option for the importer.)

update
³) both should work, but looking thru this Perl4 code with ' as package separator is aching my eyes...

update

looking into the source revealed the following line as fall back if PERL_RL is not found in %ENV

  eval "use Term::ReadLine::Gnu; 1" or eval "use Term::ReadLine::Perl; 1";

This means Term::ReadLine::Perl is only used by default if Term::ReadLine::Gnu wasn't found! Since you are using a T::RL::Perl* only feature you MUST set the env.

Maybe check with print $term->ReadLine; which module was loaded

Replies are listed 'Best First'.
Re^2: about Term::ReadLine and it's imported function
by Discipulus (Canon) on Nov 24, 2014 at 19:02 UTC
    Thanks LanX
    i'm still in the fog..
    CPAN Terminal> l Term::ReadLine .. Version Installed 1.14 Version on CPAN 1.14 CPAN Terminal> l Term::ReadLine::Perl .. Version Installed 1.0303 Version on CPAN 1.0303 #anyway using Term::ReadLine::Perl directly cause some error: io@COMP:C>perl -MTerm::ReadLine::Perl -e 0 Can't locate object method "Features" via package "Term::ReadLine::Stu +b" at C:/ulisse/strawberry/perl/lib/Term/ReadLine Perl.pm line 101. Compilation failed in require. BEGIN failed--compilation aborted.
    Eventually, modifying the code to use the ENV var seems to produce the same results:
    #!perl use strict; use warnings; use Term::ReadLine; BEGIN{$ENV{PERL_RL}="Perl"} print "\$ENV{PERL_RL} $ENV{PERL_RL}\n"; $ENV{TERM}=undef; my $term = Term::ReadLine->new('xxx'); print $term->ReadLine; my %cmds = (a=>1,b=>2); # THIS WORKS &readline::rl_basic_commands(keys %cmds); # THE FOLLOWING CHECK DOES NOT WORK if (exists &readline::rl_basic_commands){print "BEFORE WHILE EXISTS +\n"; &readline::rl_basic_commands(keys %cmds);} while ( defined ( $_ = $term->readline( '>') ) ) { print "$_\n"; } continue{ # THIS CHECK WORKS INDEED! if (exists &readline::rl_basic_commands){print "IN CONTINUE EXISTS\ +n"; &readline::rl_basic_commands(keys %cmds);} } ###OUTPUT $ENV{PERL_RL} Perl > ###if you press TAB the current dir content is dumped: this is the def +ault behaviour if ###you does not provide autocompletion list ###but after, if you press ENTER: > Term::ReadLine::Perl IN CONTINUE EXISTS > a b >
    That said, it seems to be an headache builder. Thanks for the suggestions.

    L*
    There are no rules, there are no thumbs..
    Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
      I've posted working code (plz read again), build on this and you'll find your error. ( we are at a point were you should show more efforts ;-)

      Beside of this, you are using an internal feature of Term::ReadLine::Perl while Term::ReadLine offers an official interface for all sub-modules.

      I've tested it with the debugger setting env and either *::Gnu *::Perl and *::Zoid did tab-completion w/o problems.

      Have a look at Attribs

      Cheers Rolf

      (addicted to the Perl Programming Language and ☆☆☆☆ :)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1108256]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (8)
As of 2024-04-19 12:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found