The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Email::MIME::Kit::Validator::Rx - validate assembly stash with Rx (from JSON in kit)

VERSION

version 0.200002

SYNOPSIS

Email::MIME::Kit::Validator::Rx is a Validator plugin for Email::MIME::Kit that allows an Rx schema to be used to validate kit assembly data.

A simple mkit's manifest might include the following:

  {
    "renderer" : "TT",
    "validator": "Rx",
    "header"   : [ ... mail headers ... ],
    "type"     : "text/plain",
    "path"     : "path/to/template.txt"
  }

In this simple configuration, the use of "Rx" as the validator will load the plugin in its simplest configuration. It will look for a file called rx.json in the kit and will load its contents (as JSON) and use them as a schema to validate the data passed to the it's assemble method.

More complex configurations are simple.

This configuration supplies an alternate filename for the JSON file:

  "validator": [ "Rx", { "path": "rx-schema.json" } ],

This configuration supplies the schema definition inline:

  "validator": [
    "Rx",
    {
      "schema": {
        "type"   : "//rec",
        "required": {
          "subject": "//str",
          "rcpt"   : { "type": "/perl/obj", "isa": "Email::Address" }
        }
      }
    }
  ]

Notice, above, the /perl/ prefix. By default, Data::Rx::TypeBundle::Perl is loaded along with the core types.

If a combine argument is given, multiple schema definitions may be provided. They will be combined with the logic named by the combine argument. In this release, only "all" is valid, and will require all schemata to match. Here is an example:

  "validator": [
    "Rx",
    {
      "combine": "all",
      "path"   : "rx.json",
      "schema" : [
        { "type": "//rec", "rest": "//any", "required": { "foo": "//int" } },
        { "type": "//rec", "rest": "//any", "required": { "bar": "//int" } },
      ]
    }
  ]

This definition will create an //all schema with three entries: the schema found in rx.json and the two schemata given in the array value of schema.

PERL VERSION

This module should work on any version of perl still receiving updates from the Perl 5 Porters. This means it should work on any version of perl released in the last two to three years. (That is, if the most recently released version is v5.40, then this module should work on both v5.40 and v5.38.)

Although it may work on older versions of perl, no guarantee is made that the minimum required version will not be increased. The version may be increased for any reason, and there is no promise that patches will be accepted to lower the minimum required perl.

AUTHOR

Ricardo SIGNES <cpan@semiotic.systems>

CONTRIBUTOR

Ricardo Signes <rjbs@semiotic.systems>

COPYRIGHT AND LICENSE

This software is copyright (c) 2022 by Ricardo SIGNES.

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