Brian Phillips > Text-Snippet > Text::Snippet

Download:
Text-Snippet-0.04.tar.gz

Dependencies

Annotate this POD

CPAN RT

Open  0
View/Report Bugs
Module Version: 0.04   Source  

NAME ^

Text::Snippet - TextMate-like snippet functionality

VERSION ^

version 0.04

SYNOPSIS ^

This module provides TextMate-like snippet functionality via an editor-agnostic API. The snippet syntax is modeled after the snippets provided by TextMate.

    use Text::Snippet;

    my $snippet = Text::Snippet->parse($snippet_content);

        my @tabstops = $snippet->tab_stops;
        foreach my $t (@tabstops) {
                my $replacement = get_user_input();    # get user input somehow
                $t->replace($replacement) if ($user_input);
        }
        print $snippet;                           # stringify and write to STDOUT
        
        # alternate "cursor" interface

        my $cursor = $snippet->cursor;
        while ( my $direction = get_user_tab_direction() ) {    # forward or backward
                my $t;
                if ( $direction == 1 ) {          # tab
                        $t = $cursor->next;
                } elsif ( $direction == -1 ) {    # shift-tab
                        $t = $cursor->prev;
                } else {
                        last;                         # bail
                }
                next if ( !$t );

                # get (zero-based) cursor position relative to the beginning of the snippet
                my($line, $column) = $cursor->current_position;

                my $replacement = get_user_input();
                $t->replace($replacement);
        }
        print $snippet; # stringify snippet and write to STDOUT

SUPPORTED SNIPPET SYNTAX ^

CLASS METHODS ^

parse

This is the main entry point into this module's functionality. It takes a single argument, the content of the snippet that conforms to the syntax described above.

INSTANCE METHODS ^

to_string

Obviously, gets the full content of the snippet as it currently exists. This object is overloaded as well so simply printing the object or including it inside double quotes will have the same effect.

chunks

Returns an ArrayRef that makes up the entire content of the snippet. Depending on the source of the snippet, some of these items may be literal scalars (representing static content) and others may be Text::Snippet::TabStop objects that represent the user-enterable portions of the snippet.

src

This returns the original source as it was passed to "parse"

tab_stops

This returns an ArrayRef of Text::Snippet::TabStop objects that represent the user-enterable portions of the snippet. These are ordered by the tab stop's index with the zero-th index coming last.

cursor

This method creates a Text::Snippet::TabStop::Cursor object for you which allows the caller to traverse a series of tab stops in a convenient fashion.

BUGS ^

Please report any bugs or feature requests to bug-text-snippet at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Text-Snippet. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT ^

You can find documentation for this module with the perldoc command.

    perldoc Text::Snippet

You can also look for information at:

AUTHOR ^

  Brian Phillips <bphillips@cpan.org>

COPYRIGHT AND LICENSE ^

This software is copyright (c) 2010 by Brian Phillips.

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

syntax highlighting: