[Bps-public-commit] r16458 - in sd/branches/sd-dispatcher: .

sartak at bestpractical.com sartak at bestpractical.com
Tue Oct 21 17:12:17 EDT 2008


Author: sartak
Date: Tue Oct 21 17:12:17 2008
New Revision: 16458

Modified:
   sd/branches/sd-dispatcher/   (props changed)
   sd/branches/sd-dispatcher/lib/App/SD/CLI/Dispatcher.pm

Log:
 r74332 at onn:  sartak | 2008-10-21 17:12:12 -0400
 Begin rewriting


Modified: sd/branches/sd-dispatcher/lib/App/SD/CLI/Dispatcher.pm
==============================================================================
--- sd/branches/sd-dispatcher/lib/App/SD/CLI/Dispatcher.pm	(original)
+++ sd/branches/sd-dispatcher/lib/App/SD/CLI/Dispatcher.pm	Tue Oct 21 17:12:17 2008
@@ -6,18 +6,21 @@
 on qr'^\?(.*)$' => sub {my $cmd = $1 || '';  redispatch('help'. $cmd,  @_); last_rule;};
 
 # 'sd about' -> 'sd help about', 'sd copying' -> 'sd help copying'
-on qr'^(about|copying)$' => sub { redispatch('help '.$1, @_); last_rule;};
-on qr'^help (?:push|pull|publish|server)$' => sub { redispatch('help sync', @_); last_rule;};
-on qr'^help (?:env)$' => sub { redispatch('help environment', @_); last_rule;};
-on qr'^help (?:ticket)$' => sub { redispatch('help tickets', @_); last_rule;};
-on qr'^help ticket (list|search|find)$' => sub { redispatch('help search', @_); last_rule;};
-on qr'^help (?:list|find)$' => sub { redispatch('help search', @_); last_rule;};
+on [ ['about', 'copying'] ] => sub { redispatch("help $1", @_); };
 
-on qr{ticket \s+ give \s+ (.*) \s+ (.*)}xi => sub {
+under help => sub {
+    rewrite [ ['push', 'pull', 'publish', 'server'] ] => 'help sync';
+    rewrite 'env' => 'help environment';
+    rewrite 'ticket' => 'help tickets';
+    rewrite [ 'ticket', ['list', 'search', 'find'] ] => 'help search';
+    rewrite [ ['list', 'find'] ] => 'help search';
+};
+
+on ['ticket', 'give', qr/.*/, qr/.*/] => sub {
     my $self = shift;
-    $self->context->set_arg(type => 'ticket');
-    $self->context->set_arg(id => $1);
-    $self->context->set_arg(owner => $2);
+    $self->context->set_arg(type  => 'ticket');
+    $self->context->set_arg(id    => $3);
+    $self->context->set_arg(owner => $4);
     redispatch('update', $self, @_);
 };
 
@@ -29,40 +32,6 @@
     redispatch($2, $self, @_);
 };
 
-#on qr'^about$' => sub { redispatch(('help about'); last_rule;};
-
-
-# Run class based commands
-on qr{.} => sub {
-    my $self = shift;
-    my $cli = $self->cli;
-
-    my @possible_classes;
-
-    # we want to dispatch on the original command "ticket attachment create"
-    # AND on the command we received "create"
-    for ([@{ $self->dispatching_on }], [split ' ', $_]) {
-        my @pieces = __PACKAGE__->resolve_builtin_aliases(@$_);
-
-        while (@pieces) {
-            push @possible_classes, "App::SD::CLI::Command::" . join '::', @pieces;
-            shift @pieces;
-        }
-    }
-
-    for my $class (@possible_classes) {
-        next unless Prophet::App->try_to_require($class);
-        if (!$class->isa('App::SD::CLI::Command')) {
-            warn "$class is not a subclass of App::SD::CLI::Command!";
-            next;
-        }
-
-        return $class->run;
-    }
-
-    # found no class-based rule
-    next_rule;
-};
 
 __PACKAGE__->dispatcher->add_rule(
     Path::Dispatcher::Rule::Dispatch->new(
@@ -70,29 +39,6 @@
     ),
 );
 
-my %CMD_MAP = (
-    ls      => 'search',
-    new     => 'create',
-    edit    => 'update',
-    rm      => 'delete',
-    del     => 'delete',
-    list    => 'search',
-    display => 'show',
-);
-
-sub resolve_builtin_aliases {
-    my $self = shift;
-    my @cmds = @_;
-
-    if (my $replacement = $CMD_MAP{ lc $cmds[-1] }) {
-        $cmds[-1] = $replacement;
-    }
-
-    @cmds = map { ucfirst lc } @cmds;
-
-    return wantarray ? @cmds : $cmds[-1];
-}
-
 __PACKAGE__->meta->make_immutable;
 no Moose;
 



More information about the Bps-public-commit mailing list