The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

Name

Object::Relation::Meta - Object::Relation class automation, introspection, and data validation

Synopsis

  package MyThingy;

  use strict;

  BEGIN {
      my $cm = Object::Relation::Meta->new(
        key         => 'thingy',
        plural_key  => 'thingies',
        name        => 'Thingy',
        plural_name => 'Thingies',
      );
      $cm->build;
  }

Description

This class inherits from Class::Meta to provide class automation, introspection, and data validation for Object::Relation classes. It overrides the behavior of Class::Meta to specify the use of the Object::Relation::Meta::Class subclass in place of Class::Meta::Class.

Any class created with Object::Relation::Meta will automatically have Object::Relation::Base pushed onto its @ISA array unless it already inherits from Object::Relation::Base.

Dynamic APIs

This class supports the dynamic loading of extra methods specifically designed to be used with particular Object::Relation data store implementations. This is so that the store APIs can easily dispatch to attribute objects, class objects, and data types to get data-store specific metadata without having to do extra work themselves. Data store implementors needing store-specific metadata methods should add them as necessary to the import() methods of Object::Relation::Meta::Class, Object::Relation::Meta::Attribute, and/or/ Object::Relation::Meta::Type

In general, however, Object::Relation users will not need to worry about loading data-store specific APIs, as the data stores will load them themselves. And since the methods should either be protected or otherwise transparent, no one else should use them, anyway.

As of this writing, only a single data-store specific API label is supported:

  use Object::Relation::Meta ':with_dbstore_api';

More may be added in the future.

Class Interface

Constructors

new

  my $cm = Object::Relation::Meta->new(%init);

Overrides the parent Class::Meta constructor in order to specify that the class class be Object::Relation::Meta::Classl, the attribute class be Object::Relation::Meta::Attribute, and that the method class be Object::Relation::Meta::Method. It also forces the key parameter to default to the last part of the package name, e.g., the key for the class My::Big::Fat::Cat would be "cat". This is to override Class::Meta's default of using the full class name for the key.

In addition to the parameters supported by Class::Meta->new, Object::Relation::Meta->new supports these extra attributes:

plural_key

The pluralized form of the key parameter. For example, if the key is "thingy", the plural key would be "thingies". If not defined, Lingua::EN::Inflect will be used to generate a plural key.

plural_name

The pluralized form of the name parameter. For example, if the name is "Thingy", the plural key would be "Thingies". If not defined, Lingua::EN::Inflect will be used to generate a plural name.

sort_by

This attribute is the name of an attribute or array reference of names of the attributes to use when sorting a list of objects of the class. If sort_by is not specified, it defaults to the first attribute declared after the uuid and state attributes.

extends

This attribute specifies a single Object::Relation class name that the class extends. Extension is similar to inheritance, only extended class objects have their own UUIDs and states, and there can be multiple extending objects for a single extended object (think one person acting as several users).

Class Attributes

class_class

  my $class_class = Object::Relation::Meta->class_class;
  Object::Relation::Meta->class_class($class_class);

The subclass or Class::Meta::Class that will be used to represent class objects. The value of this class attribute is only used at startup time when classes are loaded, so if you want to change it form the default, which is "Object::Relation::Meta::Class", do it before you load any Object::Relation classes.

attribute_class

  my $attribute_class = Object::Relation::Meta->attribute_class;
  Object::Relation::Meta->attribute_class($attribute_class);

The subclass or Class::Meta::Attribute that will be used to represent attribute objects. The value of this class attribute is only used at startup time when classes are loaded, so if you want to change it form the default, which is "Object::Relation::Meta::Attribute", do it before you load any Object::Relation classes.

method_class

  my $method_class = Object::Relation::Meta->method_class;
  Object::Relation::Meta->method_class($method_class);

The subclass or Class::Meta::Method that will be used to represent method objects. The value of this class method is only used at startup time when classes are loaded, so if you want to change it form the default, which is "Object::Relation::Meta::Method", do it before you load any Object::Relation classes.

Class Methods

for_key

  my $class = Object::Relation::Meta->for_key($key);

This method overrides the implementation inherited from Class::Meta to throw an exception no class object exists for the key passed as its sole argument. To use for_key() without getting an exception, call Class::Meta->for_key(), instead.

attr_for_key

  my $attribute = Object::Relation::Meta->attr_for_key('foo.bar');

This method returns a Object::Relation::Meta::Attribute object for a given class key and attribute. The class key and attribute name are separated by a dot (".") in the argument. In this above example, the attribute "bar" would be returned for the class with the key "foo".

Copyright and License

Copyright (c) 2004-2006 Kineticode, Inc. <info@obj_relode.com>

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