summary refs log tree commit diff
path: root/lib/Net/HTTP/Console/Dispatcher/Help.pm
diff options
context:
space:
mode:
authorfranck cuny <franck@lumberjaph.net>2010-06-08 15:22:36 +0200
committerfranck cuny <franck@lumberjaph.net>2010-06-08 15:22:36 +0200
commit78fcbf54a4305e1ee6c3a105f91af40c7ea0a62a (patch)
treec4eb6cec29a92076c2f6fc47ca318cbe59f5e0ba /lib/Net/HTTP/Console/Dispatcher/Help.pm
parentupdate regex; modify http methods; .. (diff)
downloadnet-http-console-78fcbf54a4305e1ee6c3a105f91af40c7ea0a62a.tar.gz
switch to MX::Declare; rename some roles and dispatcher
Diffstat (limited to 'lib/Net/HTTP/Console/Dispatcher/Help.pm')
-rw-r--r--lib/Net/HTTP/Console/Dispatcher/Help.pm83
1 files changed, 39 insertions, 44 deletions
diff --git a/lib/Net/HTTP/Console/Dispatcher/Help.pm b/lib/Net/HTTP/Console/Dispatcher/Help.pm
index 7055b2b..a7a774b 100644
--- a/lib/Net/HTTP/Console/Dispatcher/Help.pm
+++ b/lib/Net/HTTP/Console/Dispatcher/Help.pm
@@ -1,66 +1,61 @@
 package Net::HTTP::Console::Dispatcher::Help;
 
-use Moose;
-with qw/Net::HTTP::Console::Dispatcher/;
+use MooseX::Declare;
 
-sub dispatch {
-    my ($self, $input) = @_;
+class Net::HTTP::Console::Dispatcher::Help with Net::HTTP::Console::Dispatcher {
 
-    (my $cmd, my $cmd_name) = $input =~ /^help\s(\w+)?\s?(\w+)?/;
+    method dispatch($input) {
+        (my $cmd, my $cmd_name) = $input =~ /^help\s(\w+)?\s?(\w+)?/;
 
-    if ($cmd) {
-        if ($cmd eq 'command' && $cmd_name) {
-            $self->_get_help_for_command($cmd_name);
+        if ($cmd) {
+            if ($cmd eq 'command' && $cmd_name) {
+                $self->_get_help_for_command($cmd_name);
+            }
+            elsif ($cmd eq 'command') {
+                $self->_list_commands();
+            }
         }
-        elsif ($cmd eq 'command') {
-            $self->_list_commands();
+        else {
+            $self->_display_help();
         }
+        1;
     }
-    else {
-        $self->_display_help();
-    }
-    1;
-}
 
-sub pattern {
-    my ($self, $input) = @_;
-    $input =~ /^help/ ? return $input : return 0;
-}
+    method pattern($input) {
+        $input =~ /^help/ ? return $input : return 0;
+    }
 
-sub _display_help {
-    print <<EOF
+    method _display_help {
+        print <<EOF
 help command    -  help about a command
 help request    -  help on how to write request
 EOF
-}
-
-sub _list_commands {
-    my $self = shift;
-    my @methods =
-      $self->application->api_object->meta->get_all_net_api_methods();
-
-    if (!@methods) {
-        print "no method available\n";
-        return;
     }
 
-    print "available commands:\n";
-    map { print "- " . $_ . "\n" } @methods;
-}
+      method _list_commands {
+          my @methods =
+            $self->application->api_object->meta->get_all_net_api_methods();
 
-sub _get_help_for_command {
-    my ($self, $cmd_name) = @_;
+          if (!@methods) {
+              print "no method available\n";
+              return;
+          }
 
-    my $method =
-      $self->application->api_object->meta->find_net_api_method_by_name(
-        $cmd_name);
+          print "available commands:\n";
+          map { print "- " . $_ . "\n" } @methods;
+      }
 
-    if (!$method) {
-        print "unknown method " . $cmd_name . "\n";
-        return;
-    }
+      method _get_help_for_command($cmd_name) {
+          my $method =
+            $self->application->api_object->meta->find_net_api_method_by_name($cmd_name);
+
+          if (!$method) {
+              print "unknown method " . $cmd_name . "\n";
+              return;
+          }
 
-    print $method->documentation;
+          print $method->documentation;
+      }
 }
 
 1;