Ricardo SIGNES 😄


String::TagString - parse and emit tag strings (including tags with values)


version 0.005


  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);


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.)



  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


  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.


Ricardo SIGNES <rjbs@cpan.org>


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.