Provided by: libprophet-perl_0.750-1_all
NAME
Prophet::Record
DESCRIPTION
This class represents a base class for any record in a Prophet database.
METHODS
new { handle => Prophet::Replica, type => $type } Instantiates a new, empty Prophet::Record of type $type. declared_props 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. record_type 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. get_props Returns a hash of this record's properties as currently set in the database. exists When called on a loaded record, returns true if the record exists and false if it does not. 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 ''.) delete 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. changes 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). _validate_prop_name 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_prop_creator Default the creator of every record to the changeset_creator (usually the current user's email address.) default_prop_original_replica Default the original_replica of every record to the replica's uuid. validate_prop_from_recommended_values 'prop', $argsref 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. recommended_values_for_prop 'prop' 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. _default_summary_format 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. Example: '%s,$luid | %s,summary | %s,status' _summary_format 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. _parse_format_summary 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". format_summary 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. Dies with a message if there's an error in the format string that sprintf warn()s on. find_or_create_luid Finds the luid for the records uuid, or creates a new one. Returns the luid. history_as_string Returns this record's changesets as a single string. record_reference_methods Returns a list of method names that refer to other individual records collection_reference_methods Returns a list of method names that refer to collections