[Bps-public-commit] r16057 - in Prophet/branches/dispatcher: lib/Prophet lib/Prophet/CLI
sartak at bestpractical.com
sartak at bestpractical.com
Thu Sep 25 14:34:29 EDT 2008
Author: sartak
Date: Thu Sep 25 14:34:25 2008
New Revision: 16057
Modified:
Prophet/branches/dispatcher/ (props changed)
Prophet/branches/dispatcher/lib/Prophet/CLI.pm
Prophet/branches/dispatcher/lib/Prophet/CLI/Dispatcher.pm
Log:
r72450 at onn: sartak | 2008-09-25 14:32:59 -0400
Begin fleshing out the dispatcher with commands and attributes
Modified: Prophet/branches/dispatcher/lib/Prophet/CLI.pm
==============================================================================
--- Prophet/branches/dispatcher/lib/Prophet/CLI.pm (original)
+++ Prophet/branches/dispatcher/lib/Prophet/CLI.pm Thu Sep 25 14:34:25 2008
@@ -87,11 +87,10 @@
my $dispatcher = $self->dispatcher_class->new(
cli => $self,
- context => $self->context,
dispatching_on => $args,
);
- $dispatcher->run($command, %dispatcher_args);
+ $dispatcher->run($command, $dispatcher);
}
=head2 invoke outhandle, ARGV_COMPATIBLE_ARRAY
Modified: Prophet/branches/dispatcher/lib/Prophet/CLI/Dispatcher.pm
==============================================================================
--- Prophet/branches/dispatcher/lib/Prophet/CLI/Dispatcher.pm (original)
+++ Prophet/branches/dispatcher/lib/Prophet/CLI/Dispatcher.pm Thu Sep 25 14:34:25 2008
@@ -1,70 +1,48 @@
package Prophet::CLI::Dispatcher;
-use strict;
-use warnings;
use Path::Dispatcher::Declarative -base;
+use Moose;
-# "ticket display $ID" -> "ticket display --id=$ID"
-on qr{ (.*) \s+ ( \d+ | [A-Z0-9]{36} ) $ }x => sub {
- my %args = @_;
- $args{cli}->set_arg(id => $2);
- run($1, %args);
-};
-
-on qr{^(\w+)} => sub {
- my %args = @_;
-
- my $cmd = __PACKAGE__->resolve_builtin_aliases($1);
-
- my @possible_classes = (
- ("Prophet::CLI::Command::" . ucfirst lc $cmd),
- "Prophet::CLI::Command::NotFound",
- );
-
- my $cli = $args{cli};
-
- for my $class (@possible_classes) {
- if ($cli->_try_to_load_cmd_class($class)) {
- return $args{got_command}->($class);
- }
- }
-};
+use Prophet::CLI;
-on qr{^\s*$} => sub {
- run(__PACKAGE__->default_command, @_);
+has cli => (
+ is => 'rw',
+ isa => 'Prophet::CLI',
+ required => 1,
+);
-};
+has context => (
+ is => 'rw',
+ isa => 'Prophet::CLIContext',
+ lazy => 1,
+ default => sub {
+ my $self = shift;
+ $self->cli->context;
+ },
+);
-my %CMD_MAP = (
- ls => 'search',
- new => 'create',
- edit => 'update',
- rm => 'delete',
- del => 'delete',
- list => 'search',
- display => 'show',
+has dispatching_on => (
+ is => 'rw',
+ isa => 'ArrayRef',
+ required => 1,
);
-sub resolve_builtin_aliases {
+on ['server'] => sub {
my $self = shift;
- my @cmds = @_;
-
- if (my $replacement = $CMD_MAP{ lc $cmds[-1] }) {
- $cmds[-1] = $replacement;
- }
-
- @cmds = map { ucfirst lc } @cmds;
+ my $server = $self->setup_server;
+ $server->run;
+};
- return wantarray ? @cmds : $cmds[-1];
+sub setup_server {
+ my $self = shift;
+ require Prophet::Server;
+ my $server = Prophet::Server->new($self->context->arg('port') || 8080);
+ $server->app_handle($self->context->app_handle);
+ $server->setup_template_roots;
+ return $server;
}
-=head2 default_command
-
-Returns the "default" command for use when no arguments were specified on the
-command line. In Prophet, it's "shell" but your subclass can change that.
-
-=cut
-
-sub default_command { "shell" }
+no Moose;
+__PACKAGE__->meta->make_immutable;
1;
More information about the Bps-public-commit
mailing list