The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Text::Editor::Easy::Line - Object oriented interface to a file line (managed in the background by "Text::Editor::Easy::Abstract" and "Text::Editor::Easy::File_manager").

VERSION

Version 0.49

SYNOPSIS

    my $line = $editor->number(4);
    print "Initial text of line number 4 : ", $line->text, "\n";
    $line->set('This will be the new content');
    if ( ! $line->displayed ) {
        $line->display( {'at' => 'middle'} );
    }
    $line->select;
    

If we except the print, you could have done the same thing writing this horrible line :

    $editor->number(4)->set('This will be the new content')->select({'force' => 'middle'});

WARNING

"Editor" object will stand for "Text::Editor::Easy" object and "line" object will stand for "Text::Editor::Easy::Line" object.

Some of the methods of the "editor" object need a "line" object as parameter or return "line" object(s). You should never call yourself the "new" method of the "line" package to create "line" objects. First, you use an "editor" method that returns "line" object(s), and you provide the second "editor" method that need a "line" object with what you have received from the first call.

Note that 'line' instances are scalar references : you can't do anything with them except calling methods of the interface. Each 'line' knows which 'editor' it belongs to.

METHODS

bottom_ord

This method does not accept any parameter.

It returns undef if the line is not displayed. When displayed, it returns the ordinate of the bottom of the line. See also "top_ord". The ordinate is the pixel number from the top with a graphical user interface but will be the line number in console mode.

display

    $line->display( { 'at' => 32, 'from' => 'bottom', 'no_check' => 1 } );
    print "Bottom ordinate of line $line is : ", $line->bottom_ord, "\n"; # Should return 32...

This method accepts only one optional parameter which is a hash reference. The options that this hash may contain are described in 'editor display method' as the second parameter.

To display an editor, you have to take a reference which is a line of this editor. When you call display method with a line instance, this reference is contained in the caller. When you call display method with an editor instance, you have to set the line in a mandatory parameter.

displayed

This method does not accept any parameter.

In list context, it returns 'display' instances (that is Text::Editor::Easy::Display object(s)) or an empty list if the line is not visible. If wrap mode is not used, there can't be more than one 'display' instance associated to one 'line' instance. With wrap mode, it depends on the line size and on the screen width.

Called in scalar context, you just get the number of 'display' instances associated with that line : 0 if the 'line' is not visible, 1 or more if the line is visible.

Note that if wrap mode is used and the 'line' is partially visible (some 'displays' are visible, other are not) the result you get is identical as if the line was entirely visible. Lines are always displayed as a whole.

next

This method does not accept any parameter.

Returns the next 'line' instance or undef if it's the last.

    # A very slow slurp implementation (at present, 'editor' slurp method is written like that !)
    my $line   = $editor->first; # shortcut for $editor->number(1)
    my $slurp = $line->text;
    $line = $line->next;
    while ( $line ) {
        $slurp .= "\n" . $line->text;
        $line = $line->next;
    }

number

This method does not accept any parameter.

Returns the order of the line (it's number). Note that for a given 'line' instance, this number will change according to updates ('line' creations or suppressions).

previous

This method does not accept any parameter.

Returns the previous 'line' instance or undef if it's the first.

select

The interface of this method will change. At present, it's not possible to select lines that are not visible unless you force them to be visible.

set

This method accepts one parameter : a string that will update the 'line' content.

It returns the 'line' instance that was used to call the set.

text

This method does not accept any parameter.

It returns the text of the line.

top_ord

This method does not accept any parameter.

It returns undef if the line is not displayed. When displayed, it returns the ordinate of the top of the line. See also "bottom_ord".

OTHER METHODS

These methods shouldn't be used.

count (class method)

Number of "line" objects created for the thread, for all "editor" objects defined. As threre are more threads, there can be other "line" objects declared in other threads (and, why not, pointing at same the lines).

linesize (class method)

For debugging memory leaks which are numerous...

new

ref

This is the only common value (it's an auto-incrementing integer chosen by 'File_manager' thread) between all threads : for a given 'editor' instance, if 2 lines (belonging to the same editor) have the same 'ref' in 2 different threads, they are pointing at the same line. But of course, as each thread has its own memory, scalar references and, then, line instances are different.

editor

Returns the 'editor' instance the line belongs to. Should be useless (?).

seek_start

Give the start position of the line in the file, 0 if there's no file associated. This position is true only at the beginning or just after a save. Positions are not updated at each change.

set_info

To save data in association to a particular line. This data is saved in the 'File_manager' thread, so it can be seen and shared by all threads thanks to 'get_info' method.

get_info

Retrieve 'info' associated to the 'line' object thanks to 'set_info' method.

COPYRIGHT & LICENSE

Copyright 2008 - 2009 Sebastien Grommier, all rights reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.