FAQ
Hi Catalysters,

In our organization we are building a Catalyst app where form items have
nested names (i.e. <input name="foo.2.bar.5">) and the whole form data
is then expanded into a Perl tree through CGI::Expand. Next I need to
validate the shape of that tree (type of nodes, absence/presence/size of
subtrees, etc.). As far as I know, existing validation modules like
Data::FormValidator or Html::Widget::Constraint do not go that far. So
attached is a new proposal, still experimental, called Data::Domain (not
yet on CPAN). I'm interested to hear about any
comments/suggestions/collaboration proposals, or just to know if other
people have similar needs.

Best regards,

Laurent Dami

========================================
Excerpt from the doc
=========================================


=head1 NAME

Data::Domain - Data description and validation

=head1 SYNOPSIS

use Data::Domain qw/:all/;

my $domain = Struct(
anInt => Int(-min => 3, -max => 18),
aNum => Num(-min => 3.33, -max => 18.5),
aDate => Date(-max => 'today'),
aLaterDate => sub {my $context = shift;
Date(-min => $context->{flat}{aDate})},
aString => String(-min_length => 2, -optional => 1),
anEnum => Enum(qw/foo bar buz/),
anIntList => List(-min_size => 1, -all => Int),
aMixedList => List(Integer, String, Int(-min => 0), Date),
aStruct => Struct(foo => String, bar => Int(-optional => 1))
);

my $messages = $domain->inspect($some_data);
my_display_error($messages) if $messages;

=head1 DESCRIPTION

A data domain is a description of a set of values, either
scalar, or, more interestingly, structured values (arrays or hashes).
The description can include many constraints, like minimal or maximal
values, regular expressions, required fields, forbidden fields, and
also contextual dependencies. From that description, one can then
check if a given value belongs to the domain. In case of mismatch,
a structured set of error messages is returned.

The motivation for writing this package was to be able to express in a
compact way some possibly complex constraints about structured
data. The data is a Perl tree (nested hashrefs or arrayrefs) that may
come from XML, L<JSON|JSON>, or from postprocessing an HTML form
through L<CGI::Expand|CGI::Expand>. C<Data::Domain> is a kind of tree
parser on that structure, with some facilities for dealing
with dependencies within the structure through lazy
evaluation of domains.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Data-Domain-0.01.tar.gz
Type: application/x-gzip
Size: 15228 bytes
Desc: Data-Domain-0.01.tar.gz
Url : http://lists.rawmode.org/pipermail/catalyst/attachments/20061017/a2c203f8/attachment-0001.bin

Search Discussions

  • Matt S Trout at Oct 17, 2006 at 4:33 pm

    Dami Laurent (PJ) wrote:
    Hi Catalysters,

    In our organization we are building a Catalyst app where form items have
    nested names (i.e. <input name="foo.2.bar.5">) and the whole form data
    is then expanded into a Perl tree through CGI::Expand. Next I need to
    validate the shape of that tree (type of nodes, absence/presence/size of
    subtrees, etc.). As far as I know, existing validation modules like
    Data::FormValidator or Html::Widget::Constraint do not go that far. So
    attached is a new proposal, still experimental, called Data::Domain (not
    yet on CPAN). I'm interested to hear about any
    comments/suggestions/collaboration proposals, or just to know if other
    people have similar needs.
    Looks a lot like

    http://search.cpan.org/~phaylon/Declare-Constraints-Simple-0.03/

    to me.

    --
    Matt S Trout Offering custom development, consultancy and support
    Technical Director contracts for Catalyst, DBIx::Class and BAST. Contact
    Shadowcat Systems Ltd. mst (at) shadowcatsystems.co.uk for more information

    + Help us build a better perl ORM: http://dbix-class.shadowcatsystems.co.uk/ +

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupcatalyst @
categoriescatalyst, perl
postedOct 17, '06 at 4:16p
activeOct 17, '06 at 4:33p
posts2
users2
websitecatalystframework.org
irc#catalyst

2 users in discussion

Matt S Trout: 1 post Dami Laurent (PJ): 1 post

People

Translate

site design / logo © 2022 Grokbase