package Crypt::OpenToken::Serializer; use strict; use warnings; our $WS = qr/[\t ]/; # WS, as per OpenToken spec (just tab and space) our $CRLF = qr/[\r\n]/; # CRLF, as per OpenToken spec sub thaw { my $str = shift; my %data; while ($str) { my ($key, $val); my ($quote, $remainder); ($key, $remainder) = ($str =~ /^$WS*(\S+)$WS*=$WS*(.*)$/s); if ($remainder =~ /^['"]/) { ($quote, $val, $remainder) = ($remainder =~ /^(['"])(.*?)(? double and single quotes must be escaped by a preceding backslash. =item * Encoded with UTF-8 and is guaranteed to support the transport of multi-byte characters. =item * Key names might not be unique. OpenToken supports multiple values for a key name by simply adding another key-value pair. =item * Key names are case-sensitive. It is RECOMMENDED that all key names be lowercase and use hyphens to separate "words". =back =head1 METHODS =over =item Crypt::OpenToken::Serializer::thaw($string) Thaws the given serialzed data, returning a hash of data back to the caller. If the data contained any repeating keys, those are represented in the hash as having an ARRAYREF as a value. =item Crypt::OpenToken::Serializer::freeze(%data) Freezes the given data, returning a serialized string back to the caller. =back =head1 AUTHOR Graham TerMarsch (cpan@howlingfrog.com) =head1 COPYRIGHT & LICENSE C is Copyright (C) 2010, Socialtext, and is released under the Artistic-2.0 license. =cut