Mike Eldridge > Parse-Yapp-KeyValue-0.1 > Parse::Yapp::KeyValue

Download:
Parse-Yapp-KeyValue-0.1.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Module Version: 0.1   Source  

NAME ^

Parse::Yapp::KeyValue - parser for simple key/value pairs

DESCRIPTION ^

parse a string of simple key/value pairs and store the results in a hash reference for easy access. Parse::KeyValue correctly handles escaped quotes as well as escaped backslashes.

Parse::KeyValue will parse the following example string:

     AL=53 AK=54 AB=55 TN="home sweet home" =$

into a hashref with the following contents:

     {
         ''   => '$',
         'AL' => '53',
         'TN' => 'home sweet home',
         'AK' => '54',
         'AB' => '55'
     }

multiple identical keys are treated as arrays. the string

     A=1 A=2 A=3

will return a hash reference with the following contents:

     { A => [ 1, 2, 3 ] }

tokens without an associated key name will be treated as pairs with an empty string for the key. the string

     yeah alabama "crimson tide"

will return a hash reference with the following contents:

     { '' => [ 'yeah', 'alabama', 'crimson tide' ] }

SYNOPSIS ^

 my $str  = 'A=1 K=2 B=3 A=4';
 my $kv   = new Parse::Yapp::KeyValue;
 my $href = $kv->parse($str);

 print $href ? Dumper $href : "parse failed\n";

TODO ^

 - configurable delimiter
 - flags to alter behavior in the event of
   multiple keys (error, overwrite last value,
   keep first value)
 - flag to require ALL values be inside an array
   reference, not just keys with multiple values

METHODS ^

new

instantiates a new Parse::Yapp::KeyValue object. no arguments are currently accepted.

parse

parses the supplied string and returns a hash reference containing the parsed data. in the even that parsing fails, undef is returned.

AUTHOR ^

mike eldridge <diz@cpan.org>

LICENSE ^

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.8 or, at your option, any later version of Perl 5 you may have available.

syntax highlighting: