Heap::Elem::Ref is used to wrap object reference values into an element that can be managed on a heap. Each referenced object must have a method cmp which can compare itself with any of the other objects that have references on the same heap. These comparisons must be consistant with normal arithmetic. The top of the heap will have the smallest (according to cmp) element still remaining. (See Heap::Elem::RefRev if you want the heap to always return the largest element.)