Ricardo SIGNES 😄


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


version 0.200001


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": [
      "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": [
      "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.


Ricardo SIGNES <rjbs@cpan.org>


This software is copyright (c) 2013 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.