Subject: | %attribs tie in Perl.pm is incomplete |
From the Devel::REPL shell, I can access
the Term::ReadLine and try to print the
Attribs hash (tied with Term::ReadLine::Perl::Tie)
and I get the following error:
$ keys %{$_REPL->term->Attribs}
Runtime error: Can't locate object method "FIRSTKEY"
via package Term::ReadLine::Perl::Tie" at (eval 310)
line 5.
A look at the Perl.pm source I see that all the
needed TIEHASH accessors have not been implemented.
Creating a fuller implementation:
package Term::ReadLine::Perl::TieHash;
sub TIEHASH { bless {} }
sub DESTROY {}
sub STORE {
my ($self, $name) = (shift, shift);
$ {'readline::rl_' . $name} = shift;
}
sub FETCH {
my ($self, $name) = (shift, shift);
$ {'readline::rl_' . $name};
}
sub EXISTS {
my ($self, $name) = @_;
return exists $readline::{'rl_' . $name};
}
{
my (@rl_keys);
sub FIRSTKEY {
@rl_keys = sort grep { m/^rl_\w/ } keys %readline:: ;
my $key = substr shift(@rl_keys), 3;
return wantarray ? ($key, ${'readline::rl_' . $key}) : $key;
}
sub NEXTKEY {
my $key = substr shift(@rl_keys), 3;
return wantarray ? ($key, ${'readline::rl_' . $key}) : $key;
}
}
Resulted in a successful call:
$ keys %{$_REPL->term->Attribs}
$ARRAY1 = [
'History',
'HistoryIndex',
'MaxHistorySize',
'NoInitFromFile',
'OperateCount',
'attempted_completion_function',
'basic_commands',
'basic_word_break_characters',
'bind',
'completer_word_break_characters',
'completion_function',
'correct_sw',
'default_selected',
'delete_selection',
'filename_list',
'first_char',
'getc',
'last_pos_can_backspace',
'margin',
'max_numeric_arg',
'readline_name',
'screen_width',
'scroll_nextline',
'set',
'special_prefixes',
'start_default_at_beginning',
'term_set',
'vi_replace_default_on_insert'
];
As the new functionality should be a strict
superset of the existing tie. I would like
to see this folded into the official readline
support. Hope this helps.
--Chris