NAME
Tie::Tk::Text - Access Tk::Text or Tk::ROText widgets as arrays.
SYNOPSIS
use Tie::Tk::Text;
my $w = $mw->Text()->pack();
tie my @text, 'Tie::Tk::Text', $w;
$w->insert('end', "foo\nbar\nbaz\n");
print $text[1]; # "bar\n"
DESCRIPTION
This module defines a class for tie()ing Tk::Text and Tk::ROText widgets to an array, allowing them to be accessed as if they were an array of lines.
It's not expected that anyone will actually want to populate and manipulate their Text widgets this way, though you are of course free to do so. This module was created to make Text widgets accessible to functions that expect an array reference as their input. (e.g. Algorithm::Diff::sdiff) You can do that with read-only support (FETCH and FETCHSIZE). All of the methods (PUSH, POP, STORE, etc.) are included for completeness.
CAVEATS
Arrays use zero-based indexing. Text widgets use one-based indexing. Ergo, line five is at index four.
Lines end in "\n". Be careful about what you add or you could get odd results. For example, doing $text[3] = 'foo'
will replace the contents of line four with 'foo' but will join lines four and five because you didn't include a newline at the end of the string. Similarly, $text[3] = "foo\nbar\n"
will replace line four with "foo\n" and insert "bar\n" before line five.
LIMITATIONS
There's no support for tags or a lot of other things that you can do with Text widgets. There isn't supposed to be. This is not a bug.
AUTHOR
Michael J. Carman <mjcarman@mchsi.com>
COPYRIGHT AND LICENSE
Copyright (C) 2006 by Michael J. Carman
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.