Morpheus::Key - class representing config key


version 0.46


    use Morpheus::Key qw(key);

    $key = Morpheus::Key->new("/foo/bar/x");
    $key = key("/foo/bar/y");

    say "key: $key";
    say "parts: ", join '/', @{ $key->parts };

    key("/foo/bar") ge key("/foo"); # true

    key("/foo") gt key("/bar"); # false
    key("/bar") gt key("/foo"); # also false


Morpheus configuration tree looks very much like a file system with directory structure and files. The names of these "directories" and "files" are called configuration keys. They are either represented by a string of the form /namespace/subnamespace/... (like a file path) or by the Morpheus::Key object. In fact Morpheus always casts the string key representation into an object to simplify its further usage.

Morpheus::Key class provides the following features:


The string representation of a key has a disadvantage that unequal strings may refer to the same namespace. Morpheus::Key class does a normalization of the key string so that equal namespaces were represented by equal strings. That normalization includes:

  • Removal of a trailing slash if present ("/a/b/c/" -> "/a/b/c").

  • Removal of repeated slashes ("/a//b///c" -> "/a/b/c").

  • Appending of a leading "/" if it is missing ("a/b" -> "/a/b"). We plan to remove this normalization step in the future as soon as we introduce a notion of "relative" keys.

We also consider the idea of making configuration keys case insensitive, but at the moment the key case is completely preserved.

Comparison operators

It is often required to check if two namespaces are equal or one namespace is a part of another one. Morpheus::Key class overloads the following operators to help do so: eq, ne, lt, le, gt, ge. Note that the set of configuration keys is only partially ordered, that is both $key1 ge $key2 and $key1 le $key2 may be false. Consider $key1 = "/a/b" and $key2 = "/a/c" for instance.

Transparent access to string key representation

Morpheus::Key objects return their string representation when stringified.

Splitting into namespace parts

$key->parts return an arrayref of key parts.


Andrei Mishchenko <>


This software is copyright (c) 2012 by Yandex LLC.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.