logo
Free, unlimited AI code reviews that run on commit
git-lrc git-lrc GitHub Install Now We'd appreciate a star git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt

PGObject::Util::PseudoCSV - Tuple/Array parsing and serialization for PGObject

Acknowledgements

Author

       Chris Travers, "<chris.travers at gmail.com>"

Bugs

       Please  report  any  bugs or feature requests to "bug-pgobject-util-pseudocsv at rt.cpan.org", or through
       the web interface at <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=PGObject-Util-PseudoCSV>.  I will be
       notified, and then you'll automatically be notified of progress on your bug as I make changes.

Description

       PostgreSQL can represent tuples and arrays in a text format that is almost like CSV.  Unfortunately this
       format has a number of gotchas which render existing CSV-parsers useless.  This module provides basic
       parsing functions to other programs for db interface purposes.  With this module you can both parse
       pseudocsv representations of tuples and arrays and you can create them from a list.

       The API's here assume you send one (and only one) pseudo-csv record to the API at once.  These may be
       nested, so a single tuple can contain arrays of tuples which can contain arrays of tuples ad infinitum
       but the parsing only goes one layer deep tuple-wise so that handling classes have an opportunity to re-
       parse with appropriate type information. Naturally this has performance implications, so depth in SQL
       structures passed should be reasonably limited.

       As of 2.0, we no longer automatically call deserialization functions from the parser itself.  At his
       point the calling classes MUST call the deserializer themselves but this is far easier since this has
       been moved to a separate service in PGObject 2.0.  This avoids an unnecessary dependency on PGObject and
       ensures that the module is more geneally useful.

Export

       pseudocsv_to_hash
       pseudocsv_parse
       to_pseudocsv

Name

       PGObject::Util::PseudoCSV - Tuple/Array parsing and serialization for PGObject

Subroutines/Methods

pseudocsv_parse
       This  does  a  one-level deep parse of the pseudo-csv, with additional levels in arrays.  When a tuple is
       encountered it is instantiated as its type but a subarray is parsed for more entities.

       Only one pseudocsv record can be passed in at once, but embedded newlines are properly handled.

   pcsv2hash($literal_string,@cols);
       Returns a hash from a tuple literal or array literal.

   hash2pcsv($hashref,@cols)
       Takes an ordered list of columns and a hashref and returns a tuple literal

   pseudocsv_tohash($coldata,$colnames)DEPRECATED
       Takes an arrayref of column data and an arrayref of column names and returns a hash.  This  is  mostly  a
       helper function designed to help with tuple types.

       This interface is deprecated and will go away in 2.0.  Use pcsv2hash instead.

   to_pseudocsv($datalist,$is_tuple)
       Takes a list of data and an is_tuple argument and creates a pseudocsv.

       Note:   this  does  not check for array sanity.  If you are not careful you can get arrays returned which
       are not valid SQL arrays.  Remember that SQL arrays have every item being the  same  size,  and  all  SQL
       arrays are are regular in size (so all 1 and 2d arrays follow the same form as mathematical matrices).

Support

       You can find documentation for this module with the perldoc command.

           perldoc PGObject::Util::PseudoCSV

       You can also look for information at:

       •   RT: CPAN's request tracker (report bugs here)

           <http://rt.cpan.org/NoAuth/Bugs.html?Dist=PGObject-Util-PseudoCSV>

       •   AnnoCPAN: Annotated CPAN documentation

           <http://annocpan.org/dist/PGObject-Util-PseudoCSV>

       •   CPAN Ratings

           <http://cpanratings.perl.org/d/PGObject-Util-PseudoCSV>

       •   Search CPAN

           <http://search.cpan.org/dist/PGObject-Util-PseudoCSV/>

Synopsis

       This is a parser and constructor for PostgreSQL text representations of tuples and arrays.

       To parse:

       For a tuple, we'd typically:

          my @list = pseudocsv_parse($text_representation);

       We can then arrange the hash as:

          my $hashref = pseudocsv_to_hash(\@list, \@col_list);

       Which we can combine as:

          my $hashref =  pseudocsv_to_hash(
                            pseudocsv_parse($text_representation),
                            \@col_list
          );

Version

       Version 2

See Also