[Bps-public-commit] r11468 - in SVN-PropDB: bin

clkao at bestpractical.com clkao at bestpractical.com
Thu Apr 3 22:52:49 EDT 2008


Author: clkao
Date: Thu Apr  3 22:52:48 2008
New Revision: 11468

Modified:
   SVN-PropDB/bin/sd
   SVN-PropDB/lib/Prophet/CLI.pm
   SVN-PropDB/lib/Prophet/Collection.pm
   SVN-PropDB/lib/Prophet/Record.pm

Log:
move record/collection reference logic into appropriate places.


Modified: SVN-PropDB/bin/sd
==============================================================================
--- SVN-PropDB/bin/sd	(original)
+++ SVN-PropDB/bin/sd	Thu Apr  3 22:52:48 2008
@@ -10,13 +10,6 @@
 use base qw/Prophet::Record Class::Data::Inheritable/;
 __PACKAGE__->mk_classdata(REFERENCES => {});
 
-sub new {
-    my $class = shift;
-    my $args = shift;
-    Carp::cluck unless ref($args);
-    return $class->SUPER::new({ %$args, type => $class->record_type });
-}
-
 package SVB::Model::Ticket;
 use base qw/SVB::Record/;
 
@@ -26,7 +19,6 @@
 use constant summary_format => '%u %s %s';
 use constant summary_props => qw(summary status);
 
-
 sub validate_status {
     my ($self, %args) = @_;
 
@@ -47,22 +39,6 @@
                             );
 use Params::Validate;
 
-sub register_refers {
-    my ($class, $accessor, $model, @args) = @_;
-    my %args = validate( @args, { by => 1 });
-    no strict 'refs';
-    *{$class."::$accessor"} = sub {
-        my $self = shift;
-        my $collection = $model->new( handle => $self->handle, type => $model->record_class );
-        $collection->matching( sub { $_[0]->prop($args{by}) eq $self->uuid } );
-        return $collection;
-    };
-    # XXX: add validater for $args{by} in $model->record_class
-
-
-    $class->REFERENCES->{$accessor} = { %args, type => $model->record_class };
-}
-
 package SVB::Model::Comment;
 use base qw/SVB::Record/;
 

Modified: SVN-PropDB/lib/Prophet/CLI.pm
==============================================================================
--- SVN-PropDB/lib/Prophet/CLI.pm	(original)
+++ SVN-PropDB/lib/Prophet/CLI.pm	Thu Apr  3 22:52:48 2008
@@ -169,7 +169,7 @@
 
 sub _get_record {
 	my $self = shift;
-	return $self->record_class->new( { handle => $self->handle, type => $self->type } );
+	return $self->record_class->new( { handle => $self->handle } );
 }
 
 sub do_create {
@@ -191,8 +191,7 @@
     }
 
     my $record = $cli->_get_record;
-    my $records = $record->collection_class->new( handle => $cli->handle, type => $record->record_type );
-    warn $records;
+    my $records = $record->collection_class->new( handle => $cli->handle );
     $records->matching(
         sub {
             my $item  = shift;

Modified: SVN-PropDB/lib/Prophet/Collection.pm
==============================================================================
--- SVN-PropDB/lib/Prophet/Collection.pm	(original)
+++ SVN-PropDB/lib/Prophet/Collection.pm	Thu Apr  3 22:52:48 2008
@@ -35,7 +35,9 @@
     my $class = shift;
     my $self  = {};
     bless $self, $class;
-    my %args = validate( @_, { handle => 1, type => 1 } );
+    my $args  = ref($_[0]) ? $_[0] : { @_ };
+    $args->{type} ||= $class->record_class->record_type;
+    my %args  = validate( @{[%$args]}, { handle => 1, type => 1 } );
     $self->$_( $args{$_} ) for ( keys %args );
     return $self;
 }

Modified: SVN-PropDB/lib/Prophet/Record.pm
==============================================================================
--- SVN-PropDB/lib/Prophet/Record.pm	(original)
+++ SVN-PropDB/lib/Prophet/Record.pm	Thu Apr  3 22:52:48 2008
@@ -37,6 +37,7 @@
     my $class = shift;
     my $self  = bless {}, $class;
     my $args  = ref($_[0]) ? $_[0] : { @_ };
+    $args->{type} ||= $class->record_type;
     my %args  = validate( @{[%$args]}, { handle => 1, type => 1 } );
     $self->$_( $args{$_} ) for keys(%args);
     return $self;
@@ -44,6 +45,28 @@
 
 sub record_type { $_[0]->type }
 
+=head2 register_refers
+
+=cut
+
+sub register_refers {
+    my ($class, $accessor, $model, @args) = @_;
+    my %args = validate( @args, { by => 1 });
+    no strict 'refs';
+    *{$class."::$accessor"} = sub {
+        my $self = shift;
+        my $collection = $model->new( handle => $self->handle, type => $model->record_class );
+        $collection->matching( sub { $_[0]->prop($args{by}) eq $self->uuid } );
+        return $collection;
+    };
+    # XXX: add validater for $args{by} in $model->record_class
+
+
+    $class->REFERENCES->{$accessor} = { %args, type => $model->record_class };
+}
+
+
+
 =head2 create { props => { %hash_of_kv_pairs } }
 
 Creates a new Prophet database record in your database. Sets the record's properties to the keys and values passed in.



More information about the Bps-public-commit mailing list