diff options
author | franck cuny <franck@lumberjaph.net> | 2010-06-08 15:22:36 +0200 |
---|---|---|
committer | franck cuny <franck@lumberjaph.net> | 2010-06-08 15:22:36 +0200 |
commit | 78fcbf54a4305e1ee6c3a105f91af40c7ea0a62a (patch) | |
tree | c4eb6cec29a92076c2f6fc47ca318cbe59f5e0ba /lib/Net/HTTP/Console/Dispatcher/Help.pm | |
parent | update regex; modify http methods; .. (diff) | |
download | net-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.pm | 83 |
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; |