perl-Data-Validate-Perl-0.02-alt1.noarch.rpm


Advertisement

Description

perl-Data-Validate-Perl - validates in-memory perl data using a specification

Property Value
Distribution ALT Linux Sisyphus
Repository Autoimports noarch
Package filename perl-Data-Validate-Perl-0.02-alt1.noarch.rpm
Package name perl-Data-Validate-Perl
Package version 0.02
Package release alt1
Package architecture noarch
Package type rpm
Category Development/Perl
Homepage -
License -
Maintainer -
Download size 21.91 KB
Installed size 21.91 KB
In order to understand internal of this module, working knowledge of
parsing, especially Yacc is required. Stop and grab a book on topic if
you are unsure what this is.
A common parsing mechanism applies state machine onto a string, such
as regular expression. This part is easy to follow. In this module a
Yacc state machine is used, but the target is not plain text but a
in-memory data structure - a tree made up by several perl
scalar/array/hash items.
The process to validate a data structure like that is a tree
traversal. The biggest challenge is how to put these 2 things
together.
The best way to figure a solution is, imagine each step to perform a
depth-first iteration on a tree. Each move can be abstracted as a
'token'. This is the key idea behind.
To elaborate, think how to validate a simple perl hash like below:
my %hash = (key1 => value1, key2 => value2, key3 => value3);
To iterate the hash key/value pairs, use a cursor to describe the
following states:
1. initial state: place the cursor onto hash itself;
2. 1st state: move cursor to key1;
3. 2nd state: move cursor to value1;
4. 3rd state: move cursor to key2;
5. 4th state: move cursor to value2;
6. 5th state: move cursor to key3;
7. 6th state: move cursor to value3;
A draft Yacc grammar written as:
root_of_hash: key1 value1 | key2 value2 | key3 value3
The state machine needs token to decide which sub-rule to walk
into. Looking onto the key1/2/3, the corresponding token can
simply be the value of themselves. That is:
root_of_hash: 'key1' value1 | 'key2' value2 | 'key3' value3
Note the quotes, they mark key1/2/3 as tokens. Next move to the hash
value. When the cursor points to a value, I do not care about the
actual value, instead I just want to hint the state machine that it is
a value. It requires another token to accept the state. How about a
plain text token - 'TEXT'. Finally the grammar to be:
root_of_hash: 'key1' 'TEXT' | 'key2' 'TEXT' | 'key3' 'TEXT'
How to apply the generated state machine to the hash validation then?
Each time the parser cannot determine which is next state, it asks the
lexer for a token. The simplest form of a lexer is just a function to
return the corresponding tokens for each state. At this point, you
might be able to guess how it works:
1. state machine initialized, it wants to move to next state, so it asks lexer;
2. the lexer holds the hash itself, it calls keys function, returns the first key as token, put the key returned into its memory;
3. by the time state machine got key1, it moves the cursor onto 'key1', then asks lexer again;
4. the lexer checks its memory and figures it returned 'key1' just now, time to return its vlaue, as the state machine has no interest on the actual value, it returns 'TEXT';
5. state machine finished the iteration of key1/value1 pair, asks for another token;
6. lexer returns 'key2' and keeps it in its own memory;
7. state machine steps into the sub-rule 'key2' 'TEXT';
...
The state loop is fairly straightforward. Parsing isn't that
difficult, huh :-)
To iterate a nested tree full of scalar/array/hash, other tokens are
introduced:
1. '[' ']' indicates start/end state of array traversal;
2. '{' '}' indicates start/end state of hash traversal;
3. to meet special need, certain rule actions are defined to set some state flags, which influence the decision that the lexer returns the value as 'TEXT', or the actual value string itself;
The state maintenance in lexer is made up by a stack, the stack
simulates a depth-first traversal:
1. when meets array, iterates array items one by one, if any item is another array or hash, push current array onto the stack together with an index marking where we are in this array. Iterates that item recursively;
2. similar strategy is applied to hash;
The left piece is a DSL to describe the tree structure. By the time
you read here, I am fairly confident you are able to figure it out
yourself by exercising various pieces of this module, below is a small
leaf-note:
1. gen_yp_rules function handles translation from data structure spec to corresponding Yacc grammar;
2. bottom section of this module contains the Lexer function and other routines the Parse::Yapp manpage requires to work (browse the module source to read);
3. the command-line utility `dvp_gen_parser' reads the spec file, calls gen_yp_rules to generate grammar, fits it into a file and calls `yapp' to create the parser module;
Wish you like this little article and enjoy playing with this module.

Alternatives

Package Version Architecture Repository
perl-Data-Validate-Perl - - -

Requires

Name Value
/usr/share/perl5 -
rpmlib(PayloadIsLzma) -

Provides

Name Value
perl(Data/Validate/Perl.pm) = 0.020
perl-Data-Validate-Perl = 0.02-alt1

Download

Type URL
Mirror ftp.altlinux.org
Binary Package perl-Data-Validate-Perl-0.02-alt1.noarch.rpm
Source Package perl-Data-Validate-Perl-0.02-alt1.src.rpm

Install Howto

  1. Add the following line to /etc/apt/sources.list:
    
    rpm [Sisyphus] http://ftp.altlinux.org/pub/distributions/ALTLinux/autoimports/Sisyphus noarch autoimports
    rpm [Sisyphus] http://ftp.altlinux.org/pub/distributions/ALTLinux/autoimports/Sisyphus noarch autoimports
    
  2. Update the package index:
    # sudo apt-get update
  3. Install perl-Data-Validate-Perl rpm package:
    # sudo apt-get install perl-Data-Validate-Perl

Files

Path
/usr/share/doc/perl-Data-Validate-Perl-0.02/Changes
/usr/share/doc/perl-Data-Validate-Perl-0.02/README
/usr/share/perl5/Data/
/usr/share/perl5/Data/Validate/Perl.pm

See Also

Package Description
perl-Data-Validate-Perl-scripts-0.02-alt1.noarch.rpm Data-Validate-Perl scripts
perl-Data-Validate-Sanctions-0.11-alt1.noarch.rpm Validate a name against sanctions lists
perl-Data-Validate-Sanctions-scripts-0.11-alt1.noarch.rpm Data-Validate-Sanctions scripts
perl-Data-Validate-Struct-0.1-alt2.noarch.rpm Validate recursive Hash Structures
perl-Data-Validate-Type-1.6.0-alt1_10.noarch.rpm Public interface to Params::Util offering data type validation functions
perl-Data-Validate-UUID-0.1.1-alt1.noarch.rpm Data Validator to check for well formed UUIDs
perl-Data-Validate-VIN-0.04-alt1.noarch.rpm Perl extension for basic validation of
perl-Data-Validate-WithYAML-0.18-alt1.noarch.rpm Validation framework that can be configured with YAML files
perl-Data-Validate-WithYAML-Plugin-Country-0.03-alt1.noarch.rpm check whether a given value is a valid country code
perl-Data-Validate-WithYAML-Plugin-EMail-0.04-alt1.noarch.rpm Plugin for Data::Validate::WithYAML to check email addresses
perl-Data-Validate-WithYAML-Plugin-IBAN-0.04-alt1.noarch.rpm check whether a given value is a valid IBAN
perl-Data-Validate-WithYAML-Plugin-NoSpam-0.04-alt1.noarch.rpm Plugin to check that a given text is no spam
perl-Data-Validate-WithYAML-Plugin-PasswordPolicy-0.03-alt1.noarch.rpm Plugin to check passwords against a policy
perl-Data-Validate-WithYAML-Plugin-Phone-0.06-alt1.noarch.rpm Plugin to check Phone numbers (basic check)
perl-Data-Validate-WithYAML-Plugin-URL-0.02-alt1.noarch.rpm Plugin to check URL
Advertisement
Advertisement