.\" Automatically generated by Pod::Man 4.14 (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 .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . 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 "PGObject::Type::Registry 3pm" .TH PGObject::Type::Registry 3pm "2023-11-24" "perl v5.36.0" "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" PGObject::Type::Registry \- Registration of types for handing db types .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& PGObject::Type::Registry\->add_registry(\*(Aqmyapp\*(Aq); # required \& \& PGObject::Type::Registry\->register_type( \& registry => \*(Aqmyapp\*(Aq, dbtype => \*(Aqint4\*(Aq, \& apptype => \*(AqPGObject::Type::BigFloat\*(Aq \& ); \& \& # to get back a type: \& my $number = PGObject::Type::Registry\->deserialize( \& registry => \*(Aqmyapp\*(Aq, dbtype => \*(Aqint4\*(Aq, \& dbstring => \*(Aq1023\*(Aq \& ); \& \& # To get registry data: \& my %registry = PGObject::Type::Registry\->inspect(registry => \*(Aqmyapp\*(Aq); .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" The PGObject type registry stores data for serialization and deserialization relating to the database. .SH "USE" .IX Header "USE" Generally we like to separate applications into their own registries so that different libraries can be used in a more harmonious way. .SH "CREATING A REGISTRY" .IX Header "CREATING A REGISTRY" You must create a registry before using it. This is there to ensure that we make sure that subtle problems are avoided and strings returned when serialized types expected. This is idempotent and repeat calls are safe. There is no abiltiy to remove an existing registry though you can loop through and remove the existing registrations. .SS "new_registry(name)" .IX Subsection "new_registry(name)" .SH "REGISTERING A TYPE" .IX Header "REGISTERING A TYPE" .SS "register_type" .IX Subsection "register_type" Args: .PP .Vb 3 \& registry => \*(Aqdefault\*(Aq, #warning thrown if not specified \& dbtype => [required], #exception thrown if not specified \& apptype => [required], #exception thrown if not specified .Ve .PP Use: .PP This registers a type for use by PGObject. PGObject calls with the same registry key will serialize to this type, using the from_db method provided. .PP from_db will be provided two arguments. The first is the string from the database and the second is the type provided. The second argument is optional and passed along for the db interface class's use. .PP A warning is thrown if no .SH "UNREGISTERING A TYPE" .IX Header "UNREGISTERING A TYPE" To unregister a type, you provide the dbtype and registry information, both of which are required. Note that at this time this is rarely needed. .SS "unregister_type" .IX Subsection "unregister_type" .SH "DESERIALIZING A VALUE" .IX Header "DESERIALIZING A VALUE" .SS "deserialize" .IX Subsection "deserialize" This function deserializes a data from a db string. .PP Mandatory args are dbtype and dbstring The registry arg should be provided but if not, a warning will be issued and \&'default' will be used. .PP This function returns the output of the from_db method. .SS "deserializer" .IX Subsection "deserializer" This returns a coderef to deserialize data from a db string. The coderef should be called with a single argument: the argument that would be passed as 'dbstring' into \f(CW\*(C`deserialize\*(C'\fR. E.g.: .PP .Vb 2 \& my $deserializer = PGObject::Type::Registry\->deserializer(dbtype => $type); \& my $value = $deserializer\->($dbvalue); .Ve .PP Mandatory argument is dbtype. The registry arg should be provided but if not, a warning will be issued and \&'default' will be used. .PP This function returns the output of the \f(CW\*(C`from_db\*(C'\fR method of the registered class. .SS "rowhash_deserializer" .IX Subsection "rowhash_deserializer" This returns a coderef to deserialize data from a call to e.g. \&\f(CW\*(C`fetchrow_arrayref\*(C'\fR. The coderef should be called with a single argument: the hash that holds the row values with the keys being the column names. .PP Mandatory argument is \f(CW\*(C`types\*(C'\fR, which is either an arrayref or hashref. In case of a hashref, the keys are the names of the columns to be expected in the data hashrefs. The values are the types (same as the \f(CW\*(C`dbtype\*(C'\fR parameter of the \f(CW\*(C`deserialize\*(C'\fR method). In case of an arrayref, an additional argument \f(CW\*(C`columns\*(C'\fR is required, containing the names of the columns in the same order as \f(CW\*(C`types\*(C'\fR. .PP The registry arg should be provided but if not, a warning will be issued and \&'default' will be used. .PP This function returns the output of the \f(CW\*(C`from_db\*(C'\fR method of the registered class. .SH "INSPECTING A REGISTRY" .IX Header "INSPECTING A REGISTRY" Sometimes we need to see what types are registered. To do this, we can request a copy of the registry. .SS "inspect($name)" .IX Subsection "inspect($name)" \&\f(CW$name\fR is required. If it does not exist an exception is thrown. .SS "\fBlist()\fP" .IX Subsection "list()" Returns a list of existing registries. .SH "COPYRIGHT AND LICENSE" .IX Header "COPYRIGHT AND LICENSE" \&\s-1COPYRIGHT\s0 (C) 2017\-2021 The LedgerSMB Core Team .PP Redistribution and use in source and compiled forms with or without modification, are permitted provided that the following conditions are met: .IP "\(bu" 4 Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer as the first lines of this file unmodified. .IP "\(bu" 4 Redistributions in compiled form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the source code, documentation, and/or other materials provided with the distribution. .PP \&\s-1THIS SOFTWARE IS PROVIDED BY THE AUTHOR\s0(S) \*(L"\s-1AS IS\*(R" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR\s0(S) \s-1BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES\s0 (\s-1INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES\s0; \&\s-1LOSS OF USE, DATA, OR PROFITS\s0; \s-1OR BUSINESS INTERRUPTION\s0) \s-1HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\s0 (\s-1INCLUDING NEGLIGENCE OR OTHERWISE\s0) \s-1ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\s0