Name

Object::Relation::Meta::Class - Object::Relation class metadata class.

Synopsis

my $class = MyThingy->my_class;
my $thingy = MyThingy->new;

print "Examining object of ", ($class->abstract ? "abstract " : ''),
  "class ", $class->package, $/;

print "\nConstructors:\n";
for my $ctor ($class->constructors) {
    print "  o ", $ctor->name, $/;
}

print "\nAttributes:\n";
for my $attr ($class->attributes) {
    print "  o ", $attr->name, " => ", $attr->get($thingy) $/;
}

print "\nMethods:\n";
for my $meth ($class->methods) {
    print "  o ", $meth->name, $/;
}

Description

This class inherits from Class::Meta::Class to provide class metadata for Object::Relation classes. See the Class::Meta documentation for details on meta classes. See the "Accessor Methods" for the additional attributes.

The import() method is merely a placeholder to ensure that Object::Relation::Meta can dispatch its import symbols to a variety of classes and "just work". This class is specifically documented as accepting those symbols. See the documentation for Object::Relation::Meta for more information.

Class Interface

Constructor

new

This constructor overrides the parent class constructor from Class::Meta::Class in order to check for extends, type_of, and mediates parameters and, if any is present, convert it from a class key to the corresponding class object.

Instance Interface

Accessor Methods

plural_key

my $plural_key = $class->plural_key;

The pluralized form of the key attribute, such as "thingies".

name

my $name = $class->name;

Returns the localized form of the name of the class, such as "Thingy".

plural_name

my $plural_name = $class->plural_name;

Returns the localized plural form of the name of the class, such as "Thingies".

sort_by

my $sort_by  = $class->sort_by;
my @sort_bys = $class->sort_by;

Returns the name of the attribute to use when sorting a list of objects of this class. If more than one attribute has been specified for sorting, they can all be retrieved by calling sort_by() in an list context.

extends

my $extends  = $class->extends;

Returns a Object::Relation::Meta::Class object representing a class that this class extends. Extension is different than inheritance, in that the object in the extended class can correspond to one or more instances of objects in the extending class.

type_of

my $type_of  = $class->type_of;

Returns a Object::Relation::Meta::Class object representing a class that this class is a type of.

mediates

my $mediates  = $class->mediates;

Returns a Object::Relation::Meta::Class object representing a class that this class mediates.

Instance Methods

ref_attributes

my @ref_attrs = $class->ref_attributes;

Returns a list of attributes that reference other Object::Relation::Meta objects. Equivalent to

my @ref_attrs = grep { $_->references } $self->attributes;

only more efficient, thanks to build-time caching.

direct_attributes

my @direct_attrs = $class->direct_attributes;

Returns a list of attributes that do not reference other Object::Relation::Meta objects. Equivalent to

my @direct_attrs = grep { ! $_->references } $self->attributes;

only more efficient, thanks to build-time caching.

persistent_attributes

my @persistent_attrs = $class->persistent_attributes;

Returns a list of persistent attributes -- that is, those that should be stored in a data store, as opposed to used arbitrarily in the class. Equivalent to

my @persistent_attrs = grep { $_->persistent } $self->attributes;

only more efficient, thanks to build-time caching.

collection_attributes

my @collection_attrs = $class->collection_attributes;

Returns a list of collection attributes -- that is, attributes that are collections of objects. Equivalent to

my @collection_attrs = grep { $_->collection_of } $self->attributes;

only more efficient, thanks to build-time caching.

contained_in

my @containers = $class->contained_in;

if ( my $container = $class->contained_in($key) ) {
    ...
}

If instances of this class are available in collections of other classes, this method will return all of those classes, sorted by key. If given a specific key, returns the class for that key, if the current class can be contained in the key class. Otherwise, returns false.

build

This private method overrides the parent build() method in order to cache the a list of the referenced attributes for use by ref_attributes().

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.