[Bps-public-commit] r15534 - in sd/trunk: . lib/App/SD lib/App/SD/CLI

sartak at bestpractical.com sartak at bestpractical.com
Wed Aug 27 11:26:43 EDT 2008


Author: sartak
Date: Wed Aug 27 11:26:42 2008
New Revision: 15534

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

Log:
Merge dispatcher branch in

Modified: sd/trunk/bin/sd
==============================================================================
--- sd/trunk/bin/sd	(original)
+++ sd/trunk/bin/sd	Wed Aug 27 11:26:42 2008
@@ -1,8 +1,7 @@
 #!/usr/bin/env perl 
 use warnings;
 use strict;
-use Prophet::CLI;
-use App::SD;
+use App::SD::CLI;
 
 $ENV{'PROPHET_REPO'} = $ENV{'SD_REPO'} || $ENV{'HOME'}.'/.sd';
 
@@ -19,6 +18,6 @@
     };
 }
 
-my $cli = Prophet::CLI->new({ app_class => 'App::SD' });
+my $cli = App::SD::CLI->new;
 $cli->run_one_command;
 

Added: sd/trunk/lib/App/SD/CLI.pm
==============================================================================
--- (empty file)
+++ sd/trunk/lib/App/SD/CLI.pm	Wed Aug 27 11:26:42 2008
@@ -0,0 +1,19 @@
+#!/usr/bin/env perl
+package App::SD::CLI;
+use Moose;
+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;
+
+1;
+

Added: sd/trunk/lib/App/SD/CLI/Dispatcher.pm
==============================================================================
--- (empty file)
+++ sd/trunk/lib/App/SD/CLI/Dispatcher.pm	Wed Aug 27 11:26:42 2008
@@ -0,0 +1,37 @@
+#!/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 %args = @_;
+    $args{context}->set_arg(type => $1);
+    run($2, %args);
+};
+
+on qr{.} => sub {
+    my %args = @_;
+
+    my @pieces = map { ucfirst lc $_ } __PACKAGE__->resolve_builtin_aliases(@{ $args{dispatching_on} });
+
+    my @possible_classes;
+    while (@pieces) {
+        push @possible_classes, "App::SD::CLI::Command::"
+                              . join '::', @pieces;
+        shift @pieces;
+    }
+
+    my $cli = $args{cli};
+
+    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