Not a developer? Go to MovableType.com

Documentation

Other Methods

$obj->clone([\%param])

Returns a clone of $obj. That is, a distinct object which has all the same data stored within it. Changing values within one object does not modify the other.

An optional except parameter may be provided to exclude particular columns from the cloning operation. For example, the following would clone the elements of the blog except the name attribute.

$blog->clone({ except => { name => 1 } });

$obj->clone_all()

Similar to the clone method, but also makes a clones the metadata information.

$obj->column_names()

Returns a list of the names of columns in $obj; includes all those specified to the installproperties method as well as the audit properties (created_on, modified_on, created_by, modified_by), if those were enabled in installproperties.

MT::Foo->driver()

$obj->driver()

Returns the ObjectDriver object that links this object with a database. This is a subclass of Data::ObjectDriver.

$obj->dbi_driver()

This method is similar to the ‘driver’ method, but will always return a DBI driver (a subclass of the Data::ObjectDriver::Driver::DBI class) and not a caching driver.

$obj->created_on_obj()

Returns a MT::DateTime object representing the moment when the object was first saved to the database.

$obj->column_as_datetime( $column )

Returns a MT::DateTime object for the specified datetime/timestamp column specified.

MT::Foo->set_bykey($keyterms, $value_terms)

A convenience method that loads whatever object matches the $key_terms argument and sets some or all of its fields according to the $value_terms. For example:

MT::Foo->set_by_key({name => 'Thor'},
                    {region => 'Norway', gender => 'Male'});

This loads the MT::Foo object having ‘name’ field equal to ‘Thor’ and sets the ‘region’ and ‘gender’ fields appropriately.

More than one term is acceptable in the $key_terms argument. The matching object is the one that matches all of the $key_terms.

This method only useful if you know that there is a unique object matching the given key. There need not be a unique constraint on the columns named in the $key_hash; but if not, you should be confident that only one object will match the key.

MT::Foo->get_bykey($keyterms)

A convenience method that loads whatever object matches the $key_terms argument. If no matching object is found, a new object will be constructed and the $key_terms provided will be assigned to it. So regardless of whether the key exists already, this method will return an object with the key requested. Note, however: if a new object is instantiated it is not automatically saved.

my $thor = MT::Foo->get_by_key({name => 'Thor'});
$thor->region('Norway');
$thor->gender('Male');
$thor->save;

The fact that it returns a new object if one isn’t found is to help optimize this pattern:

my $obj = MT::Foo->load({key => $value});
if (!$obj) {
    $obj = new MT::Foo;
    $obj->key($value);
}

This is equivalent to:

my $obj = MT::Foo->get_by_key({key => $value});

If you don’t appreciate the autoinstantiation behavior of this method, just use the load method instead.

More than one term is acceptable in the $key_terms argument. The matching object is the one that matches all of the $key_terms.

This method only useful if you know that there is a unique object matching the given key. There need not be a unique constraint on the columns named in the $key_hash; but if not, you should be confident that only one object will match the key.

$obj->cache_property($key, $code)

Caches the provided key (e.g. entry, trackback) with the return value of the given code reference (which is often an object load call) so that the value does not have to be recomputed each time.

$obj->clear_cache()

Clears any object-level cache data (from the cache_property method) that may existing.

$obj->column_def($name)

This method returns the value of the given $name column_defs propery.

$obj->column_defs()

This method returns all the column_defs of the property of the object.

Class->index_defs()

This method returns all the index definitions assigned to this class. This is the ‘indexes’ member of the properties installed for the class.

$obj->to_hash()

Returns a hashref containing column and metadata key/value pairs for the object. If the object has a blog relationship, it also populates data from that blog. For example:

my $entry_hash = $entry->to_hash();
# returns: { entry.title => "Title", entry.blog.name => "Foo", ... }

Class->joinon( $joincolumn, \%jointerms, \%joinargs )

A simple helper method that returns an arrayref of join terms suitable for the load and load_iter methods.

$obj->properties()

Returns a hashref of the object properties that were declared with the install_properties method.

$obj->to_xml()

Returns an XML representation of the object. This method is defined in MT/BackupRestore.pm - you must first use MT::BackupRestore to use this method.

$obj->restore_parent_ids()

TODO - Backup file contains parent objects’ ids (foreign keys). However, when parent objects are restored, their ids will be changed. This method is to match the old and new ids of parent objects for children objects to be correctly associated.

This method is defined in MT/BackupRestore.pm - you must first use MT::BackupRestore to use this method.

$obj->parent_names()

TODO - Should be overridden by subclasses to return correct hash whose keys are xml element names of the object’s parent objects and values are class names of them.

This method is defined in MT/BackupRestore.pm - you must first use MT::BackupRestore to use this method.

Class->class_handler($type)

Returns the appropriate Perl package name for the given type identifier. For example,

# Yields MT::Asset::Image
MT::Asset->class_handler('asset.image');

Class->class_label

Provides a descriptive name for the requested class package. This is a localized name, using the currently assigned language.

Class->class_label_plural

Returns a descriptive pluralized name for the requested class package. This is a localized name, using the currently assigned language.

Class->class_labels

Returns a hashref of type identifiers to class labels for all subclasses associated with a multiclassed object type. For instance:

# returns { 'asset' => 'Asset', 'asset.video' => 'Video', ... }
my $labels = MT::Asset->class_labels;

Class->columns_of_type(@types)

Returns an arrayref of column names that are of the requested type.

my @dates = MT::Foo->columns_of_type('datetime', 'timestamp')

Class->has_column( $name )

Returns a boolean as to whether the column $name is defined for this class.

Class->table_name()

Returns the database table name (including any prefix) for the class.

$obj->column_func( $column )

Creates an accessor/mutator method for column $column, returning it as a coderef. This method overrides the one in Data::ObjectDriver::BaseObject, by supporting metadata column as well.

$obj->call_trigger( ‘trigger_name’, @params )

Issues a call to any Class::Trigger triggers installed for the given object. Also invokes any MT callbacks that are registered using MT’s callback system. “pre” callbacks are invoked prior to triggers; “post” callbacks are invoked after triggers are called.

$obj->deflate

Returns a minimal representation of the object, including any metadata. See also Data::ObjectDriver::BaseObject.

Class->inflate( $deflated )

Inflates the deflated representation of the object $deflated into a proper object in the class Class. That is, undoes the operation $deflated = $obj->deflate() by returning a new object equivalent to $obj.

Class->install_pre_init_properties

This static method is used to install any class properties that were registered prior to the bootstrapping of MT plugins.

$obj->modified_by

A modified getter/setter accessor method for audited classes with a modified_by, modified_on columns. In the event this method is called to assign a modified_by value, it automatically updates the modified_on column as well.

$obj->nextprev( %params )

Method to determine adjacent objects, based on a date column and/or id. The %params hash provides the following elements:

  • direction - Either “next” or “previous”.
  • terms - Any additional terms to supply to the load method.
  • args - Any additional arguments to supply to the load method (such as a join).
  • by - The column to use to determine the next/previous object. By default for audited classes, this is created_on.
Back