Slaven Rezić > WE_Framework-0.097_03 > WE::DB::ObjBase

Download:
WE_Framework-0.097_03.tar.gz

Dependencies

Annotate this POD

Module Version: 1.16   Source  

NAME ^

WE::DB::ObjBase - base class for WE_Framework object databases

SYNOPSIS ^

    use base qw(WE::DB::ObjBase);

DESCRIPTION ^

METHODS

Please see also WE::DB::Base for inherited methods.

children($object_id)

Like children_ids, but return objects.

parents($object_id)

Like parent_ids, but return parent objects instead.

versions($object_id)

Like version_ids, but return version objects instead.

objectify_params($id_or_obj, ...)

For each parameter in the list, change the argument to be an object of the database.

idify_params($id_or_obj, ...)

For each parameter in the list, change the argument to be an object identifier if it was an object, or leave it as it was.

replace_content_from_file($object_id, $filename)

Like replace_content, but get contents from file.

walk($object_id, $sub_routine, @args)

Traverse the object hierarchie, beginning at the object with id $object_id. For each object, $sub_routine is called with the object id and optional @args. Note that the subroutine is not called for the start object itself.

If there's no persistent connection to the database (i.e. the database was not accessed with -connect => 1), then using connect_if_necessary is advisable for better performance.

Here are some examples for using walk.

Get the number of descendent objects from the folder with Id $folder_id. The result is in the $obj_count variable:

    my $obj_count = 0;
    $objdb->walk($folder_id, sub {
                     my($id, $ref) = @_;
                     $$ref++;
                 }, \$obj_count);
    warn "There are $obj_count objects in $folder_id\n";

Get all released descendant objects. The released state should be recorded in the Release_State member. The resulting list is a flat array.

    my @results;
    $objdb->walk($folder_id, sub {
                     my($id) = @_;
                     my $obj = $objdb->get_object($id);
                     if ($obj->Release_State eq 'released') {
                         push @results, $obj;
                     }
                 });
    # The released objects are in @results.

If you want to break the recursion on a condition, simply use an eval-block and die on the condition. See the source code of name_to_objid method for an example.

walk uses postorder traversal, that is, subtrees first, node later.

Note that the start object itself is not included in the traversal and the subroutine will not be called for it.

The returned value of the last callback called with be returned.

walk_preorder($object_id, $sub_routine, @args)

This is like walk, but uses preorder instead of postorder, that is, node first, children later.

Note that the start object itself will be included in the traversal. This is different from the walk method.

In preorder walk, the traversal of subtrees can be avoided by setting the global variable $WE::DB::Obj::prune to a true value.

walk_up($object_id, $sub_routine, @args)

Same as walk, but walk the tree up, that is, traverse all parents from the object to the root.

walk_up_preorder($object_id, $sub_routine, @args)

Same as walk_up, but traverse in pre-order, that is, from the object to the root. Note that the object itself is also included in the traversal.

In preorder walk, the further traversal of parents can be avoided by setting the global variable $WE::DB::Obj::prune to a true value.

whole_tree([$objid])

Return the whole (sub)tree of $objid. If $objid is not given, then return the whole tree. The elements of the tree are structured in a nested array. Each element is a hash of the following elements: Id, Title and isFolder.

_undirty($object)

Return the object with all Dirty flags set to 0.

is_locked($object_id)

Return true if the object is locked by someone else.

lock($object_id, -type => $lock_type)

Lock the object $object_id. Only single objects can be locked (no folder hierarchies). Locking must be handled in the client by using is_locked(). The $lock_type may have the following values:

SessionLock

This lock should only be valid for this session. If the user closes the session (either by a logout or by closing the browser window), then the lock will be invalidated.

PermanentLock

This lock lasts over session ends.

Return the object itself.

Now, it should be checked programmatically whether the lock can be set or not (by looking at the value is_locked). It is not clear what is the right solution, because there are version control systems where breaking locks is possible (RCS).

unlock($object_id)

Unlock the object with id $object_id.

Return the object itself.

Now, it should be checked programmatically whether the lock can be unset or not (by looking at the value is_locked). It is not clear what is the right solution, because there are version control systems where breaking locks is possible (RCS).

pathobjects($object_or_id [, $parent_obj])

For the object or id $object_or_id, the object path is returned. This is similar to the pathname method, but returns a list of objects instead of a pathname.

If $parent_obj is given as a object, then the returned pathname is only a partial path starting from this parent object.

pathobjects_with_cache($object_or_id [, $parent_obj], $cache_hash_ref)

As pathobjects, but also use a cache for a faster access.

name_to_objid($name)

Return the object id for the object containing the Attribute Name=$name. If there is no such object, undef is returned. Note: This method may or may not be efficient, depending whether there is an index database (NameDB) or not.

AUTHOR ^

Slaven Rezic - slaven@rezic.de

SEE ALSO ^

WE::DB::Base, WE::DB.

syntax highlighting: