logo
Free, unlimited AI code reviews that run on commit
git-lrc git-lrc GitHub Install Now We'd appreciate a star git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt

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

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)

Description

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

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.

Name

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

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

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

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

Use

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

See Also