[Bps-public-commit] Prophet branch, master, updated. 0.742-10-ge09f46c

Shawn Moore sartak at bestpractical.com
Fri Jun 18 16:41:31 EDT 2010


The branch, master has been updated
       via  e09f46c7cd8bf2e373d16b2e69c890a72e746a79 (commit)
      from  746a38aa77f8b524f3eb342e1fa15e788e59f1d3 (commit)

Summary of changes:
 lib/Prophet/CLI.pm                 |    4 +++-
 lib/Prophet/CLI/Command/Shell.pm   |    2 +-
 lib/Prophet/CLI/Dispatcher.pm      |    2 ++
 lib/Prophet/CLI/Dispatcher/Rule.pm |    8 +-------
 lib/Prophet/CLI/Parameters.pm      |   21 +++++++--------------
 5 files changed, 14 insertions(+), 23 deletions(-)

- Log -----------------------------------------------------------------
commit e09f46c7cd8bf2e373d16b2e69c890a72e746a79
Author: Shawn M Moore <sartak at bestpractical.com>
Date:   Fri Jun 18 16:42:04 2010 -0400

    Refactor cli to be dynamic so we actually have access to it everywhere
    
        Threading it through all the places we need it just isn't working
        for dispatchery stuff

diff --git a/lib/Prophet/CLI.pm b/lib/Prophet/CLI.pm
index f344514..5851524 100644
--- a/lib/Prophet/CLI.pm
+++ b/lib/Prophet/CLI.pm
@@ -120,7 +120,7 @@ sub run_one_command {
     #  really, we shouldn't be doing this stuff from the command dispatcher
     $self->context( Prophet::CLIContext->new( app_handle => $self->app_handle ) );
     $self->context->setup_from_args(@args);
-    my $dispatcher = $self->dispatcher_class->new( cli => $self );
+    my $dispatcher = $self->dispatcher_class->new;
 
     # Path::Dispatcher is string-based, so we need to join the args
     # hash with spaces before passing off (args with whitespace in
@@ -129,6 +129,8 @@ sub run_one_command {
             s/"/\\"/g;  # escape double quotes
             /\s/ ? qq{"$_"} : $_;
         } @{ $self->context->primary_commands });
+
+    local $Prophet::CLI::Dispatcher::cli = $self;
     my $dispatch = $dispatcher->dispatch( $dispatch_command_string );
     $self->start_pager();
     $dispatch->run($dispatcher);
diff --git a/lib/Prophet/CLI/Command/Shell.pm b/lib/Prophet/CLI/Command/Shell.pm
index e1d508b..16427cc 100644
--- a/lib/Prophet/CLI/Command/Shell.pm
+++ b/lib/Prophet/CLI/Command/Shell.pm
@@ -101,7 +101,7 @@ sub _complete {
     # we can't just use $last_word because we want all the text before the cursor to
     # matter, not just the current word
 
-    my $dispatcher = $self->cli->dispatcher_class->new(cli => $self->cli);
+    my $dispatcher = $self->cli->dispatcher_class->new;
 
     # We're supposed to return only the completion of $last_word, not replacements
     # of $line. So for a completion that returns multiple words, this could screw
diff --git a/lib/Prophet/CLI/Dispatcher.pm b/lib/Prophet/CLI/Dispatcher.pm
index 7842de2..03fe193 100644
--- a/lib/Prophet/CLI/Dispatcher.pm
+++ b/lib/Prophet/CLI/Dispatcher.pm
@@ -7,6 +7,8 @@ use Prophet::CLI::Dispatcher::Rule::RecordId;
 
 with 'Prophet::CLI::Parameters';
 
+our $cli;
+
 our @PREFIXES = qw(Prophet::CLI::Command);
 sub add_command_prefix { unshift @PREFIXES, @_ }
 
diff --git a/lib/Prophet/CLI/Dispatcher/Rule.pm b/lib/Prophet/CLI/Dispatcher/Rule.pm
index 0988e8e..0294859 100644
--- a/lib/Prophet/CLI/Dispatcher/Rule.pm
+++ b/lib/Prophet/CLI/Dispatcher/Rule.pm
@@ -1,12 +1,6 @@
 package Prophet::CLI::Dispatcher::Rule;
 use Any::Moose 'Role';
-
-has cli => (
-    is        => 'rw',
-    isa       => 'Prophet::CLI',
-    weak_ref  => 1,
-    predicate => 'has_cli',
-);
+with 'Prophet::CLI::Parameters';
 
 no Any::Moose 'Role';
 
diff --git a/lib/Prophet/CLI/Parameters.pm b/lib/Prophet/CLI/Parameters.pm
index 2e6112d..8771cc3 100644
--- a/lib/Prophet/CLI/Parameters.pm
+++ b/lib/Prophet/CLI/Parameters.pm
@@ -2,21 +2,14 @@
 package Prophet::CLI::Parameters;
 use Any::Moose 'Role';
 
-has cli => (
-    is       => 'rw',
-    isa      => 'Prophet::CLI',
-    required => 1,
-);
+sub cli {
+    return $Prophet::CLI::Dispatcher::cli;
+}
 
-has context => (
-    is       => 'rw',
-    isa      => 'Prophet::CLIContext',
-    lazy     => 1,
-    default  => sub {
-        my $self = shift;
-        $self->cli->context;
-    },
-);
+sub context {
+    my $self = shift;
+    $self->cli->context;
+}
 
 no Any::Moose;
 

-----------------------------------------------------------------------



More information about the Bps-public-commit mailing list