.\" -*- mode: troff; coding: utf-8 -*- .\" Automatically generated by Pod::Man 5.01 (Pod::Simple 3.43) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. .ie n \{\ . ds C` "" . ds C' "" 'br\} .el\{\ . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Data::Pond 3pm" .TH Data::Pond 3pm 2024-01-11 "perl v5.38.2" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH NAME Data::Pond \- Perl\-based open notation for data .SH SYNOPSIS .IX Header "SYNOPSIS" .Vb 1 \& use Data::Pond qw($pond_datum_rx); \& \& if($expr =~ /\eA$pond_datum_rx\ez/o) { ... \& # and other regular expressions \& \& use Data::Pond qw(pond_read_datum pond_write_datum); \& \& $datum = pond_read_datum($text); \& $text = pond_write_datum($datum); \& $text = pond_write_datum($datum, { indent => 0 }); .Ve .SH DESCRIPTION .IX Header "DESCRIPTION" This module is concerned with representing data structures in a textual notation known as "Pond" (\fIP\fRerl-based \fIo\fRpen \fIn\fRotation for \fId\fRata). The notation is a strict subset of Perl expression syntax, but is intended to have language-independent use. It is similar in spirit to JSON, which is based on JavaScript, but Pond represents fewer data types directly. .PP The data that can be represented in Pond consist of strings (of characters), arrays, and string-keyed hashes. Arrays and hashes can recursively (but not cyclically) contain any of these kinds of data. This does not cover the full range of data types that Perl or other languages can handle, but is intended to be a limited, fixed repertoire of data types that many languages can readily process. It is intended that more complex data can be represented using these basic types. The arrays and hashes provide structuring facilities (ordered and unordered collections, respectively), and strings are a convenient way to represent atomic data. .PP The Pond syntax is a subset of Perl expression syntax, consisting of string literals and constructors for arrays and hashes. Strings may be single-quoted or double-quoted, or may be decimal integer literals. Double-quoted strings are restricted in which backslash sequences they can use: the permitted ones are the single-character ones (such as \f(CW\*(C`\en\*(C'\fR), \&\f(CW\*(C`\ex\*(C'\fR sequences (such as \f(CW\*(C`\exe3\*(C'\fR and \f(CW\*(C`\ex{e3}\*(C'\fR), and octal digit sequences (such as \f(CW\*(C`\e010\*(C'\fR). Non-ASCII characters are acceptable in quoted strings. Strings may also appear as pure-ASCII barewords, when they directly precede \f(CW\*(C`=>\*(C'\fR in an array or hash constructor. Array (\f(CW\*(C`[]\*(C'\fR) and hash (\f(CW\*(C`{}\*(C'\fR) constructors must contain data items separated by \f(CW\*(C`,\*(C'\fR and \f(CW\*(C`=>\*(C'\fR commas, and can have a trailing comma but not adjacent commas. Whitespace is permitted where Perl allows it. Control characters are not permitted, except for whitespace outside strings. .PP A Pond expression can be \f(CW\*(C`eval\*(C'\fRed by Perl to yield the data item that it represents, but this is not the recommended way to do it. Any use of \f(CW\*(C`eval\*(C'\fR on data opens up security issues. Instead use the "pond_read_datum" function of this module, which does not use Perl's parser but directly parses the restricted Pond syntax. .PP This module is implemented in XS, with a pure Perl backup version for systems that can't handle XS. .SH "REGULAR EXPRESSIONS" .IX Header "REGULAR EXPRESSIONS" Each of these regular expressions corresponds precisely to part of Pond syntax. The regular expressions do not include any anchors, so to check whether an entire string matches a production you must supply the anchors yourself. .PP The regular expressions with \f(CW\*(C`_ascii_\*(C'\fR in the name match the subset of the grammar that uses only ASCII characters. All Pond data can be expressed using only ASCII characters. .ie n .IP $pond_string_rx 4 .el .IP \f(CW$pond_string_rx\fR 4 .IX Item "$pond_string_rx" .PD 0 .ie n .IP $pond_ascii_string_rx 4 .el .IP \f(CW$pond_ascii_string_rx\fR 4 .IX Item "$pond_ascii_string_rx" .PD A string literal. This may be a double-quoted string, a single-quoted string, or a decimal integer literal. It does not accept barewords. .ie n .IP $pond_array_rx 4 .el .IP \f(CW$pond_array_rx\fR 4 .IX Item "$pond_array_rx" .PD 0 .ie n .IP $pond_ascii_array_rx 4 .el .IP \f(CW$pond_ascii_array_rx\fR 4 .IX Item "$pond_ascii_array_rx" .PD An array \f(CW\*(C`[]\*(C'\fR constructor. .ie n .IP $pond_hash_rx 4 .el .IP \f(CW$pond_hash_rx\fR 4 .IX Item "$pond_hash_rx" .PD 0 .ie n .IP $pond_ascii_hash_rx 4 .el .IP \f(CW$pond_ascii_hash_rx\fR 4 .IX Item "$pond_ascii_hash_rx" .PD A hash \f(CW\*(C`{}\*(C'\fR constructor. .ie n .IP $pond_datum_rx 4 .el .IP \f(CW$pond_datum_rx\fR 4 .IX Item "$pond_datum_rx" .PD 0 .ie n .IP $pond_ascii_datum_rx 4 .el .IP \f(CW$pond_ascii_datum_rx\fR 4 .IX Item "$pond_ascii_datum_rx" .PD Any permitted expression. This may be a string literal, array constructor, or hash constructor. .SH FUNCTIONS .IX Header "FUNCTIONS" .IP pond_read_datum(TEXT) 4 .IX Item "pond_read_datum(TEXT)" \&\fITEXT\fR is a character string. This function parses it as a Pond-encoded datum, with optional surrounding whitespace, returning the represented item as a Perl native datum. \f(CW\*(C`die\*(C'\fRs if a malformed item is encountered. .IP "pond_write_datum(DATUM[, OPTIONS])" 4 .IX Item "pond_write_datum(DATUM[, OPTIONS])" \&\fIDATUM\fR is a Perl native datum. This function serialises it as a character string using Pond encoding. The data to be serialised can recursively contain Perl strings, arrays, and hashes. Numbers are implicitly stringified, and \f(CW\*(C`undef\*(C'\fR is treated as the empty string. \&\f(CW\*(C`die\*(C'\fRs if an unserialisable datum is encountered. .Sp \&\fIOPTIONS\fR, if present, must be a reference to a hash, containing options that control the serialisation process. The recognised options are: .RS 4 .IP \fBindent\fR 4 .IX Item "indent" If \f(CW\*(C`undef\*(C'\fR (which is the default), no optional whitespace will be added. Otherwise it must be a non-negative integer, and the datum will be laid out with whitespace (where it is optional) to illustrate the structure by indentation. The number given must be the number of leading spaces on the line on which the resulting element will be placed. If whitespace is added, the element will be arranged to end on a line of the same indentation, and all intermediate lines will have greater indentation. .IP \fBundef_is_empty\fR 4 .IX Item "undef_is_empty" If false (the default), \f(CW\*(C`undef\*(C'\fR will be treated as invalid data. If true, \f(CW\*(C`undef\*(C'\fR will be serialised as an empty string. .IP \fBunicode\fR 4 .IX Item "unicode" If false (the default), the datum will be expressed using only ASCII characters. If true, non-ASCII characters may be used in string literals. .RE .RS 4 .RE .SH "SEE ALSO" .IX Header "SEE ALSO" Data::Dumper, JSON::XS, "eval" in perlfunc .SH AUTHOR .IX Header "AUTHOR" Andrew Main (Zefram) .SH COPYRIGHT .IX Header "COPYRIGHT" Copyright (C) 2009 PhotoBox Ltd .PP Copyright (C) 2010, 2012, 2017 Andrew Main (Zefram) .SH LICENSE .IX Header "LICENSE" This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.