Dermot wrote:
> Hi All,
> 
> I have been at this for a couple of days and could really use some
> help. I have been trying to validate some data. I opted for a module
> called Data::Domain by Dami Laurent. I have emailed him but he's
> server is not collecting (which is odd because I have seen him on
> other lists).
> 
> 
> My problem is that, under the "concept" key, the string data should
> contain at least one entry; history, space, environment...etc
> 
> A created a test script with 2 records, one with concepts=>
> ['flowers', 'environment'], and the other with a single item
> ['environment']. This last one fails. I have been trying combinations
> of Enum, List and One_off method to try and achieve my aims but I can
> configure the Struct that fits.
> 
> If anyone can spot what I am doing wrong or worse case, suggest a
> completely different validation framework, please let me know.
> TIA,
> Dp.
> 
> 
> 
> #########################
> #!/usr/bin/perl
> use strict;
> use warnings;
> use Data::Domain qw/:all/;
> 
> my $rec1 =           {
>             'concepts' => ['flowers', 'environment'],
>             'keywords' => 'Cheese biscuits, biscuits, biscuit, stack,
> baked goods, ciutout, cut out, white background',
>             'title' => 'Cheese biscuits',
>           };
> my $rec2 =           {
>             'concepts' => ['environment'],
>             'keywords' => 'Cheese biscuits, biscuits, biscuit, stack,
> baked goods, ciutout, cut out, white background',
>             'title' => 'Cheese cake',
>         };
> my @tests = ($rec1, $rec2);
> 
> my @concepts = (
>         [ qr/\s?history\s?/i,                           'history'],
>         [ qr/\s?science\s+(\&|and)\s+technology\s?/i,   'science and
> technology'],
>         [ qr/\s?heathcare\s?/i,                         'healthcare'],
>         [ qr/\s?flower(s|)\s?/i,                        'flowers'],
>         [ qr/\s?space\s?/i,                             'space'],
>         [ qr/\s?environment\s?/i,                       'environment'],
>         [ qr/\s?animal(s|)\s?/i,                        'animals'],
>   );
> 
> my $domain = Struct(
>         concepts                => List(-any =>
> [String($concepts[3]->[0]), String($concepts[5]->[0]) ]),
>         keywords                => String(-regex =>
> qr/^[A-Za-z0-9_\s\.\-]+/,  -min => 3,  -name => 'keywords'),
>         title                   => String(-length => [1, 42], -name => 
> "title"),
>         );
> 
> foreach my $t (@tests) {
>         print "Check $t->{'title'}\n";
>         my $msg = $domain->inspect($t);
>         if ($msg) {
>                 for (keys %{$msg} ) {
>                    print "Error: $t->{'title'} \t$_ - ", $msg->{$_},"\n";
>                 }
>         }
> }
> ###########
> 
> # http://search.cpan.org/~dami/Data-Domain-0.09/lib/Data/Domain.pm


I think you need

  concepts => List(-all => One_of(
    String($concepts[3][0]),
    String($concepts[5][0])
  )),

HTH,

Rob

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to