What is the best practice when the intent is to make a package available to all namespaces?

Hello,

Still related to the unit test with coverage support project, one goal is to make that package available to everyone.

One possible way I already know of is that all fully qualified class names (ie, the package + the class name) start with %, which mean that on installation all classes will end up in the %SYS namespace, but this requires that the install be done as a user with the necessary privileges to write to %SYS.

This is rather convenient in my situation, sure; but is there another way which does not require such privileges? If yes, is there a way to make this package available to anybody who wants to use it?

Answers

See the documentation on the special %ALL "namespace".

%ALL allows for globals/routines/packages to be mapped to all namespaces. Your %Installer (if you're using one) can check to see if this is set up and create it if not, and add the mappings. You might want to map the packages and perhaps system-wide settings your code uses, but perhaps not any namespace-specific data.

Hmm...

I don't use an %Installer... And in a default Caché installation there is no %ALL namespace.

What would you say is the less intrusive solution, then?

I really would recommend creating a %All namespace (if there isn't already one), via %Installer or something that works similarly.

One projects on the intersystems-ru github, Caché Web Terminal, has the same requirement (use from any namespace); this class might be helpful for reference: https://github.com/intersystems-ru/webterminal/blob/master/export/WebTerminal/Installer.xml. It doesn't actually use %Installer, so configuration changes are implemented in COS instead of being generated based on XML, but it works similarly.

Particularly, see methods CreateAllNamespace and Map/UnMap. You should be able to adapt these without too much effort. If your code coverage project eventually has a UI, then the web application setup method will be useful too (for simple installation).

First of all you should know that namespace it is not final destination for any data in Caché. Namespace just defines easy access to set of data, but all data stores in databases. And any security settings uses on Databases not for Namespaces. Data

There some reasons why you can't just use any %-classes; 

  • By default all %-classes, appeared in CACHELIB database, which read-only by default after installation.
  • CACHELIB database after any installation process, will be overwritten with all you custom content.

Actually first point is not so truly, because InterSystems gives us one chance to create %-class, without loosing it after next upgrade. You should use %Z* or %z* name for classes and routines (some names have already reserved for InterSystems use), and in this case that classes will be stored at CACHESYS database, which available to write, and any upgrade will not rewrite such classes. 

So, you should read this page in documentation, to know more about names, which names you can't use, and how to name recommend.

I was not asking about how to name things but about how to make this package accessible to everyone

Only two way to do it, Mapping with %ALL namespace as suggested Timothy, or %-class which as you already know by default mapped to all namespace, but I said how you should name your class, to send this class to Write-enabled database.