Codebase list libdata-validate-struct-perl / a1e71168-3f0b-4dca-9238-2aa8ae3ff56b/upstream
Import upstream version 0.1+git20160602.1.f407cf9 Debian Janitor 2 years ago
5 changed file(s) with 107 addition(s) and 100 deletion(s). Raw diff Collapse all Expand all
0 0.11
1 o typos
2
3 o added cpanfile
4
05 0.10
16 o fixed RT#101884
27 - _trim() only removed 1st whitespace
44 "Per Carlson <pelle@cpan.org>"
55 ],
66 "dynamic_config" : 1,
7 "generated_by" : "ExtUtils::MakeMaker version 7.02, CPAN::Meta::Converter version 2.142690",
7 "generated_by" : "ExtUtils::MakeMaker version 7.44, CPAN::Meta::Converter version 2.150010",
88 "license" : [
99 "perl_5"
1010 ],
1111 "meta-spec" : {
1212 "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec",
13 "version" : "2"
13 "version" : 2
1414 },
1515 "name" : "Data-Validate-Struct",
1616 "no_index" : {
4444 "url" : "https://github.com/TLINDEN/Data-Validate-Struct"
4545 }
4646 },
47 "version" : "0.1"
47 "version" : 0.11,
48 "x_serialization_backend" : "JSON::PP version 4.04"
4849 }
77 configure_requires:
88 ExtUtils::MakeMaker: '0'
99 dynamic_config: 1
10 generated_by: 'ExtUtils::MakeMaker version 7.02, CPAN::Meta::Converter version 2.142690'
10 generated_by: 'ExtUtils::MakeMaker version 7.44, CPAN::Meta::Converter version 2.150010'
1111 license: perl
1212 meta-spec:
1313 url: http://module-build.sourceforge.net/META-spec-v1.4.html
2323 Regexp::Common: '0'
2424 resources:
2525 repository: https://github.com/TLINDEN/Data-Validate-Struct
26 version: '0.1'
26 version: 0.11
27 x_serialization_backend: 'CPAN::Meta::YAML version 0.018'
00 #
11 # Makefile.PL - build file for Date::Validate::Struct
22 #
3 # Copyright (c) 2007-2014 T. v.Dein <tom |AT| cpan.org>.
3 # Copyright (c) 2007-2016 T. v.Dein <tom |AT| cpan.org>.
44 # All Rights Reserved. Std. disclaimer applies.
55 # Artistic License, same as perl itself. Have fun.
66 #
88 use ExtUtils::MakeMaker;
99
1010 WriteMakefile(
11 NAME => 'Data::Validate::Struct',
12 VERSION_FROM => 'Struct.pm',
11 NAME => 'Data::Validate::Struct',
12 VERSION_FROM => 'Struct.pm',
1313 ABSTRACT => 'Validate recursive hash structures',
1414 LICENSE => 'perl',
1515 AUTHOR => [
16 'Thomas v.Dein <tom@cpan.org>',
17 'Per Carlson <pelle@cpan.org>',
18 ],
19 clean => { FILES => '*~ */*~' },
20 PREREQ_PM => {
21 'Regexp::Common' => 0,
22 'Data::Validate' => '0.06',
23 'Data::Validate::IP' => '0.18',
24 },
25 dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', },
26 test => { TESTS => 't/*.t' },
16 'Thomas v.Dein <tom@cpan.org>',
17 'Per Carlson <pelle@cpan.org>',
18 ],
19 clean => { FILES => '*~ */*~' },
20 PREREQ_PM => {
21 'Regexp::Common' => 0,
22 'Data::Validate' => '0.06',
23 'Data::Validate::IP' => '0.18',
24 },
25 dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', },
26 test => { TESTS => 't/*.t' },
2727 'META_MERGE' => {
2828 resources => {
2929 repository => 'https://github.com/TLINDEN/Data-Validate-Struct',
3030 },
3131 },
3232
33 );
33 );
3434
00 #
1 # Copyright (c) 2007-2015 T. v.Dein <tlinden |AT| cpan.org>.
1 # Copyright (c) 2007-2016 T. v.Dein <tlinden |AT| cpan.org>.
22 # All Rights Reserved. Std. disclaimer applies.
33 # Artistic License, same as perl itself. Have fun.
44 #
2020 use Data::Validate qw(:math is_printable);
2121 use Data::Validate::IP qw(is_ipv4 is_ipv6);
2222
23 our $VERSION = 0.10;
23 our $VERSION = 0.11;
2424
2525 use vars qw(@ISA);
2626
3131 @EXPORT_OK = qw(add_validators);
3232
3333 %__ValidatorTypes = (
34 # primitives
35 int => sub { return defined(is_integer($_[0])); },
36 hex => sub { return defined(is_hex($_[0])); },
37 oct => sub { return defined(is_oct($_[0])); },
38 number => sub { return defined(is_numeric($_[0])); },
39
40 word => qr(^[\w_\-]+$),
41 line => qr/^[^\n]+$/s,
42
43 text => sub { return defined(is_printable($_[0])); },
44
45 regex => sub {
46 my $r = ref $_[0];
47 return 1 if $r eq 'Regexp';
48 if ($r eq '') {
49 # this is a bit loosy but should match most regular expressions
50 # using the qr() operator, but it doesn't check if the expression
51 # is valid. we could do this by compiling it, but this would lead
52 # to exploitation possiblities to programs using the module.
53 return $_[0] =~ qr/^qr ( (.).*\1 | \(.*\) | \{.*\} ) $/x;
54 }
55 return 0;
56 },
57
58 # via imported regexes
59 uri => qr(^$RE{URI}$),
60 cidrv4 => sub {
61 my ($p, $l) = split(/\//, $_[0]);
62 return defined(is_ipv4($p)) && defined(is_between($l, 0, 32));
63 },
64 ipv4 => sub { defined(is_ipv4($_[0])) },
65 quoted => qr/^$RE{delimited}{ -delim => qr(\') }$/,
66 hostname => qr(^$host$),
67
68 ipv6 => sub { defined(is_ipv6($_[0])) },
69 cidrv6 => sub {
70 my ($p, $l) = split('/', $_[0]);
71 return defined(is_ipv6($p)) && defined(is_between($l, 0, 128));
72 },
73
74 # matches perl style scalar variables
75 # possible matches: $var ${var} $(var)
76 vars => qr/(?<!\\) ( \$\w+ | \$\{[^\}]+\} | \$\([^\)]+\) )/x,
77
78 # closures
79
80 # this one doesn't do a stat() syscall, so keep cool
81 path => sub { return file_name_is_absolute($_[0]); },
82
83 # though this one does it - it stat()s if the file exists
84 fileexists => sub { return stat($_[0]); },
85
86 # do a dns lookup on given value, this also fails if
87 # no dns is available - so be careful with this
88 resolvablehost => sub { return gethostbyname($_[0]); },
89
90 # looks if the given value is an existing user on the host system
91 user => sub { return (getpwnam($_[0]))[0]; },
92
93 # same with group
94 group => sub { return getgrnam($_[0]); },
95
96 # int between 0 - 65535
97 port => sub {
98 if ( $_[0] =~ /^$port$/ && ($_[0] > 0 && $_[0] < 65535) )
99 { return 1; } else { return 0; } },
100
101 # variable integer range, use: range(N1 - N2)
102 range => sub {
103 if ( defined(is_integer($_[0])) && ($_[0] >= $_[2] && $_[0] <= $_[3]) )
104 { return 1; } else { return 0; } },
105
106 # just a place holder at make the key exist
107 optional => 1,
108 );
34 # primitives
35 int => sub { return defined(is_integer($_[0])); },
36 hex => sub { return defined(is_hex($_[0])); },
37 oct => sub { return defined(is_oct($_[0])); },
38 number => sub { return defined(is_numeric($_[0])); },
39
40 word => qr(^[\w_\-]+$),
41 line => qr/^[^\n]+$/s,
42
43 text => sub { return defined(is_printable($_[0])); },
44
45 regex => sub {
46 my $r = ref $_[0];
47 return 1 if $r eq 'Regexp';
48 if ($r eq '') {
49 # this is a bit loosy but should match most regular expressions
50 # using the qr() operator, but it doesn't check if the expression
51 # is valid. we could do this by compiling it, but this would lead
52 # to exploitation possiblities to programs using the module.
53 return $_[0] =~ qr/^qr ( (.).*\1 | \(.*\) | \{.*\} ) $/x;
54 }
55 return 0;
56 },
57
58 # via imported regexes
59 uri => qr(^$RE{URI}$),
60 cidrv4 => sub {
61 my ($p, $l) = split(/\//, $_[0]);
62 return defined(is_ipv4($p)) && defined(is_between($l, 0, 32));
63 },
64 ipv4 => sub { defined(is_ipv4($_[0])) },
65 quoted => qr/^$RE{delimited}{ -delim => qr(\') }$/,
66 hostname => qr(^$host$),
67
68 ipv6 => sub { defined(is_ipv6($_[0])) },
69 cidrv6 => sub {
70 my ($p, $l) = split('/', $_[0]);
71 return defined(is_ipv6($p)) && defined(is_between($l, 0, 128));
72 },
73
74 # matches perl style scalar variables
75 # possible matches: $var ${var} $(var)
76 vars => qr/(?<!\\) ( \$\w+ | \$\{[^\}]+\} | \$\([^\)]+\) )/x,
77
78 # closures
79
80 # this one doesn't do a stat() syscall, so keep cool
81 path => sub { return file_name_is_absolute($_[0]); },
82
83 # though this one does it - it stat()s if the file exists
84 fileexists => sub { return stat($_[0]); },
85
86 # do a dns lookup on given value, this also fails if
87 # no dns is available - so be careful with this
88 resolvablehost => sub { return gethostbyname($_[0]); },
89
90 # looks if the given value is an existing user on the host system
91 user => sub { return (getpwnam($_[0]))[0]; },
92
93 # same with group
94 group => sub { return getgrnam($_[0]); },
95
96 # int between 0 - 65535
97 port => sub {
98 if ( $_[0] =~ /^$port$/ && ($_[0] > 0 && $_[0] < 65535) )
99 { return 1; } else { return 0; } },
100
101 # variable integer range, use: range(N1 - N2)
102 range => sub {
103 if ( defined(is_integer($_[0])) && ($_[0] >= $_[2] && $_[0] <= $_[3]) )
104 { return 1; } else { return 0; } },
105
106 # just a place holder at make the key exist
107 optional => 1,
108 );
109109
110110 sub add_validators {
111111 # class method, add validators globally, not per object
556556
557557 In some rare situations you might require a negative match. So
558558 a test shall return TRUE if a particular value does NOT match the
559 given type. This might be usefull to prevent certain things.
559 given type. This might be useful to prevent certain things.
560560
561561 To achieve this, you just have to prepend one of the below mentioned
562562 types with the keyword B<no>.
678678 Returns an array ref with the errors found when validating the hash.
679679 Each error is on the format '<value> doesn't match <types> at <ref>',
680680 where <ref> is a comma separated tree view depicting where in the
681 the error occured.
681 the error occurred.
682682
683683 =item B<errstr()>
684684
898898
899899 =head1 VERSION
900900
901 0.10
901 0.11
902902
903903 =cut
904904