[Bps-public-commit] r11473 - in SVN-PropDB: . bin lib/Prophet t/lib/TestApp

jesse at bestpractical.com jesse at bestpractical.com
Thu Apr 3 23:31:55 EDT 2008


Author: jesse
Date: Thu Apr  3 23:31:55 2008
New Revision: 11473

Modified:
   SVN-PropDB/   (props changed)
   SVN-PropDB/bin/sd
   SVN-PropDB/lib/Prophet/Record.pm
   SVN-PropDB/lib/Prophet/Sync/Source/RT.pm
   SVN-PropDB/t/lib/TestApp/Bug.pm

Log:
 r29137 at 70-5-183-240:  jesse | 2008-04-03 17:30:43 -1000
 * changes to how validators and canonicalizers work


Modified: SVN-PropDB/bin/sd
==============================================================================
--- SVN-PropDB/bin/sd	(original)
+++ SVN-PropDB/bin/sd	Thu Apr  3 23:31:55 2008
@@ -15,9 +15,13 @@
 use constant collection_class => 'SVB::Collection::Ticket';
 use constant record_type => 'ticket';
 
+
 use constant summary_format => '%u %s %s';
 use constant summary_props => qw(summary status);
 
+
+
+
 sub validate_status {
     my ($self, %args) = @_;
     # XXX: validater not called when a value is unset, so can't do
@@ -34,11 +38,10 @@
 #has status
 #has owner
 
-__PACKAGE__->register_refers( comments => 'SVB::Collection::Comment',
+__PACKAGE__->register_reference( comments => 'SVB::Collection::Comment',
                               by => 'ticket'
                             );
-use Params::Validate;
-
+                            
 package SVB::Model::Comment;
 use base qw/SVB::Record/;
 
@@ -50,9 +53,14 @@
 
 #has SVK::Model::Ticket;
 
+__PACKAGE__->register_reference( ticket => 'SVB::Model::Comment');
+
+
 package SVB::Collection::Ticket;
 use base 'Prophet::Collection';
 
+
+
 use constant record_class => 'SVB::Model::Ticket';
 
 package SVB::Collection::Comment;

Modified: SVN-PropDB/lib/Prophet/Record.pm
==============================================================================
--- SVN-PropDB/lib/Prophet/Record.pm	(original)
+++ SVN-PropDB/lib/Prophet/Record.pm	Thu Apr  3 23:31:55 2008
@@ -17,15 +17,17 @@
 
 __PACKAGE__->mk_accessors(qw'handle uuid type');
 __PACKAGE__->mk_classdata(REFERENCES => {});
+__PACKAGE__->mk_classdata(declared_props => {});
 
 use Params::Validate;
 use Prophet::HistoryEntry;
 use Data::UUID;
-
+use List::MoreUtils qw/uniq/;
 my $UUIDGEN = Data::UUID->new();
 
 use constant collection_class => 'Prophet::Collection';
 
+
 =head1 METHODS
 
 =head2 new  { handle => Prophet::Handle, type => $type }
@@ -46,7 +48,7 @@
 
 sub record_type { $_[0]->type }
 
-=head2 register_refers $accessor, $collection_class, by => $key_in_model
+=head2 register_reference $accessor, $collection_class, by => $key_in_model
 
 Registers and create accessor in current class the associated
 collection C<$collection_class>, which refers to the current class by
@@ -54,7 +56,7 @@
 
 =cut
 
-sub register_refers {
+sub register_reference {
     my ($class, $accessor, $collection_class, @args) = @_;
     my %args = validate( @args, { by => 1 });
     no strict 'refs';
@@ -88,8 +90,8 @@
     my %args = validate( @_, { props => 1 } );
     my $uuid = $UUIDGEN->create_str;
 
-    $self->_canonicalize_props( $args{'props'} );
-    $self->_validate_props( $args{'props'} ) or return undef;
+    $self->canonicalize_props( $args{'props'} );
+    $self->validate_props( $args{'props'} ) or return undef;
 
     $self->uuid($uuid);
 
@@ -145,8 +147,8 @@
     my $self = shift;
     my %args = validate( @_, { props => 1 } );
 
-    $self->_canonicalize_props( $args{'props'} );
-    $self->_validate_props( $args{'props'} );
+    $self->canonicalize_props( $args{'props'} );
+    $self->validate_props( $args{'props'} );
     $self->handle->set_node_props( type => $self->type, uuid => $self->uuid, props => $args{'props'} );
 }
 
@@ -202,13 +204,14 @@
 
 }
 
-sub _validate_props {
+
+sub validate_props {
     my $self   = shift;
     my $props  = shift;
     my $errors = {};
-    for my $key ( keys %$props ) {
+    for my $key ( uniq(keys %$props, $self->declared_props) ) {
         return undef unless ( $self->_validate_prop_name($key) );
-        if ( my $sub = $self->can( 'validate_' . $key ) ) {
+        if ( my $sub = $self->can( 'validate_prop_' . $key ) ) {
             $sub->( $self, props => $props, errors => $errors ) or die "validation error on $key: $errors->{$key}\n";
         }
     }
@@ -217,12 +220,12 @@
 
 sub _validate_prop_name {1}
 
-sub _canonicalize_props {
+sub canonicalize_props {
     my $self   = shift;
     my $props  = shift;
     my $errors = {};
-    for my $key ( keys %$props ) {
-        if ( my $sub = $self->can( 'canonicalize_' . $key ) ) {
+    for my $key ( uniq(keys %$props, $self->declared_props) ) {
+        if ( my $sub = $self->can( 'canonicalize_prop_' . $key ) ) {
             $sub->( $self, props => $props, errors => $errors );
         }
     }

Modified: SVN-PropDB/lib/Prophet/Sync/Source/RT.pm
==============================================================================
--- SVN-PropDB/lib/Prophet/Sync/Source/RT.pm	(original)
+++ SVN-PropDB/lib/Prophet/Sync/Source/RT.pm	Thu Apr  3 23:31:55 2008
@@ -152,10 +152,10 @@
 }
 
 
-
-sub _recode_txn_EmailRecord {
-    return;
-}
+sub _recode_txn_EmailRecord { return ;}
+sub _recode_txn_AddReminder { return ;}
+sub _recode_txn_ResolveReminder { return ;}
+sub _recode_txn_DeleteLink {}
 
 sub _recode_txn_Status {
     my $self = shift;

Modified: SVN-PropDB/t/lib/TestApp/Bug.pm
==============================================================================
--- SVN-PropDB/t/lib/TestApp/Bug.pm	(original)
+++ SVN-PropDB/t/lib/TestApp/Bug.pm	Thu Apr  3 23:31:55 2008
@@ -8,7 +8,7 @@
 sub new { shift->SUPER::new( @_, type => 'bug') }
 
 
-sub validate_name { 
+sub validate_prop_name { 
     my $self = shift;
     my %args = (@_);
 
@@ -18,7 +18,7 @@
 
 }
 
-sub canonicalize_email {
+sub canonicalize_prop_email {
     my $self = shift;
     my %args = (@_);
     $args{props}->{email} = lc($args{props}->{email});



More information about the Bps-public-commit mailing list