def register(func=None, name=None):
    """
    Expose compiler to factory.

    :param func: the callable to expose
    :type func: callable
    :param name: name of format
    :type name: str

    It can be used as a decorator::

        @register(name='my:validator')
        def my_validator(obj):
            if obj is True:
                return obj
            raise ValidationError('obj is not true')

    or as a function::

        def my_validator(obj):
            if obj is True:
                return obj
            raise ValidationError('obj is not true')

        @register(name='my:validator')

    """
    if not name:
        raise CompilationError('Name is required')
    if not func:
        return partial(register, name=name)
    return FormatRegistry.register(name, func)