PGObject::Type::Registry(3pm)

PGObject::Type::Registry3pm

Registration of types for handing db types

Usage

  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');

Overview

The PGObject type registry stores data for serialization and deserialization relating to the database.

Use

Generally we like to separate applications into their own registries so that different libraries can be used in a more harmonious way.

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.

new_registry(name)

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. The second argument is optional and passed along for the db interface class's use.

A warning is thrown if no

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.

unregister_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.

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. 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 "dbtype" parameter of the "deserialize" method). In case of 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.

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.

list()

Returns a list of existing registries.

Releases

4 releases since Debian 10 (Buster); the text changed 3 times.

  1. 10
  2. 11
  3. 12
  4. 13

From libpgobject-perl 2.4.0-1 in Debian 13 (Trixie). Parsed by carta from the page's man source.