[Bps-public-commit] r11457 - SVN-PropDB/bin

clkao at bestpractical.com clkao at bestpractical.com
Thu Apr 3 21:04:34 EDT 2008


Author: clkao
Date: Thu Apr  3 21:04:22 2008
New Revision: 11457

Modified:
   SVN-PropDB/bin/sd

Log:
first cut of reference accessor.

Modified: SVN-PropDB/bin/sd
==============================================================================
--- SVN-PropDB/bin/sd	(original)
+++ SVN-PropDB/bin/sd	Thu Apr  3 21:04:22 2008
@@ -30,13 +30,32 @@
     $args{errors}{status} = 'hate';
     return 0;
 
-    
 }
 
 #has many SVK::Model::Comment
 #has status
 #has owner
 
+__PACKAGE__->register_refers( comments => 'SVB::Collection::Comment',
+                              by => 'ticket'
+                            );
+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
+
+    # XXX: register in a hash so Prophet::CLI can create subcommand
+    # for listing and add new $model associated with $class
+}
 
 package SVB::Model::Comment;
 use base qw/SVB::Record/;
@@ -45,13 +64,25 @@
 
 #has SVK::Model::Ticket;
 
+package SVB::Collection::Comment;
+use base 'Prophet::Collection';
+
+use constant record_class => 'SVB::Model::Comment';
+
+sub new {
+    my $class = shift;
+    my %args = @_;
+    return $class->SUPER::new({ %args, type => $class->record_class->record_type });
+}
+
+
 package main;
 use Prophet::CLI;
 
 $ENV{'PROPHET_REPO'} = $ENV{'SVB_REPO'} || $ENV{'HOME'}.'/.svb';
 
 my $CLI = Prophet::CLI->new( {  } );
-$CLI->register_types('SVB::Model' => qw(ticket));
+$CLI->register_types('SVB::Model' => qw(ticket comment));
 
 my $command = shift @ARGV;
 
@@ -79,6 +110,23 @@
 }
 
 
+sub cmd_comments {
+    my ($ticket) = @ARGV;
+    my $record = SVB::Model::Ticket->new( { handle => $CLI->handle } );
+    $record->load( uuid => $ticket );
+    print "id: " . $record->uuid . "\n";
+    unless (@{$record->comments}) {
+        print "No commnets found\n";
+    }
+
+    for (@{$record->comments}) {
+        print "comment id: ".$_->uuid."\n";
+        print "Content:\n".$_->prop('content');
+        print "\n\n";
+    }
+
+}
+
 sub cmd_push {
 
     # Trivial first pass:



More information about the Bps-public-commit mailing list