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

Krzysztof Krzyzaniak eloy at costa.debian.org
Fri Dec 23 22:17:53 UTC 2005


Author: eloy
Date: 2005-12-23 22:17:51 +0000 (Fri, 23 Dec 2005)
New Revision: 1737

Added:
   packages/libformvalidator-simple-perl/trunk/t/25_all.t
Modified:
   packages/libformvalidator-simple-perl/trunk/Changes
   packages/libformvalidator-simple-perl/trunk/MANIFEST
   packages/libformvalidator-simple-perl/trunk/META.yml
   packages/libformvalidator-simple-perl/trunk/debian/changelog
   packages/libformvalidator-simple-perl/trunk/debian/control
   packages/libformvalidator-simple-perl/trunk/debian/watch
   packages/libformvalidator-simple-perl/trunk/lib/FormValidator/Simple.pm
   packages/libformvalidator-simple-perl/trunk/lib/FormValidator/Simple/Messages.pm
   packages/libformvalidator-simple-perl/trunk/lib/FormValidator/Simple/Validator.pm
   packages/libformvalidator-simple-perl/trunk/t/22_messages.t
   packages/libformvalidator-simple-perl/trunk/t/23_messages_yaml.t
Log:
eloy: new upstream version


Modified: packages/libformvalidator-simple-perl/trunk/Changes
===================================================================
--- packages/libformvalidator-simple-perl/trunk/Changes	2005-12-23 22:14:59 UTC (rev 1736)
+++ packages/libformvalidator-simple-perl/trunk/Changes	2005-12-23 22:17:51 UTC (rev 1737)
@@ -1,5 +1,12 @@
 Revision history for Perl extension FormValidator::Simple.
 
+0.13  Thu Nov 24 00:45:00 2005
+    - added set_message_format
+      Thanks to Daisuke Murase.
+
+0.12  Thu Nov 24 00:45:00 2005
+    - added validation ALL
+
 0.11  Thu Nov 24 00:45:00 2005
     - added set_option method
 

Modified: packages/libformvalidator-simple-perl/trunk/MANIFEST
===================================================================
--- packages/libformvalidator-simple-perl/trunk/MANIFEST	2005-12-23 22:14:59 UTC (rev 1736)
+++ packages/libformvalidator-simple-perl/trunk/MANIFEST	2005-12-23 22:17:51 UTC (rev 1737)
@@ -41,5 +41,6 @@
 t/22_messages.t
 t/23_messages_yaml.t
 t/24_options.t
+t/25_all.t
 t/conf/messages.yml
 t/lib/FormValidator/Simple/Plugin/Sample.pm

Modified: packages/libformvalidator-simple-perl/trunk/META.yml
===================================================================
--- packages/libformvalidator-simple-perl/trunk/META.yml	2005-12-23 22:14:59 UTC (rev 1736)
+++ packages/libformvalidator-simple-perl/trunk/META.yml	2005-12-23 22:17:51 UTC (rev 1737)
@@ -1,7 +1,7 @@
 # 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.11
+version:      0.13
 version_from: lib/FormValidator/Simple.pm
 installdirs:  site
 requires:

Modified: packages/libformvalidator-simple-perl/trunk/debian/changelog
===================================================================
--- packages/libformvalidator-simple-perl/trunk/debian/changelog	2005-12-23 22:14:59 UTC (rev 1736)
+++ packages/libformvalidator-simple-perl/trunk/debian/changelog	2005-12-23 22:17:51 UTC (rev 1737)
@@ -1,3 +1,10 @@
+libformvalidator-simple-perl (0.13-1) unstable; urgency=low
+
+  * New upstream release
+  * "Donate" package to Debian Perl Group
+
+ -- Krzysztof Krzyzaniak (eloy) <eloy at debian.org>  Fri, 23 Dec 2005 23:15:11 +0100
+
 libformvalidator-simple-perl (0.11-1) unstable; urgency=low
 
   * New upstream release (closes: #341127)

Modified: packages/libformvalidator-simple-perl/trunk/debian/control
===================================================================
--- packages/libformvalidator-simple-perl/trunk/debian/control	2005-12-23 22:14:59 UTC (rev 1736)
+++ packages/libformvalidator-simple-perl/trunk/debian/control	2005-12-23 22:17:51 UTC (rev 1737)
@@ -2,7 +2,8 @@
 Section: perl
 Priority: optional
 Build-Depends-Indep: perl (>= 5.8.0-7), debhelper (>= 4.0.2), 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
-Maintainer: Krzysztof Krzyzaniak (eloy) <eloy at debian.org>
+Maintainer: Debian Perl Group <pkg-perl-maintainers at lists.alioth.debian.org>
+Uploaders: Krzysztof Krzyzaniak (eloy) <eloy at debian.org>
 Standards-Version: 3.6.2
 
 Package: libformvalidator-simple-perl

Modified: packages/libformvalidator-simple-perl/trunk/debian/watch
===================================================================
--- packages/libformvalidator-simple-perl/trunk/debian/watch	2005-12-23 22:14:59 UTC (rev 1736)
+++ packages/libformvalidator-simple-perl/trunk/debian/watch	2005-12-23 22:17:51 UTC (rev 1737)
@@ -1,3 +1,3 @@
 # format version number, currently 2; this line is compulsory!
 version=2
-ftp://ftp.icm.edu.pl/mirrors/ftp.cpan.org/pub/CPAN/modules/by-module/FormValidator/FormValidator-Simple-([\d\.]+).tar.gz
+ftp://ftp.icm.edu.pl/mirrors/ftp.cpan.org/pub/CPAN/authors/id/L/LY/LYOKATO/FormValidator-Simple-([\d\.]+).tar.gz

Modified: packages/libformvalidator-simple-perl/trunk/lib/FormValidator/Simple/Messages.pm
===================================================================
--- packages/libformvalidator-simple-perl/trunk/lib/FormValidator/Simple/Messages.pm	2005-12-23 22:14:59 UTC (rev 1736)
+++ packages/libformvalidator-simple-perl/trunk/lib/FormValidator/Simple/Messages.pm	2005-12-23 22:17:51 UTC (rev 1737)
@@ -6,11 +6,20 @@
 sub new {
     my $class = shift;
     my $self  = bless {
-        _data => undef,
+        _data   => undef,
+        _format => "%s",
     }, $class;
     return $self;
 }
 
+sub format {
+    my ($self, $format) = @_;
+    if ($format) {
+        $self->{_format} = $format;
+    }
+    $self->{_format};
+}
+
 sub load {
     my ($self, $data) = @_;
     if (ref $data eq 'HASH') {
@@ -34,15 +43,38 @@
 }
 
 sub get {
+    my $self = shift;
+    my $msg  = $self->_get(@_);
+    return sprintf $self->format, $msg;
+}
+
+sub _get {
     my ($self, $action, $name, $type) = @_;
     my $data = $self->{_data};
     unless ($data) {
-    FormValidator::Simple::Exception->throw(
-    qq/set messages before calling get()./
-    );
+        FormValidator::Simple::Exception->throw(
+        qq/set messages before calling get()./
+        );
     }
-    unless ( exists $data->{$action} ) {
-        return "$name is invalid.";
+
+    unless ( $action && exists $data->{$action} ) {
+        if ( exists $data->{DEFAULT} ) {
+            if ( exists $data->{DEFAULT}{$name} ) {
+                my $conf = $data->{DEFAULT}{$name};
+                if ( exists $conf->{$type} ) {
+                    return $conf->{$type};
+                }
+                elsif ( exists $conf->{DEFAULT} ) {
+                    return $conf->{DEFAULT};
+                }
+            }
+            else {
+                return "$name is invalid.";
+            }
+        }
+        else {
+            return "$name is invalid.";
+        }
     }
     if ( exists $data->{$action}{$name} ) {
         my $conf = $data->{$action}{$name};
@@ -52,7 +84,27 @@
         elsif ( exists $conf->{DEFAULT} ) {
             return $conf->{DEFAULT};
         }
+        elsif ( exists  $data->{DEFAULT}
+              && exists $data->{DEFAULT}{$name} ) {
+            my $conf = $data->{DEFAULT}{$name};
+            if ( exists $conf->{$type} ) {
+                return $conf->{$type};
+            }
+            elsif ( exists $conf->{DEFAULT} ) {
+                return $conf->{DEFAULT};
+            }
+        }
     }
+    elsif ( exists $data->{DEFAULT}
+         && exists $data->{DEFAULT}{$name} ) {
+        my $conf = $data->{DEFAULT}{$name};
+        if ( exists $conf->{$type} ) {
+            return $conf->{$type};
+        }
+        elsif ( exists $conf->{DEFAULT} ) {
+            return $conf->{DEFAULT};
+        }
+    }
     return "$name is invalid.";
 }
 

Modified: packages/libformvalidator-simple-perl/trunk/lib/FormValidator/Simple/Validator.pm
===================================================================
--- packages/libformvalidator-simple-perl/trunk/lib/FormValidator/Simple/Validator.pm	2005-12-23 22:14:59 UTC (rev 1736)
+++ packages/libformvalidator-simple-perl/trunk/lib/FormValidator/Simple/Validator.pm	2005-12-23 22:17:51 UTC (rev 1737)
@@ -291,6 +291,16 @@
     return $data =~ /$reg/ ? TRUE : FALSE;
 }
 
+sub ALL {
+    my ($self, $params, $args) = @_;
+    foreach my $param ( @$params ) {
+        unless ( defined $param && $param ne '' ) {
+            return FALSE;
+        }
+    }
+    return TRUE;
+}
+
 1;
 __END__
 

Modified: packages/libformvalidator-simple-perl/trunk/lib/FormValidator/Simple.pm
===================================================================
--- packages/libformvalidator-simple-perl/trunk/lib/FormValidator/Simple.pm	2005-12-23 22:14:59 UTC (rev 1736)
+++ packages/libformvalidator-simple-perl/trunk/lib/FormValidator/Simple.pm	2005-12-23 22:17:51 UTC (rev 1737)
@@ -11,7 +11,7 @@
 use FormValidator::Simple::Constants;
 use FormValidator::Simple::Messages;
 
-our $VERSION = '0.11';
+our $VERSION = '0.13';
 
 __PACKAGE__->mk_accessors(qw/data prof results/);
 
@@ -58,6 +58,13 @@
     $class->messages->load($file);
 }
 
+sub set_message_format {
+    my ($proto, $format) = @_;
+    $format ||= '';
+    my $class = ref $proto || $proto;
+    $class->messages->format($format);
+}
+
 sub new {
     my $proto = shift;
     my $class = ref $proto || $proto;
@@ -227,7 +234,7 @@
 
 A hash reference includes input data, or an object of some class that has a method named 'param', for example L<CGI>, is needed as first argument.
 
-And set profile as array reference into second argument. Profile confists of some pairs of input data and constraints.
+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' );
@@ -539,13 +546,19 @@
 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');
 
@@ -566,6 +579,7 @@
         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 %]
@@ -574,6 +588,17 @@
         [% 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 %]
+
 =head1 RESULT HANDLING
 
 See L<FormValidator::Simple::Results>

Modified: packages/libformvalidator-simple-perl/trunk/t/22_messages.t
===================================================================
--- packages/libformvalidator-simple-perl/trunk/t/22_messages.t	2005-12-23 22:14:59 UTC (rev 1736)
+++ packages/libformvalidator-simple-perl/trunk/t/22_messages.t	2005-12-23 22:17:51 UTC (rev 1737)
@@ -1,9 +1,14 @@
 use strict;
-use Test::More tests => 5;
+use Test::More tests => 6;
 BEGIN{ use_ok("FormValidator::Simple") }
 use CGI;
 
 FormValidator::Simple->set_messages( {
+    DEFAULT => {
+        data4 => {
+            DEFAULT => 'input data4',    
+        },
+    },
     test => {
         data1 => {
             NOT_BLANK => 'input data1',
@@ -23,11 +28,13 @@
 $q->param( data1 => 'hoge' );
 $q->param( data2 => '123'  );
 $q->param( data3 => ''     );
+$q->param( data4 => ''     );
 
 my $r = 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 $messages = $r->messages('test');
@@ -35,4 +42,5 @@
 is($messages->[1], 'data1 has wrong length');
 is($messages->[2], 'default error for data2');
 is($messages->[3], 'input data3');
+is($messages->[4], 'input data4');
 

Modified: packages/libformvalidator-simple-perl/trunk/t/23_messages_yaml.t
===================================================================
--- packages/libformvalidator-simple-perl/trunk/t/23_messages_yaml.t	2005-12-23 22:14:59 UTC (rev 1736)
+++ packages/libformvalidator-simple-perl/trunk/t/23_messages_yaml.t	2005-12-23 22:17:51 UTC (rev 1737)
@@ -1,5 +1,5 @@
 use strict;
-use Test::More tests => 5;
+use Test::More tests => 9;
 BEGIN{ use_ok("FormValidator::Simple") }
 use CGI;
 my $conf_file = "t/conf/messages.yml";
@@ -22,3 +22,11 @@
 is($messages->[2], 'default error for data2');
 is($messages->[3], 'input data3');
 
+
+FormValidator::Simple->set_message_format('<p>%s</p>');
+my $messages2 = $r->messages('test');
+is($messages2->[0], '<p>input integer for data1</p>');
+is($messages2->[1], '<p>data1 has wrong length</p>');
+is($messages2->[2], '<p>default error for data2</p>');
+is($messages2->[3], '<p>input data3</p>');
+

Copied: packages/libformvalidator-simple-perl/trunk/t/25_all.t (from rev 1736, packages/libformvalidator-simple-perl/branches/upstream/current/t/25_all.t)




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