Object::Relation::Meta::Type - Object::Relation Data type validation and accessor building


      key     => "state",
      name    => "State",
      builder => 'Object::Relation::Meta::AccessorBuilder',
      raw     => sub { ref $_[0] ? shift->value : shift },
      store_raw   => sub { shift->store_value },
      check   => sub {
          UNIVERSAL::isa($_[0], 'Object::Relation::DataType::State')
              or throw_invalid(['Value "[_1]" is not a valid [_2] object',
                                $_[0], 'Object::Relation::DataType::State']);
          throw_invalid(['Cannot assign permanent state'])
            if $_[0] == Object::Relation::DataType::State->PERMANENT;


This class subclasses Class::Meta::Type to provide additional attributes. These attributes can optionally be set via the call to new(), and may be fetched via their accessors.

Dynamic APIs

This class supports the dynamic loading of extra methods specifically designed to be used with particular Object::Relation data store implementations. See Object::Relation::Meta for details. The supported labels are:


Adds a new() constructor to overload the parent. The purpose is to add a raw() accessor that returns the database ID of an referenced object, rather than the object itself.

Instance Interface

Instance Methods


  my $code = $type->raw;

Returns a code reference to get the raw value of a type. Used internally by Object::Relation::Meta::Attribute.

The code reference should simply expect the value returned by the get accessor as its sole argument. It can then take whatever steps are necessary to return a serializable value. For example, if for a Object::Relation::DataType::DateTime data type, we might want to get back a string in ISO-8601 format in the UTC time zone. The raw code reference to do so might look like this:

  sub { shift->clone->set_time_zone('UTC')->iso8601 }


  my $code = $type->store_raw;

Returns a code reference to get the store raw value of a type. Used internally by Object::Relation::Meta::Attribute. In general, it will exactly the same as raw(), but may occasionally be different, as when different data stores require different raw values for a particular data type.

For the Object::Relation::DataType::Duration type, for example, raw() would return an ISO-8601 string representation, while store_raw() would return one string representation for the PostgreSQL data store, and a 0-padded ISO-8601 string for all other data stores.

As with the raw() code reference. The store_raw code reference should expect the value returned from an attribute's get() method.


  my $code = $type->bake;

Returns a code reference to set the raw value of a type without actually needing to set an object value. Used internally by Object::Relation::Meta::Attribute.

Copyright and License

Copyright (c) 2004-2006 Kineticode, Inc. <>

This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.