Git Product home page Git Product logo

data-processor's Introduction

NAME

Data::Processor - Transform Perl Data Structures, Validate Data against a Schema, Produce Data from a Schema, or produce documentation directly from information in the Schema.

SYNOPSIS

use Data::Processor;
my $schema = {
  section => {
      description => 'a section with a few members',
      error_msg   => 'cannot find "section" in config',
      members => {
          foo => {
              # value restriction either with a regex..
              value => qr{f.*},
              description => 'a string beginning with "f"'
          },
          bar => {
              # ..or with a validator callback.
              validator => sub {
                  my $self   = shift;
                  my $parent = shift;
                  # undef is "no-error" -> success.
                  no strict 'refs';
                  return undef
                      if $self->{value} == 42;
              }
          },
          wuu => {
              optional => 1
          }
      }
  }
};

my $p = Data::Processor->new($schema);

my $data = {
  section => {
      foo => 'frobnicate',
      bar => 42,
      # "wuu" being optional, can be omitted..
  }
};

my $error_collection = $p->validate($data, verbose=>0);
# no errors :-)

# in case of errors:
# ------------------
# print each error on one line.
say $error_collection;

# same
for my $e ($error_collection->as_array){
    say $e;
    # do more..
}

DESCRIPTION

Data::Processor is a tool for transforming, verifying, and producing Perl data structures from / against a schema, defined as a Perl data structure.

METHODS

new

my $processor = Data::Processor->new($schema);

optional parameters: - indent: count of spaces to insert when printing in verbose mode. Default 4 - depth: level at which to start. Default is 0. - verbose: Set to a true value to print messages during processing.

validate

Validate the data against a schema. The schema either needs to be present already or be passed as an argument.

my $error_collection = $processor->validate($data, verbose=>0);

validate_schema

check that the schema is valid. This method gets called upon creation of a new Data::Processor object.

my $error_collection = $processor->validate_schema();

merge_schema

merges another schema into the schema (optionally at a specific node)

my $error_collection = $processor->merge_schema($schema_2);

merging rules:

  • merging transformers will result in an error
  • merge checks if all merged elements match existing elements
  • non existing elements will be added from merging schema
  • validators from existing and merging schema get combined

transform_data

Transform one key in the data according to rules specified as callbacks that themodule calls for you. Transforms the data in-place.

my $validator = Data::Processor::Validator->new($schema, data => $data)
my $error_string = $processor->transform($key, $schema_key, $value);

This is not tremendously useful at the moment, especially because validate() transforms during validation.

make_data

Writes a data template using the information found in the schema.

my $data = $processor->make_data(data=>$data);

make_pod

Write descriptive pod from the schema.

my $pod_string = $processor->make_pod();

AUTHOR

Matthias Bloch [email protected]

COPYRIGHT

Copyright 2015- Matthias Bloch

LICENSE

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

data-processor's People

Contributors

maettu avatar oetiker avatar hadfl avatar

Watchers

delkyd avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.