internal package Foswiki::Contrib::DBCacheContrib::Map

See PublishedAPI for packages intended to be used by Plugin and Contrib authors, or browse all packages.
See also Developing plugins, Developer's Bible, Technical Overview

package Foswiki::Contrib::DBCacheContrib::Map

This is an interface that is implemented by all back-end stores (archivists). A Map is basically a hash table, and can be tied to a perl hash.

Objects of this class are created using the newMap interface defined by Foswiki::Contrib::DBCacheContrib::Archivist. You can use references in the content of a Map, but you can only refer to other objects that were created using the same Archivist. If you point anywhere else, expect fireworks.

The keys in a map operate like any other keys, except that key names beginning with underscore are interpreted as internal references to objects that must be "weak" i.e. are not used in garbage collection (see the doc on Scalar::Util::weaken for more info).

ObjectMethod parse($string)

Parse a bunch of key-value expressions in $string and add them to the map. $string is a space-or-comma separated list of key=value pairs, where values can be enclosed in quotes (either single or double). Keys must be alphanumeric plus '.'. For example:

this.that='the other', one3three=four five="5"

get($k, $root) -> datum

  • $k - key
  • $root what # refers to
Get the value corresponding to key $k; return if not set.

Subfield syntax
  • get("X",$r) will get the subfield named X.
  • get("X.Y",$r) will get the subfield Y of the subfield named X.
  • get("[X]",$r) = will get the subfield named =X (so X[Y] and X.Y are synonymous)..
  • # means "reset to root". So get("#.Y", $r) will return the subfield =Y of $r (assuming $r is a map!), as will get("#[Y]".

Where the result of a subfield expansion is another object (a Map or an Array) then further subfield expansions can be used. For example,
get("UserTable[0].Surname", $web);

See also Foswiki::Contrib::DBCacheContrib::Array for syntax that applies to arrays.

set($k, $v)

  • $k - key
  • $v - value
Set the given key, value pair in the map.

size() -> integer

Get the size of the map

remove($index) -> old value

  • $index - integer index
Remove an entry at an index from the map. Return the old value.

search($search) -> search result

Search the map for keys that match with the given object. values. Return a Foswiki::Contrib::DBCacheContrib::Array of matching keys.

getKeys() -> @keys

Overridable method that returns a list even when the object isn't tied.

getValues() -> @values

Overridable method that returns a list even when the object isn't tied.

toString($limit, $level, $strung) -> string

  • $limit - recursion limit for expansion of elements
  • $level - currentl recursion level
Generates an HTML string representation of the object.

Topic revision: r1 - 21 Nov 2014, ProjectContributor
This site is powered by FoswikiCopyright © by the contributing authors. All material on this site is the property of the contributing authors.
Ideas, requests, problems regarding GSICS Wiki? Send feedback