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

clkao at bestpractical.com clkao at bestpractical.com
Thu Apr 3 21:30:54 EDT 2008


Author: clkao
Date: Thu Apr  3 21:30:53 2008
New Revision: 11460

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

Log:
minimum referenced model cli cmd redispatch.

Modified: SVN-PropDB/bin/sd
==============================================================================
--- SVN-PropDB/bin/sd	(original)
+++ SVN-PropDB/bin/sd	Thu Apr  3 21:30:53 2008
@@ -7,7 +7,8 @@
 
 
 package SVB::Record; # should probably be Prophet::App::Record
-use base qw/Prophet::Record/;
+use base qw/Prophet::Record Class::Data::Inheritable/;
+__PACKAGE__->mk_classdata(REFERENCES => {});
 
 sub new {
     my $class = shift;
@@ -53,8 +54,8 @@
     };
     # 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
+
+    $class->REFERENCES->{$accessor} = { %args, type => $model->record_class };
 }
 
 package SVB::Model::Comment;

Modified: SVN-PropDB/lib/Prophet/CLI.pm
==============================================================================
--- SVN-PropDB/lib/Prophet/CLI.pm	(original)
+++ SVN-PropDB/lib/Prophet/CLI.pm	Thu Apr  3 21:30:53 2008
@@ -44,9 +44,9 @@
     return $self->_resdb_handle();
 }
 
-=head2 record_cmd
+=head2 _record_cmd
 
-Returns a closure that handles the subcommand for a particular type
+handles the subcommand for a particular type
 
 =cut
 
@@ -60,23 +60,35 @@
     list => 'search'
 );
 
-sub record_cmd {
-    my ($self, $type, $record_class) = @_;
-    return sub {
-        my $cmd = shift @ARGV or die "record subcommand required";
-        $cmd =~ s/^--//g;
-        $cmd = $CMD_MAP{$cmd} if exists $CMD_MAP{$cmd};
-        my $func = $self->can("do_$cmd") or die "no such record command $cmd";
-        if ($record_class) {
-        	$self->record_class($record_class);
-        }
-        else {
-        	$self->record_class('Prophet::Record');
-	        $self->type($type);
-	    }
-        $self->parse_record_cmd_args();
-        $func->($self);
-    };
+sub _handle_reference_command {
+    my ($self, $class, $ref_spec) = @_;
+    # turn uuid arg into a prop at ref'ed class
+    my $by_type = $ref_spec->{by};
+    @ARGV = map { s/--uuid/--$by_type/; $_ } @ARGV;
+    unshift @ARGV, '--search', '--regex', '.'; # list only for now
+    $self->_record_cmd($ref_spec->{type}->record_type, $ref_spec->{type});
+}
+
+sub _record_cmd {
+    my ( $self, $type, $record_class ) = @_;
+    my $cmd = shift @ARGV or die "record subcommand required";
+    $cmd =~ s/^--//g;
+
+    if ( $record_class->REFERENCES->{$cmd} ) {
+        return $self->_handle_reference_command( $record_class, $record_class->REFERENCES->{$cmd} );
+    }
+
+    $cmd = $CMD_MAP{$cmd} if exists $CMD_MAP{$cmd};
+    my $func = $self->can("do_$cmd") or Carp::confess "no such record command $cmd";
+    if ($record_class) {
+        $self->record_class($record_class);
+    }
+    else {
+        $self->record_class('Prophet::Record');
+        $self->type($type);
+    }
+    $self->parse_record_cmd_args();
+    $func->($self);
 }
 
 =head2 register_types TYPES
@@ -87,16 +99,19 @@
 
 
 sub register_types {
-    my $self = shift;
+    my $self       = shift;
     my $model_base = shift;
-    my @types = (@_);
-    
+    my @types      = (@_);
+
     my $calling_package = (caller)[0];
     for my $type (@types) {
         no strict 'refs';
-        my $class = $model_base.'::'.ucfirst($type);
-         *{$calling_package."::cmd_".$type} = $self->record_cmd($type => $class);
-        }
+        my $class = $model_base . '::' . ucfirst($type);
+        *{ $calling_package . "::cmd_" . $type } =
+            sub {
+                $self->_record_cmd( $type => $class )
+            };
+    }
 }
 
 



More information about the Bps-public-commit mailing list