Discipulus has asked for the wisdom of the Perl Monks concerning the following question:

hello there,

i was trying to add an 'edit' function to a command line interactive menù where i have to use only core modules.
The behaviour i want is: when you type 'edit somekey', if somekey exists in a hash, you get a prompt like:
edit somekey>This is the editable string: change it if you want.
Then you can use backspace to cancel, arrows to move, etc, etc..
Borwsing the core modules list i have encountered Term::ReadLine and asking in the chatterbox some wise monk told me that T:RL:Perl can call readline with two argouments where the second one is an 'editable text string'
In some clean new installation this worked but in some other no, beacuse seems that T:RL call other modules (T:RL::Perl and T:RL::GNU, for example) and only some module can handle the two argouments form and this is why the form is not documented.

in which way can I reproduce this behaviour?

I looked at the source of the T:RL::Perl at the readline sub but, sincerely, i cannot understand it.

More: i'm a little bit confused about this module and the core list: the main is in the core list but can load the perl or the gnu version. But T:RL::Perl is not in the core list..

the docs say that the method call ReadLine returns which version is loaded so in two different Perl installation i tried this:
perl -e "use Term::ReadLine; $term = Term::ReadLine->new('name'); + print $term->ReadLine" #in both installation it returns: Term::ReadLine::Perl # #but when i tried: # perl -e "use Term::ReadLine::Perl" #in one installation (strawberry) i got: Can't locate object method "Features" via package "Term::ReadLine::Stu +b" at C:/Perl_Flash/pperl2/pperl/perl/site/lib/Term/ReadLine/Perl.pm +line 101. Compilation failed in require at -e line 1. BEGIN failed--compilation aborted at -e line 1.
in conclusion:

how can i replicate the wanted behaviour of pre-filling some user's input?
what is the situation for this module? thanks for the patience

L*

there are no rules, there are no thumbs..

Replies are listed 'Best First'.
Re: emulate the Term::ReadLine's two arguments form
by LanX (Saint) on Feb 17, 2012 at 14:08 UTC
    I was recently also struggeling with T:RL. as it seems Gnu-Readline is the reference implementation and all alternatives have practically no POD.

    If you don't wanna install an XS module, I'd recommend to take one of the pure Perl implemantations, which have practically no dependencies, i.e. you could simply copy them into your distribution and modify them as you wish (but check licence before!)

    see %Features of T::RL to know which functionality is supported by underlying module.

    DB<105> $term->Features => { addHistory => 1, appname => 1, attribs => 1, autohistory => 1, getHistory => 1, minline => 1, newTTY => 1, ornaments => 1, preput => 1, readHistory => 1, setHistory => 1, stiflehistory => 1, tkRunning => 1, writeHistory => 1, }

    I suppose preput means what your looking for.

    HTH

    Cheers Rolf

      "preput" it is. Good work++. Here's my attempt at a preput.
      #!/usr/bin/perl -l use strict; use warnings; use Term::ReadLine; my $term = new Term::ReadLine "Default Input"; my $input = $term->readline("Enter some text: ", "What do you want to +say?"); print "You entered: $input";
        thanks to you all, but
        the problem is that in the previous posted code, in my two installations the 'editable second arg' is simply ignored.

        more: i cannot succesfully load the T:RL:Perl module in the starwberry installation: the error is my first post.
        if i load directly that module in a script, nothing special appens nor error catched by strict or warning..

        how can i then replicate this behavior in every Perl installation?

        thanks
        L*
        there are no rules, there are no thumbs..