++ed by:

2 PAUSE users

Jesse Vincent
and 1 contributors




This class represents a base class for any record in a Prophet database.


new { handle => Prophet::Replica, type => $type }

Instantiates a new, empty "" in Prophet::Record of type $type.


Returns a sorted list of the names of the record's declared properties. Declared properties are always validated even if the user provides no value for that prop. This can be used for such things as requiring records to have certain props in order to be created, for example.


Returns the record's type.

register_reference $class, $accessor, $foreign_class, @args

Registers a reference to a foreign class to this record. The foreign class must be of type Prophet::Collection or Prophet::Record, or else a fatal error is triggered.

register_collection_reference $accessor, $collection_class, by => $key_in_model

Registers and creates an accessor in the current class to the associated collection $collection_class, which refers to the current class by $key_in_model in the model class of $collection_class.

register_record_reference $accessor, $record_class, by => $key_in_model

Registers and creates an accessor in the current class to the associated record $record_class, which refers to the current class by $key_in_model in the model class of $collection_class.

create { props => { %hash_of_kv_pairs } }

Creates a new Prophet database record in your database. Sets the record's properties to the keys and values passed in.

Automatically canonicalizes and then validates the props.

Upon successful creation, returns the new record's uuid. In case of failure, returns undef.

load { uuid => $UUID } or { luid => $UUID }

Given a UUID or LUID, look up the LUID or UUID (the opposite of what was given) in the database. Set this record's LUID and UUID attributes, and return the LUID or UUID (whichever wasn't given in the method call).

Returns undef if the record doesn't exist in the database.

set_prop { name => $name, value => $value }

Updates the current record to set an individual property called $name to $value

This is a convenience method around "set_props".

set_props { props => { key1 => val1, key2 => val2} }

Updates the current record to set all the keys contained in the props parameter to their associated values. Automatically canonicalizes and validates the props in question.

In case of failure, returns false.

On success, returns true.


Returns a hash of this record's properties as currently set in the database.

prop $name

Returns the current value of the property $name for this record. (This is a convenience method wrapped around "get_props").

delete_prop { name => $name }

Deletes the current value for the property $name. (This is currently equivalent to setting the prop to ''.)


Deletes this record from the database. (Note that it does _not_ purge historical versions of the record)

changesets { limit => $int }

Returns an ordered list of changeset objects for all changesets containing changes to the record specified by this record object.

Note that changesets may include changes to other records.

If a limit is specified, this routine will only return that many changesets, starting from the changeset containing the record's creation.


Returns an ordered list of all the change objects that represent changes to the record specified by this record object.

uniq @list

The List::MoreUtils::uniq function (taken from version 0.21).

Returns a new list by stripping duplicate values in @list. The order of elements in the returned list is the same as in @list. In scalar context, returns the number of unique elements in @list.

    my @x = uniq 1, 1, 2, 2, 3, 5, 3, 4; # returns 1 2 3 5 4
    my $x = uniq 1, 1, 2, 2, 3, 5, 3, 4; # returns 5

validate_props $propsref

Takes a reference to a props hash and validates each prop in the hash or in the PROPERTIES attribute that has a validation routine (validate_prop_$prop).

Dies if any prop fails validation. Returns true on success. Returns false if any prop is not allowable (prop name fails validation).


A hook to allow forcing users to only use certain prop names.

Currently just returns true for all inputs.

canonicalize_props $propsref

Takes a hashref to a props hash and canonicalizes each one if a canonicalize_prop_$prop routine is available.

Returns true on completion.

default_props $props_ref

Takes a reference to a hash of props and looks up the defaults for those props, if they exist (by way of default_prop_$prop routines). Sets the values of the props in the hash to the defaults.


Default the creator of every record to the changeset_creator (usually the current user's email address.)


Default the original_replica of every record to the replica's uuid.

Checks to see if the given property has a valid value and returns true if so. If not, adds an error message to $argsref->{errors}{prop} and returns false.

Given a record property, return an array of the values that should usually be associated with this property.

If a property doesn't have a specific range of values, undef is returned.

This is mainly intended for use in prop validation (see validate_prop_from_recommended_values). Recommended values for a prop are set by defining methods called _recommended_values_for_prop_$prop in application modules that inherit from Prophet::Record.


A string of the default summary format for record types that do not define their own summary format.

A summary format should consist of format_string,field pairs, separated by | characters.

Fields that are not property names must start with the $ character and be handled in the atom_value routine.


'%s,$luid | %s,summary | %s,status'


Tries to find the summary format for the record type. Returns _default_summary_format if nothing better can be found.

_atomize_summary_format [$format]

Splits a summary format into pieces (separated by arbitrary whitespace and the | character). Returns the split list.

If no summary format is supplied, this routine attempts to find one by calling _summary_format.


Parses the summary format for this record's type (or the default summary format if no type-specific format exists).

Returns a list of hashrefs to hashes which contain the following keys: format, prop, value, and formatted

(These are the format string, the property to be formatted, the value of that property, and the atom formatted according to format_atom, respectively.)

If no format string is supplied in a given format atom, %s is used.

If a format atom $value's value does not start with a $ character, it is swapped with the value of the prop $value (or the string "(no value)".

All values are filtered through the function atom_value.


Returns a formatted string that is the summary for the record. In an array context, returns a list of

atom_value $value_in

Takes an input value from a summary format atom and returns either its output value or itself (because it is a property and its value should be retrieved from the props attribute instead).

For example, an input value of "$uuid" would return the record object's uuid field.

format_atom $string => $value

Takes a format string / value pair and returns a formatted string for printing.


Finds the luid for the records uuid, or creates a new one. Returns the luid.


Returns this record's changesets as a single string.


Returns a list of method names that refer to other individual records


Returns a list of method names that refer to collections