NAME
String::TagString - parse and emit tag strings (including tags with values)
VERSION
version 0.006
SYNOPSIS
use String::TagString;
# Parse a string into a set of tags:
my $tags = String::TagString->tags_from_string($string);
# Represent a set of tags as a string:
my $string = String::TagString->string_from_tags($tags);
DESCRIPTION
String::TagString enables Web 2.0 synergy by deconstructing and synthesizing folksonomic nomenclature into structured dynamic programming ontologies.
Also, it parses strings of "tags" into hashrefs, so you can tag whatever junk you want with strings.
A set of tags is an unordered set of simple strings, each possibly associated with a simple string value. This library parses strings of these tags into hashrefs, and turns hashrefs (or arrayrefs) back into these strings.
This string:
my $string = q{ beef cheese: peppers:hot };
Turns into this hashref:
my $tags = {
beef => undef,
cheese => '',
peppers => 'hot',
};
That hashref, of course, would turn back into the same string -- although sorting is not guaranteed.
Tag String Syntax
Tag strings are space-separated tags. Tag syntax may change slightly in the future, so don't get too attached to any specific quirk, but basically:
A tag is a name, then optionally a colon and value.
Tag names can contains letters, numbers, dots underscores, and dashes. They can't start with a dash, but they can start with an at sign.
A value is similar, but cannot start with an at sign.
Alternately, either a tag or a value can be almost anything if it enclosed in double quotes. (Internal double quotes can be escaped with a backslash.)
PERL VERSION
This library should run on perls released even a long time ago. It should work on any version of perl released in the last five years.
Although it may work on older versions of perl, no guarantee is made that the minimum required version will not be increased. The version may be increased for any reason, and there is no promise that patches will be accepted to lower the minimum required perl.
METHODS
tags_from_string
my $tag_hashref = String::TagString->tags_from_string($tag_string);
This will either return a hashref of tags, as described above, or raise an exception. It will raise an exception if the string can't be interpreted, or if a tag appears multiple times with conflicting definitions, like in these examples:
foo foo:
foo:1 foo:2
string_from_tags
my $string = String::TagString->string_from_tags( $tag_set );
This method returns a string representing the given tags. $tag_set
may be either a hashref or arrayref. An arrayref is treated like a hashref in which every value is undef.
Tag names and values will only be quoted if needed.
AUTHOR
Ricardo SIGNES <cpan@semiotic.systems>
CONTRIBUTORS
Ricardo SIGNES <rjbs@codesimply.com>
Ricardo Signes <rjbs@semiotic.systems>
COPYRIGHT AND LICENSE
This software is copyright (c) 2006 by Ricardo SIGNES.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.