Adding Primitives

slaughter allows you to write your policies in a combiantion of pure-perl, and a set of primitive functions it provides.

This page describes two ways that you may add your own primitives.


100% local primitives

If you wish to create primitives which are entirely local to your situation, environment, or company this should be as simple as implementing a new class.

In the slaughter-generated code the following line is included:

use Slaughter;

The implementation of the module actually results in loading both a generic module, inside which the 100% pure-perl primitives are implemented, and a pair of environment-specific modules, for example:

# implementation of pure-perl primitives.
use Slaughter::API::generic;

# implementation of OS-dependant primitives (e.g. packing-related).
use Slaughter::API::linux;

# optional local module containing your additions.
use Slaughter::API::Local::linux;

The last part of the module-name comes from the "$^O" perl variable. By default the last module, with the ::Local:: component to its name, will not exist and the failure to load this will be silently ignored.

If you implement, and install, this module upon your system(s) any included code will become available to you and your slaughter scripts - This allows you to write new primitives which are 100% separate and distinct from those included in the release.


Primitives you intend to submit for inclusion

If you wish to submit a new primitive for inclusion in the Slaughter distribution then instead of making it local-only you should implement it in the core code.

As alluded to in the HACKING file you need to choose where to implement it:

100% pure perl?

If the implementation of your primitive is 100% pure & portable perl you need implement it only once in the module Slaughter::API::generic.


You need to place a stub which outputs an error message in Slaughter::API::generic, then implement it in each of the platform-specific modules. This includes:

  • Slaughter::API::linux
  • Slaughter::API::netbsd
  • Slaughter::API::openbsd

Once your implementations are complete you should run the test suite by executing:

make test

If all tests continue to pass then you may mail your changes to me.