PGObject::Type::Registry(3pm) | User Contributed Perl Documentation | PGObject::Type::Registry(3pm) |
PGObject::Type::Registry - Registration of types for handing db types
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');
The PGObject type registry stores data for serialization and deserialization relating to the database.
Generally we like to separate applications into their own registries so that different libraries can be used in a more harmonious way.
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.
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
To unregister a type, you provide the dbtype and registry information, both of which are required. Note that at that this is rarely needed.
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.
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.
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.
Sometimes we need to see what types are registered. To do this, we can request a copy of the registry.
$name is required. If it does not exist an exception is thrown.
Returns a list of existing registries.
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:
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.
2020-08-19 | perl v5.30.3 |