PGObje...gistry(3pm)
π NAME π
okay so bestie, welcome to PGObje...gistry(3pm) β say hi to PGObject::Type::Registry, the little module that handles registration of types for handing db types. yes, that's literally what it does. it's giving type-bouncer-at-the-club energy π
β¨ SYNOPSIS β¨
here's the whole vibe in one look, no cap:
PGObject::Type::Registry->add_registry('myapp'); # required
PGObject::Type::Registry->register_type(
registry => 'myapp', dbtype => 'int4',
apptype => 'PGObject::Type::BigFloat'
);
# to get back a type:
my $number = PGObject::Type::Registry->deserialize(
registry => 'myapp', dbtype => 'int4',
dbstring => '1023'
);
# To get registry data:
my %registry = PGObject::Type::Registry->inspect(registry => 'myapp');
π¦ DESCRIPTION π¦
so the PGObject type registry stores data for serialization and deserialization relating to the database. that's the whole main character moment. it's the place where your app remembers "oh, THIS db type maps to THAT app type" π«Ά
π USE π
generally we like to separate applications into their own registries so that different libraries can be used in a more harmonious way. harmonious, yes β like a group chat where nobody is beefing. β¨
π CREATING A REGISTRY π
you must create a registry before using it, bestie. not optional, not a suggestion, it's a rule. this is there to ensure that we make sure that subtle problems are avoided and strings returned when serialized types expected. π€
the good news: this is idempotent and repeat calls are safe β so go off, call it twice, it won't be weird about it.
the bad news: there is literally no ability to remove an existing registry. like, none. though you can loop through and remove the existing registrations if you need to clean house. π§Ή
new_registry(name)
that's the one, that's the call. make your registry, then live your life. π
π REGISTERING A TYPE π
register_type
Args:
registry => 'default', #warning thrown if not specified
dbtype => [required], #exception thrown if not specified
apptype => [required], #exception thrown if not specified
Use:
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. π₯
from_db will be provided two arguments. the first is the string from the database and the second is the type provided. that second argument is optional and passed along for the db interface class's use. iykyk.
A warning is thrown if no
not me quoting the original verbatim but likeβ¦ bestie the source page literally stops there mid-sentence π we leave it exactly as we found it, dangling clause and all. π
π 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 β so like, don't stress about it unless you actually need it, fr fr. π
unregister_type
yeah. that's the move. bye-bye type. π¦
π DESERIALIZING A VALUE π
deserialize
this function deserializes a data from a db string. β¨
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.
this function returns the output of the from_db method. that's it, that's the whole thing. π«Ά
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 "deserialize". E.g.: π
my $deserializer = PGObject::Type::Registry->deserializer(dbtype => $type);
my $value = $deserializer->($dbvalue);
mandatory argument is dbtype. the registry arg should be provided but if not, a warning will be issued and 'default' will be used.
this function returns the output of the "from_db" method of the registered class. π
rowhash_deserializer
this returns a coderef to deserialize data from a call to e.g. "fetchrow_arrayref". the coderef should be called with a single argument: the hash that holds the row values with the keys being the column names. πΈ
mandatory argument is "types", which is either an arrayref or hashref.
- if it's 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
"dbtype"parameter of the"deserialize"method). - if it's an arrayref, an additional argument
"columns"is required, containing the names of the columns in the same order as"types". β
the registry arg should be provided but if not, a warning will be issued and 'default' will be used.
this function returns the output of the "from_db" method of the registered class. same energy as always. π
π₯ INSPECTING A REGISTRY π₯
sometimes we need to see what types are registered. π to do this, we can request a copy of the registry.
inspect($name)
$name is required. if it does not exist, an exception is thrown. no name, no peek. π«
list()
returns a list of existing registries. iconic, brief, does exactly what it says. β¨
π COPYRIGHT AND LICENSE π
COPYRIGHT (C) 2017-2021 The LedgerSMB Core Team
redistribution and use in source and compiled forms with or without modification, are permitted provided that the following conditions are met:
- 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.
- 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.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) "AS IS" 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(S) BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
and that's the whole page, bestie!! π this one was generated by perl v5.36.0 on 2023-11-24 β so if you're reading this in the future, yes it's vintage, yes it's still serving. stay registered, stay unserialized-until-you-need-to-be. mwah ππ β¨
π¦ where this page comes from
- debian trixie: libpgobject-perl 2.4.0-1 Β· BSD-2-Clause
- ubuntu noble: libpgobject-perl 2.4.0-1 Β· BSD-2-Clause
- ubuntu resolute: libpgobject-perl 2.4.0-1 Β· BSD-2-Clause
- ubuntu stonking: libpgobject-perl 2.4.0-1 Β· BSD-2-Clause
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms