<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">NAME
    Data::Rx::Tools::ShareDirValidator - A Simple base class for generating
    simple validators based on Data::Rx

VERSION
    version 0.1.0

SYNOPSIS
      package Foo;
      use Data::Rx::Tools::ShareDirValidator;
      use parent 'Data::Rx::Tools::ShareDirValidator';

      sub filename { 'schema' } # default value.
      sub suffix  {'.json'} # default value.

      1;

      ...

    Later:

      use Foo;
      Foo-&gt;check({ some =&gt; [ 'data', 'structure' ] }) # true/false

      1;

DESCRIPTION
    The purpose of this is to make creating a portable validator with
    Data::Rx as painless as possible, while still permitting you to keep the
    specification itself separate from the actual implementation.

METHODS
  filename
    Defaults to just 'schema' and is combined with "suffix" to form the name
    of the file to load from the share directory.

  suffix
    Defaults to '.json' and is combined with "filename" to form the name of
    the file.

  check
      ClassName-&gt;check( $data )

    Does all the lifting behind this module and validates the data in $data.

  decode_file
    Defaults to a decoder that can read JSON files.

      -&gt;decode_file( Path::Class::File $file )

    Override this method with something else if you don't want JSON files.

IMPLEMENTATION INSTRUCTIONS
    1. Create package 'Foo' and fill it with the generic boilerplate to
    extend the base class.
    2. Generate your Data::Rx schema in the format you desire ( ideally JSON
    ) and place it in the modules "Share" directory.
        ( i.e.: With Dist::Zilla, you would do this:

          [ModuleSharedirs]
          Foo = sharedir/Foo

        or something similar. )

    3. Ship your distribution and/or install it.
    4. Use it by simply doing:
          use Foo;
          if( Foo-&gt;check({ datastructure =&gt; [] })

        passing the data structure you need validated to check().

EXTENDING
    By default, we assume you want JSON for everything, so by default, the
    suffix is ".json", and the default deserialiser is as follows:

      sub decode_file {
        my ( $self, $file ) = @_;
        require JSON;
        return JSON-&gt;new()-&gt;utf8(1)-&gt;relaxed(1)-&gt;decode( scalar $file-&gt;slurp() );
      }

    If you want to use a file format other than JSON, overriding the suffix
    and decode_file sub is required.

    Note: $file in this context is a "file" from Path::Class, which is why
    we can just do "slurp()" on it.

AUTHOR
    Kent Fredric &lt;kentnl@cpan.org&gt;

COPYRIGHT AND LICENSE
    This software is copyright (c) 2011 by Kent Fredric &lt;kentnl@cpan.org&gt;.

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

</pre></body></html>