NAME

PGObject::Type::Registry - Registration of types for handing db types

SYNOPSIS

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

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

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.

COPYRIGHT AND LICENSE

COPYRIGHT (C) 2017-2020 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.