[Bps-public-commit] r14863 - in sd/branches/dispatcher: . lib/App/SD/CLI

sartak at bestpractical.com sartak at bestpractical.com
Wed Aug 6 14:05:48 EDT 2008


Author: sartak
Date: Wed Aug  6 14:05:48 2008
New Revision: 14863

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

Log:
 r68891 at onn:  sartak | 2008-08-06 14:05:36 -0400
 Most of the SD dispatcher


Modified: sd/branches/dispatcher/lib/App/SD/CLI.pm
==============================================================================
--- sd/branches/dispatcher/lib/App/SD/CLI.pm	(original)
+++ sd/branches/dispatcher/lib/App/SD/CLI.pm	Wed Aug  6 14:05:48 2008
@@ -4,11 +4,14 @@
 extends 'Prophet::CLI';
 
 use App::SD;
+use App::SD::CLI::Dispatcher;
 
 has '+app_class' => (
     default => 'App::SD',
 );
 
+sub dispatcher { "App::SD::CLI::Dispatcher" }
+
 __PACKAGE__->meta->make_immutable;
 no Moose;
 

Added: sd/branches/dispatcher/lib/App/SD/CLI/Dispatcher.pm
==============================================================================
--- (empty file)
+++ sd/branches/dispatcher/lib/App/SD/CLI/Dispatcher.pm	Wed Aug  6 14:05:48 2008
@@ -0,0 +1,36 @@
+#!/usr/bin/env perl
+package App::SD::CLI::Dispatcher;
+use strict;
+use warnings;
+use Prophet::CLI::Dispatcher -base;
+
+on qr{^(ticket|comment|attachment) \s+ (.*)}xi => sub {
+    my $cli = shift;
+    $cli->set_arg(type => $1);
+    run($2, $cli, @_);
+};
+
+on qr{.} => sub {
+    my $cli = shift;
+    my %args = @_;
+
+    my @pieces = @{ $args{dispatching_on} };
+
+    my @possible_classes;
+    while (@pieces) {
+        push @possible_classes, "App::SD::CLI::Command::"
+                              . join '::', @pieces;
+        shift @pieces;
+    }
+
+    for my $class (@possible_classes) {
+        if ($cli->_try_to_load_cmd_class($class)) {
+            return $args{got_command}->($class);
+        }
+    }
+
+    next_rule;
+};
+
+1;
+



More information about the Bps-public-commit mailing list