David Glasser > Text-Tags > Text::Tags::Parser

Download:
Text-Tags-0.04.tar.gz

Dependencies

Annotate this POD

CPAN RT

Open  0
View/Report Bugs
Source  

NAME ^

Text::Tags::Parser - parses "folksonomy" space-separated tags

SYNOPSIS ^

    use Text::Tags::Parser;
    my @tags = Text::Tags::Parser->new->parse_tags(q{ foo  bar  "baz bap" jenny's   'beep beep' });
    my $line = Text::Tags::Parser->new->join_tags('foo', 'bar', 'baz bap', "jenny's", 'beep beep');

DESCRIPTION ^

Parses "folksonomies", which are simple space-or-comma-separated-but-optionally-quoted tag lists.

Specifically, tags can be any string, as long as they don't contain both a single and a double quote. Hopefully, this is a pretty obscure restriction. In addition, all whitespace inside tags is normalized to a single space (with no leading or trailing whitespace).

In a tag list string, tags can optionally be quoted with either single or double quotes. There is no escaping of either kind of quote, although you can include one type of quote inside a string quoted with the other. Quotes can also just be included inside tags, as long as they aren't at the beginning; thus a tag like joe's can just be entered without any extra quoting. Tags are separated by whitespace and/or commas, though quoted tags can run into each other without whitespace. Empty tags (put in explicitly with "" or '') are ignored. (Note that commas are not normalized with whitespace, and can be included in a tag if you quote them.)

Why did the previous paragraph need to be so detailed? Because Text::Tags::Parser always successfully parses every line. That is, every single tags line converts into a list of tags, without any error conditions. For general use, you can just understand the rules as being separate tags with spaces or commas, and put either kind of quotes around tags that need to have spaces.

METHODS ^

new

Creates a new Text::Tags::Parser object. In this version of the module, the objects do not actually hold any state, but this could change in a future version.

parse_tags($string)

Given a tag list string, returns a list of tags (unquoted) using the rules described above. Any given tag will show up at most once in the output list.

join_tags(@tags)

Given a list of tags, returns a tag list string containing them (appropriately quoted). Note that illegal tags will have all of their double quotes converted to single quotes. Any given tag will show up at most once in the output string.

join_quoted_tags(@tags)

As "join_tags", but every tag will be delimited by wither single or double quotes -- unlike "join_tags", which only quotes when necessary.

DEPENDENCIES ^

None.

BUGS AND LIMITATIONS ^

The rules are kind of complicated, but at least they are well-defined.

Please report any bugs or feature requests to bug-text-tags@rt.cpan.org, or through the web interface at http://rt.cpan.org.

SEE ALSO ^

Text::Folksonomies, a module with similar functionality but has much more simplistic quote handling. (Specifically, it doesn't allow you to put any type of quote into a tag.) But if you don't care about that sort of support, it seems to work fine.

AUTHOR ^

David Glasser <glasser@bestpractical.com>

LICENCE AND COPYRIGHT ^

Copyright (c) 2005, Best Practical Solutions, LLC. All rights reserved.

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

DISCLAIMER OF WARRANTY ^

BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR CORRECTION.

IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.

syntax highlighting: