markburgess/core — pull request #1 by markburgess (2012-06-17 19:18:33+00:00)
Title: Implement namespaces for bundles and bodies

We need an approach to namespaces that will do least damage to syntax,
will respect the knowledge map, and which has precendence in the language
so users don't have to learn new ideas.

There is precedence in CFEngine for using *prefixes* as namespace
modifers, e.g. in remoteclasses, and modules. It therefore seems
reasonable to stick to this approach.

e.g. remoteclasses("regex","server","yes","myprefix");

A namespace is a possibly overlapping set of bundles and bodies, formed from files.
A file declares itself to be in one or more namespaces by

body file control
{
namespace => "mynamespace";
}

The structures

Bundle *
Bodies *

need to be effectively associated arrays. As a first step, this can be accomplished by
adding a member, since Bundles/bodies might span multiple namespaces (this is normal cfengine
behaviour to allow categories to overlap)

To refer to "mymethod" in a different namespace

methods:

"demo" usebundle othernamespace_mymethod;

To access the private namespace, no prefix is required.

methods:

"demo usebundle mymethod;

Persistent classes are not covered in this patch. The propsal for them
is also to enforce a user-prefix, but by failing compilation if the
user does not define this explicitly, since it is not possible to
automatically map class-values that are present in expressions to a
namespace without significant risk. Thus we leave this up to the user
to make the user aware of the issue.