[Bast-commits] r3269 - in trunk/DBIx-Class-Validation: .
lib/DBIx/Class t
claco at dev.catalyst.perl.org
claco at dev.catalyst.perl.org
Wed May 9 00:52:02 GMT 2007
Author: claco
Date: 2007-05-09 00:52:01 +0100 (Wed, 09 May 2007)
New Revision: 3269
Modified:
trunk/DBIx-Class-Validation/Changes
trunk/DBIx-Class-Validation/README
trunk/DBIx-Class-Validation/lib/DBIx/Class/Validation.pm
trunk/DBIx-Class-Validation/t/pod_spelling.t
Log:
Fixed DBIC::Test comment snafu
Profiles can now be a subref that will dynamically generate the profile (John Napiorkowski)
Modified: trunk/DBIx-Class-Validation/Changes
===================================================================
--- trunk/DBIx-Class-Validation/Changes 2007-05-08 20:43:07 UTC (rev 3268)
+++ trunk/DBIx-Class-Validation/Changes 2007-05-08 23:52:01 UTC (rev 3269)
@@ -1,6 +1,9 @@
Revision history for DBIx::Class::Validation
+0.01003 Tue May 08 18:49:11 2007
- Fixed DBIC::Test comment snafu
+ - Profiles can now be a subref that will dynamically generate the
+ profile (John Napiorkowski)
0.01002 Sat May 05 11:38:16 2007
- Converted to Module::Install
Modified: trunk/DBIx-Class-Validation/README
===================================================================
--- trunk/DBIx-Class-Validation/README 2007-05-08 20:43:07 UTC (rev 3268)
+++ trunk/DBIx-Class-Validation/README 2007-05-08 23:52:01 UTC (rev 3269)
@@ -49,8 +49,32 @@
{ ... }
);
- Sets the profile that will be passed to the validation module.
+ Sets the profile that will be passed to the validation module. Expects
+ either a HASHREF or a reference to a subroutine. If it's a subref it
+ will be passed the result row object as it's first parameter so that you
+ can perform complex data validation for cases when you'd like to have
+ access to the actual result.
+ For example, you could use the following to return an error if the named
+ field is not unique in the table:
+
+ my $profile = sub {
+ my $result = shift @_;
+
+ return {`
+ required => [qw/email/],
+ constraint_methods => {
+ email => sub {
+ my ($dvf, $val) = @_;
+ return $result->result_source->resultset->find({email=>$val}) ? 0:1;
+ },
+ },
+ };
+ };
+
+ Please note that the subref needs to return a hashref/arrayref suitable
+ for use in the validation module you have chosen.
+
validation_auto
__PACKAGE__->validation_auto( 1 );
@@ -94,7 +118,8 @@
Aran C. Deltac <bluefeet at cpan.org>
CONTRIBUTERS
- Tom Kirkpatrick <tkp at cpan.org> Christopher Laco <claco at cpan.org>
+ Tom Kirkpatrick <tkp at cpan.org> Christopher Laco <claco at cpan.org> John
+ Napiorkowski <jjn1056 at yahoo.com>
LICENSE
You may distribute this code under the same terms as Perl itself.
Modified: trunk/DBIx-Class-Validation/lib/DBIx/Class/Validation.pm
===================================================================
--- trunk/DBIx-Class-Validation/lib/DBIx/Class/Validation.pm 2007-05-08 20:43:07 UTC (rev 3268)
+++ trunk/DBIx-Class-Validation/lib/DBIx/Class/Validation.pm 2007-05-08 23:52:01 UTC (rev 3269)
@@ -10,7 +10,7 @@
#local $^W = 0; # Silence C:D:I redefined sub errors.
# Switched to C::D::Accessor which doesn't do this. Hate hate hate hate.
-our $VERSION = '0.01002';
+our $VERSION = '0.01003';
__PACKAGE__->mk_classdata( 'validation_profile' );
__PACKAGE__->mk_classdata( 'validation_auto' => 1 );
@@ -106,8 +106,31 @@
{ ... }
);
-Sets the profile that will be passed to the validation module.
+Sets the profile that will be passed to the validation module. Expects either
+a HASHREF or a reference to a subroutine. If it's a subref it will be passed
+the result row object as it's first parameter so that you can perform complex
+data validation for cases when you'd like to have access to the actual result.
+For example, you could use the following to return an error if the named field
+is not unique in the table:
+
+ my $profile = sub {
+ my $result = shift @_;
+
+ return {`
+ required => [qw/email/],
+ constraint_methods => {
+ email => sub {
+ my ($dvf, $val) = @_;
+ return $result->result_source->resultset->find({email=>$val}) ? 0:1;
+ },
+ },
+ };
+ };
+
+Please note that the subref needs to return a hashref/arrayref suitable for use
+in the validation module you have chosen.
+
=head2 validation_auto
__PACKAGE__->validation_auto( 1 );
@@ -203,6 +226,7 @@
Tom Kirkpatrick <tkp at cpan.org>
Christopher Laco <claco at cpan.org>
+John Napiorkowski <jjn1056 at yahoo.com>
=head1 LICENSE
Modified: trunk/DBIx-Class-Validation/t/pod_spelling.t
===================================================================
--- trunk/DBIx-Class-Validation/t/pod_spelling.t 2007-05-08 20:43:07 UTC (rev 3268)
+++ trunk/DBIx-Class-Validation/t/pod_spelling.t 2007-05-08 23:52:01 UTC (rev 3269)
@@ -26,3 +26,5 @@
INSERTs
UPDATEs
pre
+subref
+Napiorkowski
More information about the Bast-commits
mailing list