r3685 - in /packages/libformvalidator-simple-perl/trunk: ./ debian/ lib/FormValidator/ lib/FormValidator/Simple/ t/

gregoa-guest at users.alioth.debian.org gregoa-guest at users.alioth.debian.org
Sat Sep 9 19:06:14 UTC 2006


Author: gregoa-guest
Date: Sat Sep  9 19:06:13 2006
New Revision: 3685

URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=3685
Log:
* New upstream release.
* Add libclass-data-accessor-perl to (build) dependencies.
* Set debhelper compatibility level to 5.

Modified:
    packages/libformvalidator-simple-perl/trunk/Changes
    packages/libformvalidator-simple-perl/trunk/META.yml
    packages/libformvalidator-simple-perl/trunk/Makefile.PL
    packages/libformvalidator-simple-perl/trunk/README
    packages/libformvalidator-simple-perl/trunk/debian/changelog
    packages/libformvalidator-simple-perl/trunk/debian/compat
    packages/libformvalidator-simple-perl/trunk/debian/control
    packages/libformvalidator-simple-perl/trunk/lib/FormValidator/Simple.pm
    packages/libformvalidator-simple-perl/trunk/lib/FormValidator/Simple/Profile.pm
    packages/libformvalidator-simple-perl/trunk/lib/FormValidator/Simple/Results.pm
    packages/libformvalidator-simple-perl/trunk/t/05_results.t
    packages/libformvalidator-simple-perl/trunk/t/07_simple.t
    packages/libformvalidator-simple-perl/trunk/t/22_messages.t

Modified: packages/libformvalidator-simple-perl/trunk/Changes
URL: http://svn.debian.org/wsvn/pkg-perl/packages/libformvalidator-simple-perl/trunk/Changes?rev=3685&op=diff
==============================================================================
--- packages/libformvalidator-simple-perl/trunk/Changes (original)
+++ packages/libformvalidator-simple-perl/trunk/Changes Sat Sep  9 19:06:13 2006
@@ -1,4 +1,11 @@
 Revision history for Perl extension FormValidator::Simple.
+
+0.17  Tue Sep 05 15:22:00 2006
+    - took CLACO's patch that resolves RT issues: 21224, 20658, 19667.
+        RT20658: fixed POD error, thanks to ISHIGAKI.
+        RT20658: fixed Profile _init from eating profile via slice
+                 set_messages on object now overrides messages set on class
+        RT21224: added 'clear' method to FVS::Results. Thanks to CLACO.
 
 0.16  Tue May 16 10:19:00 2006
     - added DATETIME_FORMAT and DATETIME_STRPTIME validation

Modified: packages/libformvalidator-simple-perl/trunk/META.yml
URL: http://svn.debian.org/wsvn/pkg-perl/packages/libformvalidator-simple-perl/trunk/META.yml?rev=3685&op=diff
==============================================================================
--- packages/libformvalidator-simple-perl/trunk/META.yml (original)
+++ packages/libformvalidator-simple-perl/trunk/META.yml Sat Sep  9 19:06:13 2006
@@ -1,11 +1,12 @@
 # http://module-build.sourceforge.net/META-spec.html
 #XXXXXXX This is a prototype!!!  It will change in the future!!! XXXXX#
 name:         FormValidator-Simple
-version:      0.16
+version:      0.17
 version_from: lib/FormValidator/Simple.pm
 installdirs:  site
 requires:
     Class::Accessor:               0.22
+    Class::Data::Accessor:         0
     Class::Data::Inheritable:      0.04
     Class::Inspector:              1.13
     Date::Calc:                    5.4
@@ -20,4 +21,4 @@
     YAML:                          0.39
 
 distribution_type: module
-generated_by: ExtUtils::MakeMaker version 6.17
+generated_by: ExtUtils::MakeMaker version 6.30

Modified: packages/libformvalidator-simple-perl/trunk/Makefile.PL
URL: http://svn.debian.org/wsvn/pkg-perl/packages/libformvalidator-simple-perl/trunk/Makefile.PL?rev=3685&op=diff
==============================================================================
--- packages/libformvalidator-simple-perl/trunk/Makefile.PL (original)
+++ packages/libformvalidator-simple-perl/trunk/Makefile.PL Sat Sep  9 19:06:13 2006
@@ -6,6 +6,7 @@
     'Class::Accessor'            => 0.22,
     'Class::Inspector'           => 1.13,
     'Class::Data::Inheritable'   => 0.04,
+    'Class::Data::Accessor'      => 0,
     'UNIVERSAL::require'         => 0.10,
     'Mail::Address'              => 0,
     'Email::Valid'               => 0.15,

Modified: packages/libformvalidator-simple-perl/trunk/README
URL: http://svn.debian.org/wsvn/pkg-perl/packages/libformvalidator-simple-perl/trunk/README?rev=3685&op=diff
==============================================================================
--- packages/libformvalidator-simple-perl/trunk/README (original)
+++ packages/libformvalidator-simple-perl/trunk/README Sat Sep  9 19:06:13 2006
@@ -1,34 +1,476 @@
-FormValidator-Simple version 0.01
-=================================
-
-The README is used to introduce the module and provide instructions on
-how to install the module, any machine dependencies it may have (for
-example C compilers and installed libraries) and any other information
-that should be provided before the module is installed.
-
-A README file is required for CPAN modules since CPAN extracts the
-README file from a module distribution so that people browsing the
-archive can use it get an idea of the modules uses. It is usually a
-good idea to provide version information here so that people can
-decide whether fixes for the module are worth downloading.
-
-INSTALLATION
-
-To install this module type the following:
-
-   perl Makefile.PL
-   make
-   make test
-   make install
-
-
-COPYRIGHT AND LICENCE
-
-
-Copyright (C) 2005 by Lyo Kato
-
-This library is free software; you can redistribute it and/or modify
-it under the same terms as Perl itself, either Perl version 5.8.5 or,
-at your option, any later version of Perl 5 you may have available.
-
-
+NAME
+    FormValidator::Simple - validation with simple chains of constraints
+
+SYNOPSIS
+        my $query = CGI->new;
+        $query->param( param1 => 'ABCD' );
+        $query->param( param2 =>  12345 );
+        $query->param( mail1  => 'lyo.kato at gmail.com' );
+        $query->param( mail2  => 'lyo.kato at gmail.com' );
+        $query->param( year   => 2005 );
+        $query->param( month  =>   11 );
+        $query->param( day    =>   27 );
+
+        my $result = FormValidator::Simple->check( $query => [
+            param1 => ['NOT_BLANK', 'ASCII', ['LENGTH', 2, 5]],
+            param2 => ['NOT_BLANK', 'INT'  ],
+            mail1  => ['NOT_BLANK', 'EMAIL_LOOSE'],
+            mail2  => ['NOT_BLANK', 'EMAIL_LOOSE'],
+            { mails => ['mail1', 'mail2'       ] } => ['DUPLICATION'],
+            { date  => ['year',  'month', 'day'] } => ['DATE'],
+        ] );
+
+        if ( $result->has_error ) {
+            my $tt = Template->new({ INCLUDE_PATH => './tmpl' });
+            $tt->process('template.html', { result => $result });
+        }
+
+    template example
+
+        [% IF result.has_error %]
+        <p>Found Input Error</p>
+        <ul>
+
+            [% IF result.missing('param1') %]
+            <li>param1 is blank.</li>
+            [% END %]
+
+            [% IF result.invalid('param1') %]
+            <li>param1 is invalid.</li>
+            [% END %]
+
+            [% IF result.invalid('param1', 'ASCII') %]
+            <li>param1 needs ascii code.</li>
+            [% END %]
+
+            [% IF result.invalid('param1', 'LENGTH') %]
+            <li>input into param1 with characters that's length should be between two and five. </li>
+            [% END %]
+
+        </ul>
+        [% END %]
+
+    example2
+
+        [% IF result.has_error %]
+        <ul>
+            [% FOREACH key IN result.error %]
+                [% FOREACH type IN result.error(key) %]
+                <li>invalid: [% key %] - [% type %]</li>
+                [% END %]
+            [% END %]
+        </ul>
+        [% END %]
+
+DESCRIPTION
+    This module provides you a sweet way of form data validation with simple
+    constraints chains. You can write constraints on single line for each
+    input data.
+
+    This idea is based on Sledge::Plugin::Validator, and most of validation
+    code is borrowed from this plugin.
+
+    (Sledge is a MVC web application framework: http://sl.edge.jp [Japanese]
+    )
+
+    The result object this module returns behaves like
+    Data::FormValidator::Results.
+
+HOW TO SET PROFILE
+        FormValidator::Simple->check( $q => [
+            #profile
+        ] );
+
+    Use 'check' method.
+
+    A hash reference includes input data, or an object of some class that
+    has a method named 'param', for example CGI, is needed as first
+    argument.
+
+    And set profile as array reference into second argument. Profile
+    consists of some pairs of input data and constraints.
+
+        my $q = CGI->new;
+        $q->param( param1 => 'hoge' );
+
+        FormValidator::Simple->check( $q => [
+            param1 => [ ['NOT_BLANK'], ['LENGTH', 4, 10] ],
+        ] );
+
+    In this case, param1 is the name of a form element. and the array ref "[
+    ['NOT_BLANK']... ]" is a constraints chain.
+
+    Write constraints chain as arrayref, and you can set some constraints
+    into it. In the last example, two constraints 'NOT_BLANK', and 'LENGTH'
+    are set. Each constraints is should be set as arrayref, but in case the
+    constraint has no argument, it can be written as scalar text.
+
+        FormValidator::Simple->check( $q => [
+            param1 => [ 'NOT_BLANK', ['LENGTH', 4, 10] ],
+        ] );
+
+    Now, in this sample 'NOT_BLANK' constraint is not an arrayref, but
+    'LENGTH' isn't. Because 'LENGTH' has two arguments, 4 and 10.
+
+  MULTIPLE DATA VALIDATION
+    When you want to check about multiple input data, do like this.
+
+        my $q = CGI->new;
+        $q->param( mail1 => 'lyo.kato at gmail.com' );
+        $q->param( mail2 => 'lyo.kato at gmail.com' );
+
+        my $result = FormValidator::Simple->check( $q => [
+            { mails => ['mail1', 'mail2'] } => [ 'DUPLICATION' ],
+        ] )
+
+        [% IF result.invalid('mails') %]
+        <p>mail1 and mail2 aren't same.</p>
+        [% END %]
+
+    and here's an another example.
+
+        my $q = CGI->new;
+        $q->param( year  => 2005 );
+        $q->param( month =>   12 );
+        $q->param(   day =>   27 );
+
+        my $result = FormValidator::Simple->check( $q => [ 
+            { date => ['year', 'month', 'day'] } => [ 'DATE' ],
+        ] );
+
+        [% IF result.invalid('date') %]
+        <p>Set correct date.</p>
+        [% END %]
+
+  FLEXIBLE VALIDATION
+        my $valid = FormValidator::Simple->new();
+
+        $valid->check( $q => [ 
+            param1 => [qw/NOT_BLANK ASCII/, [qw/LENGTH 4 10/] ],
+        ] );
+
+        $valid->check( $q => [
+            param2 => [qw/NOT_BLANK/],
+        ] );
+
+        my $results = $valid->results;
+
+        if ( found some error... ) {
+            $results->set_invalid('param3' => 'MY_ERROR');
+        }
+
+    template example
+
+        [% IF results.invalid('param1') %]
+        ...
+        [% END %]
+        [% IF results.invalid('param2') %]
+        ...
+        [% END %]
+        [% IF results.invalid('param3', 'MY_ERROR') %]
+        ...
+        [% END %]
+
+HOW TO SET OPTIONS
+    Option setting is needed by some validation, especially in plugins.
+
+    You can set them in two ways.
+
+        FormValidator::Simple->set_option(
+            dbic_base_class => 'MyProj::Model::DBIC',
+            charset         => 'euc',
+        );
+
+    or
+
+        $valid = FormValidator::Simple->new(
+            dbic_base_class => 'MyProj::Model::DBIC',
+            charset         => 'euc',
+        );
+
+        $valid->check(...)
+
+VALIDATION COMMANDS
+    You can use follow variety validations. and each validations can be used
+    as negative validation with 'NOT_' prefix.
+
+        FormValidator::Simple->check( $q => [ 
+            param1 => [ 'INT', ['LENGTH', 4, 10] ],
+            param2 => [ 'NOT_INT', ['NOT_LENGTH', 4, 10] ],
+        ] );
+
+    SP  check if the data has space or not.
+
+    INT check if the data is integer or not.
+
+    UINT
+        unsigined integer check. for example, if -1234 is input, the
+        validation judges it invalid.
+
+    DECIMAL
+            $q->param( 'num1' => '123.45678' );
+
+            my $result = FormValidator::Simple->check( $q => [ 
+                num1 => [ ['DECIMAL', 3, 5] ],
+            ] );
+
+        each numbers (3,5) mean maximum digits before/after '.'
+
+    ASCII
+        check is the data consists of only ascii code.
+
+    LENGTH
+        check the length of the data.
+
+            my $result = FormValidator::Simple->check( $q => [
+                param1 => [ ['LENGTH', 4] ],
+            ] );
+
+        check if the length of the data is 4 or not.
+
+            my $result = FormValidator::Simple->check( $q => [
+                param1 => [ ['LENGTH', 4, 10] ],
+            ] );
+
+        when you set two arguments, it checks if the length of data is in
+        the range between 4 and 10.
+
+    HTTP_URL
+        verify it is a http(s)-url
+
+            my $result = FormValidator::Simple->check( $q => [
+                param1 => [ 'HTTP_URL' ],
+            ] );
+
+    SELECTED_AT_LEAST
+        verify the quantity of selected parameters is counted over allowed
+        minimum.
+
+            <input type="checkbox" name="hobby" value="music" /> Music
+            <input type="checkbox" name="hobby" value="movie" /> Movie
+            <input type="checkbox" name="hobby" value="game"  /> Game
+
+            my $result = FormValidator::Simple->check( $q => [ 
+                hobby => ['NOT_BLANK', ['SELECTED_AT_LEAST', 2] ],
+            ] );
+
+    REGEX
+        check with regular expression.
+
+            my $result = FormValidator::Simple->check( $q => [ 
+                param1 => [ ['REGEX', qr/^hoge$/ ] ],
+            ] );
+
+    DUPLICATION
+        check if the two data are same or not.
+
+            my $result = FormValidator::Simple->check( $q => [ 
+                { duplication_check => ['param1', 'param2'] } => [ 'DUPLICATION' ],
+            ] );
+
+    EMAIL
+        check with Email::Valid.
+
+    EMAIL_MX
+        check with Email::Valid, including mx check.
+
+    EMAIL_LOOSE
+        check with Email::Valid::Loose.
+
+    EMAIL_LOOSE_MX
+        check with Email::Valid::Loose, including mx check.
+
+    DATE
+        check with Date::Calc
+
+            my $result = FormValidator::Simple->check( $q => [ 
+                { date => [qw/year month day/] } => [ 'DATE' ]
+            ] );
+
+    TIME
+        check with Date::Calc
+
+            my $result = FormValidator::Simple->check( $q => [
+                { time => [qw/hour min sec/] } => ['TIME'],
+            ] );
+
+    DATETIME
+        check with Date::Calc
+
+            my $result = FormValidator::Simple->check( $q => [ 
+                { datetime => [qw/year month day hour min sec/] } => ['DATETIME']
+            ] );
+
+    DATETIME_STRPTIME
+        check with DateTime::Format::Strptime.
+
+            my $q = CGI->new;
+            $q->param( datetime => '2006-04-26T19:09:21+0900' );
+
+            my $result = FormValidator::Simple->check( $q => [
+              datetime => [ [ 'DATETIME_STRPTIME', '%Y-%m-%dT%T%z' ] ],
+            ] );
+
+    DATETIME_FORMAT
+        check with DateTime::Format::***. for example,
+        DateTime::Format::HTTP, DateTime::Format::Mail,
+        DateTime::Format::MySQL and etc.
+
+            my $q = CGI->new;
+            $q->param( datetime => '2004-04-26 19:09:21' );
+
+            my $result = FormValidator::Simple->check( $q => [
+              datetime => [ [qw/DATETIME_FORMAT MySQL/] ],
+            ] );
+
+    GREATER_THAN
+        numeric comparison
+
+            my $result = FormValidator::Simple->check( $q => [
+                age => [ ['GREATER_THAN', 25] ],
+            ] );
+
+    LESS_THAN
+        numeric comparison
+
+            my $result = FormValidator::Simple->check( $q => [
+                age => [ ['LESS_THAN', 25] ],
+            ] );
+
+    EQUAL_TO
+        numeric comparison
+
+            my $result = FormValidator::Simple->check( $q => [
+                age => [ ['EQUAL_TO', 25] ],
+            ] );
+
+    BETWEEN
+        numeric comparison
+
+            my $result = FormValidator::Simple->check( $q => [
+                age => [ ['BETWEEN', 20, 25] ],
+            ] );
+
+    ANY check if there is not blank data in multiple data.
+
+            my $result = FormValidator::Simple->check( $q => [ 
+                { some_data => [qw/param1 param2 param3/] } => ['ANY']
+            ] );
+
+    IN_ARRAY
+        check if the food ordered is in menu
+
+            my $result = FormValidator::Simple->check( $q => [
+                food => [ ['IN_ARRAY', qw/noodle soba spaghetti/] ],
+            ] };
+
+HOW TO LOAD PLUGINS
+        use FormValidator::Simple qw/Japanese CreditCard/;
+
+    FormValidator::Simple::Plugin::Japanese,
+    FormValidator::Simple::Plugin::CreditCard are loaded.
+
+    or use 'load_plugin' method.
+
+        use FormValidator::Simple;
+        FormValidator::Simple->load_plugin('FormValidator::Simple::Plugin::CreditCard');
+
+MESSAGE HANDLING
+    You can custom your own message with key and type.
+
+        [% IF result.has_error %]
+            [% FOREACH key IN result.error %]
+                [% FOREACH type IN result.error(key) %]
+                <p>error message:[% type %] - [% key %]</p>
+                [% END %]
+            [% END %]
+        [% END %]
+
+    And you can also set messages configuration before. You can prepare
+    configuration as hash reference.
+
+        FormValidator::Simple->set_messages( {
+            action1 => {
+                name => {
+                    NOT_BLANK => 'input name!',
+                    LENGTH    => 'input name (length should be between 0 and 10)!',
+                },
+                email => {
+                    DEFAULT => 'input correct email address!',
+                },
+            },
+        } );
+
+    or a YAML file.
+
+        # messages.yml
+        DEFAULT:
+            name:
+                DEFAULT: name is invalid!
+        action1:
+            name:
+                NOT_BLANK: input name!
+                LENGTH: input name(length should be between 0 and 10)!
+            email:
+                DEFAULT: input correct email address!
+        action2:
+            name:
+                DEFAULT: ...
+                
+    # in your perl-script, set the file's path.
+        FormValidator::Simple->set_messages('messages.yml');
+
+    DEFAULT is a special type. If it can't find setting for indicated
+    validation-type, it uses message set for DEFAULT.
+
+    after setting, execute check(),
+
+        my $result = FormValidator::Simple->check( $q => [
+            name  => [qw/NOT_BLANK/, [qw/LENGTH 0 10/] ],
+            email => [qw/NOT_BLANK EMAIL_LOOSE/, [qw/LENGTH 0 20/] ],
+        ] );
+
+        # matching result and messages for indicated action.
+        my $messages = $result->messages('action1');
+
+        foreach my $message ( @$messages ) {
+            print $message, "\n";
+        }
+
+    When it can't find indicated action, name, and type, it searches proper
+    message from DEFAULT action. If in template file,
+
+        [% IF result.has_error %]
+            [% FOREACH msg IN result.messages('action1') %]
+            <p>[% msg %]</p>
+            [% END %]
+        [% END %]
+
+    you can set each message format.
+
+        FormValidator::Simple->set_message_format('<p>%s</p>');
+        my $result = FormValidator::Simple->check( $q => [
+            ...profile
+        ] );
+
+        [% IF result.has_error %]
+            [% result.messages('action1').join("\n") %]
+        [% END %]
+
+RESULT HANDLING
+    See FormValidator::Simple::Results
+
+SEE ALSO
+    Data::FormValidator
+
+    http://sl.edge.jp/ (Japanese)
+
+    http://sourceforge.jp/projects/sledge
+
+AUTHOR
+    Lyo Kato <lyo.kato at gmail.com>
+
+COPYRIGHT AND LICENSE
+    This library is free software. You can redistribute it and/or modify it
+    under the same terms as perl itself.
+

Modified: packages/libformvalidator-simple-perl/trunk/debian/changelog
URL: http://svn.debian.org/wsvn/pkg-perl/packages/libformvalidator-simple-perl/trunk/debian/changelog?rev=3685&op=diff
==============================================================================
--- packages/libformvalidator-simple-perl/trunk/debian/changelog (original)
+++ packages/libformvalidator-simple-perl/trunk/debian/changelog Sat Sep  9 19:06:13 2006
@@ -1,3 +1,11 @@
+libformvalidator-simple-perl (0.17-1) unstable; urgency=low
+
+  * New upstream release.
+  * Add libclass-data-accessor-perl to (build) dependencies.
+  * Set debhelper compatibility level to 5.
+
+ -- gregor herrmann <gregor+debian at comodo.priv.at>  Sat,  9 Sep 2006 21:04:23 +0200
+
 libformvalidator-simple-perl (0.16-1) unstable; urgency=low
 
   * New upstream release

Modified: packages/libformvalidator-simple-perl/trunk/debian/compat
URL: http://svn.debian.org/wsvn/pkg-perl/packages/libformvalidator-simple-perl/trunk/debian/compat?rev=3685&op=diff
==============================================================================
--- packages/libformvalidator-simple-perl/trunk/debian/compat (original)
+++ packages/libformvalidator-simple-perl/trunk/debian/compat Sat Sep  9 19:06:13 2006
@@ -1,1 +1,1 @@
-4
+5

Modified: packages/libformvalidator-simple-perl/trunk/debian/control
URL: http://svn.debian.org/wsvn/pkg-perl/packages/libformvalidator-simple-perl/trunk/debian/control?rev=3685&op=diff
==============================================================================
--- packages/libformvalidator-simple-perl/trunk/debian/control (original)
+++ packages/libformvalidator-simple-perl/trunk/debian/control Sat Sep  9 19:06:13 2006
@@ -1,15 +1,15 @@
 Source: libformvalidator-simple-perl
 Section: perl
 Priority: optional
-Build-Depends: debhelper (>= 4.0.2)
-Build-Depends-Indep: perl (>= 5.8.0-7), libtest-pod-perl, libyaml-perl, libemail-valid-loose-perl, libtie-ixhash-perl, libclass-accessor-perl, libdate-calc-perl, libclass-data-inheritable-perl, libclass-inspector-perl, libmailtools-perl, libuniversal-exports-perl, liblist-moreutils-perl, libdatetime-format-strptime-perl
+Build-Depends: debhelper (>= 5.0.0)
+Build-Depends-Indep: perl (>= 5.8.0-7), libtest-pod-perl, libyaml-perl, libemail-valid-loose-perl, libtie-ixhash-perl, libclass-accessor-perl, libdate-calc-perl, libclass-data-inheritable-perl, libclass-inspector-perl, libmailtools-perl, libuniversal-exports-perl, liblist-moreutils-perl, libdatetime-format-strptime-perl, libclass-data-accessor-perl
 Maintainer: Debian Perl Group <pkg-perl-maintainers at lists.alioth.debian.org>
-Uploaders: Krzysztof Krzyzaniak (eloy) <eloy at debian.org>
+Uploaders: Krzysztof Krzyzaniak (eloy) <eloy at debian.org>, gregor herrmann <gregor+debian at comodo.priv.at>
 Standards-Version: 3.7.2
 
 Package: libformvalidator-simple-perl
 Architecture: all
-Depends: ${perl:Depends}, ${misc:Depends}, libyaml-perl, libemail-valid-loose-perl, libtie-ixhash-perl, libclass-accessor-perl, libdate-calc-perl, libclass-data-inheritable-perl, libclass-inspector-perl, libmailtools-perl, libuniversal-exports-perl, liblist-moreutils-perl, libdatetime-format-strptime-perl
+Depends: ${perl:Depends}, ${misc:Depends}, libyaml-perl, libemail-valid-loose-perl, libtie-ixhash-perl, libclass-accessor-perl, libdate-calc-perl, libclass-data-inheritable-perl, libclass-inspector-perl, libmailtools-perl, libuniversal-exports-perl, liblist-moreutils-perl, libdatetime-format-strptime-perl, libclass-data-accessor-perl
 Description:  validation with simple chains of constraints
  This module provides you a sweet way of form data validation with
  simple constraints chains. You can write constraints on single line

Modified: packages/libformvalidator-simple-perl/trunk/lib/FormValidator/Simple.pm
URL: http://svn.debian.org/wsvn/pkg-perl/packages/libformvalidator-simple-perl/trunk/lib/FormValidator/Simple.pm?rev=3685&op=diff
==============================================================================
--- packages/libformvalidator-simple-perl/trunk/lib/FormValidator/Simple.pm (original)
+++ packages/libformvalidator-simple-perl/trunk/lib/FormValidator/Simple.pm Sat Sep  9 19:06:13 2006
@@ -1,8 +1,9 @@
 package FormValidator::Simple;
 use strict;
-use base qw/Class::Accessor::Fast Class::Data::Inheritable/;
+use base qw/Class::Accessor::Fast Class::Data::Inheritable Class::Data::Accessor/;
 use Class::Inspector;
 use UNIVERSAL::require;
+use Scalar::Util qw/blessed/;
 use FormValidator::Simple::Results;
 use FormValidator::Simple::Exception;
 use FormValidator::Simple::Data;
@@ -11,11 +12,10 @@
 use FormValidator::Simple::Constants;
 use FormValidator::Simple::Messages;
 
-our $VERSION = '0.16';
-
-__PACKAGE__->mk_accessors(qw/data prof results/);
-
-__PACKAGE__->mk_classdata( messages => FormValidator::Simple::Messages->new );
+our $VERSION = '0.17';
+
+__PACKAGE__->mk_classaccessors(qw/data prof results/);
+__PACKAGE__->mk_classaccessor( messages => FormValidator::Simple::Messages->new );
 
 sub import {
     my $class = shift;
@@ -55,14 +55,20 @@
 sub set_messages {
     my ($proto, $file) = @_;
     my $class = ref $proto || $proto;
-    $class->messages->load($file);
+    if (blessed $proto) {
+        $proto->messages(FormValidator::Simple::Messages->new)->load($file);
+        $proto->results( FormValidator::Simple::Results->new(
+            messages => $proto->messages,
+        ) );
+    } else {
+        $class->messages->load($file);
+    }
 }
 
 sub set_message_format {
     my ($proto, $format) = @_;
     $format ||= '';
-    my $class = ref $proto || $proto;
-    $class->messages->format($format);
+    $proto->messages->format($format);
 }
 
 sub new {
@@ -78,7 +84,7 @@
     my $class = ref $self;
     $class->set_option(@args);
     $self->results( FormValidator::Simple::Results->new(
-        messages => $class->messages,
+        messages => $self->messages,
     ) );
 }
 
@@ -100,7 +106,7 @@
 sub check {
     my ($proto, $input, $prof, $options) = @_;
     $options ||= {};
-    my $self = ref $proto ? $proto : $proto->new(%$options);
+    my $self = blessed $proto ? $proto : $proto->new(%$options);
 
     my $data = FormValidator::Simple::Data->new($input);
     my $prof_setting = FormValidator::Simple::Profile->new($prof);
@@ -530,8 +536,6 @@
     my $result = FormValidator::Simple->check( $q => [ 
         { some_data => [qw/param1 param2 param3/] } => ['ANY']
     ] );
-
-=back
 
 =item IN_ARRAY
 

Modified: packages/libformvalidator-simple-perl/trunk/lib/FormValidator/Simple/Profile.pm
URL: http://svn.debian.org/wsvn/pkg-perl/packages/libformvalidator-simple-perl/trunk/lib/FormValidator/Simple/Profile.pm?rev=3685&op=diff
==============================================================================
--- packages/libformvalidator-simple-perl/trunk/lib/FormValidator/Simple/Profile.pm (original)
+++ packages/libformvalidator-simple-perl/trunk/lib/FormValidator/Simple/Profile.pm Sat Sep  9 19:06:13 2006
@@ -6,9 +6,10 @@
 
 sub _init {
     my($self, $prof) = @_;
-    while ( my($keys, $constraints) = splice(@$prof, 0, 2) ) {
+    for (my $i = 0; $i <= $#{$prof}; $i += 2) {
+        my ($key, $constraints) = ($prof->[$i], $prof->[$i + 1]);
         my $record = FormValidator::Simple::Profile::Record->new;
-        $record->set_keys($keys);
+        $record->set_keys($key);
         $record->set_constraints($constraints);
         $self->append($record);
     }

Modified: packages/libformvalidator-simple-perl/trunk/lib/FormValidator/Simple/Results.pm
URL: http://svn.debian.org/wsvn/pkg-perl/packages/libformvalidator-simple-perl/trunk/lib/FormValidator/Simple/Results.pm?rev=3685&op=diff
==============================================================================
--- packages/libformvalidator-simple-perl/trunk/lib/FormValidator/Simple/Results.pm (original)
+++ packages/libformvalidator-simple-perl/trunk/lib/FormValidator/Simple/Results.pm Sat Sep  9 19:06:13 2006
@@ -177,6 +177,10 @@
     }
 }
 
+sub clear {
+  %{shift->_records} = ();
+}
+
 1;
 __END__
 

Modified: packages/libformvalidator-simple-perl/trunk/t/05_results.t
URL: http://svn.debian.org/wsvn/pkg-perl/packages/libformvalidator-simple-perl/trunk/t/05_results.t?rev=3685&op=diff
==============================================================================
--- packages/libformvalidator-simple-perl/trunk/t/05_results.t (original)
+++ packages/libformvalidator-simple-perl/trunk/t/05_results.t Sat Sep  9 19:06:13 2006
@@ -1,5 +1,5 @@
 use strict;
-use Test::More tests => 29;
+use Test::More tests => 34;
 
 BEGIN{ use_ok("FormValidator::Simple::Results") }
 
@@ -55,3 +55,10 @@
 is( $results->valid('r3'), 'data' );
 
 
+$results->clear;
+is(scalar keys %{$results->valid}, 0);
+is(scalar @{$results->missing}, 0);
+ok(!$results->has_error);
+ok(!$results->has_invalid);
+ok($results->success);
+

Modified: packages/libformvalidator-simple-perl/trunk/t/07_simple.t
URL: http://svn.debian.org/wsvn/pkg-perl/packages/libformvalidator-simple-perl/trunk/t/07_simple.t?rev=3685&op=diff
==============================================================================
--- packages/libformvalidator-simple-perl/trunk/t/07_simple.t (original)
+++ packages/libformvalidator-simple-perl/trunk/t/07_simple.t Sat Sep  9 19:06:13 2006
@@ -1,5 +1,5 @@
 use strict;
-use Test::More tests => 23;
+use Test::More tests => 24;
 use CGI;
 
 BEGIN { use_ok("FormValidator::Simple"); }
@@ -64,3 +64,16 @@
 
 ok($results3->invalid('hoge'));
 ok($results3->invalid( hoge => 'HOGE' ));
+
+# make sure check doesn't eat the profile
+my $profile = [
+  text => [qw/NOT_BLANK INT/],
+  int  => [qw/NOT_BLANK INT/],
+];
+
+my $r3 = FormValidator::Simple->check( $q => $profile );
+is_deeply( $profile, [
+  text => [qw/NOT_BLANK INT/],
+  int  => [qw/NOT_BLANK INT/],
+] );
+

Modified: packages/libformvalidator-simple-perl/trunk/t/22_messages.t
URL: http://svn.debian.org/wsvn/pkg-perl/packages/libformvalidator-simple-perl/trunk/t/22_messages.t?rev=3685&op=diff
==============================================================================
--- packages/libformvalidator-simple-perl/trunk/t/22_messages.t (original)
+++ packages/libformvalidator-simple-perl/trunk/t/22_messages.t Sat Sep  9 19:06:13 2006
@@ -1,9 +1,9 @@
 use strict;
-use Test::More tests => 6;
+use Test::More tests => 16;
 BEGIN{ use_ok("FormValidator::Simple") }
 use CGI;
 
-FormValidator::Simple->set_messages( {
+my $data = {
     DEFAULT => {
         data4 => {
             DEFAULT => 'input data4',    
@@ -22,7 +22,9 @@
             NOT_BLANK => 'input data3',
         },
     },
-} );
+};
+
+FormValidator::Simple->set_messages( $data );
 
 my $q = CGI->new;
 $q->param( data1 => 'hoge' );
@@ -44,3 +46,55 @@
 is($messages->[3], 'input data3');
 is($messages->[4], 'input data4');
 
+# check that messages on object don't trash class messages
+my $fvs = FormValidator::Simple->new;
+
+is_deeply(FormValidator::Simple->messages->{_data}, $data);
+
+# set your own
+my $objdata = {
+  object => {
+    object1 => {
+      NOT_BLANK => 'not blank for object1',
+    },
+    object2 => {
+      LENGTH => 'length wrong for object2',
+    },
+  }
+};
+
+# object has its messages
+$fvs->set_messages( $objdata );
+is_deeply($fvs->messages->{_data}, $objdata);
+
+# class should be int tact
+is_deeply(FormValidator::Simple->messages->{_data}, $data);
+
+my $oq = CGI->new;
+$oq->param( object1 => ''       );
+$oq->param( object2 => 'abcdef' );
+
+my $or = $fvs->check( $oq => [
+    object1 => [ [qw/NOT_BLANK/] ],
+    object2 => [ [qw/LENGTH 1 2/] ],
+] );
+
+my $omessages = $or->messages('object');
+is($omessages->[0], 'not blank for object1');
+is($omessages->[1], 'length wrong for object2');
+
+# make sure the class version still works:
+my $nr = FormValidator::Simple->check( $q => [
+  data1 => [qw/NOT_BLANK INT/, [qw/LENGTH 0 3/] ],
+  data2 => [qw/NOT_BLANK ASCII/, [qw/LENGTH 5/] ],
+  data3 => [qw/NOT_BLANK/],
+  data4 => [qw/NOT_BLANK/],
+] );
+
+my $nmessages = $nr->messages('test');
+is($nmessages->[0], 'input integer for data1');
+is($nmessages->[1], 'data1 has wrong length');
+is($nmessages->[2], 'default error for data2');
+is($nmessages->[3], 'input data3');
+is($nmessages->[4], 'input data4');
+




More information about the Pkg-perl-cvs-commits mailing list