blob: 3868d730a747eaecfde499fe7e5dd5c6038c7a77 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
package Net::HTTP::Console::Dispatcher::Help;
use MooseX::Declare;
class Net::HTTP::Console::Dispatcher::Help with Net::HTTP::Console::Dispatcher {
method pattern($input) {
$input =~ /^help/ ? return $input : return 0;
}
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);
}
elsif ($cmd eq 'command') {
$self->_list_commands();
}elsif($cmd eq 'view') {
$self->_help_about_view();
}elsif($cmd eq 'set') {
$self->_help_about_set();
}elsif($cmd eq 'request') {
$self->_help_about_request();
}elsif($cmd eq 'load') {
$self->_help_about_load();
}
}
else {
$self->_display_help();
}
1;
}
method _display_help {
print <<EOF
help command - help about a command
help request - help on how to write request
help set - help on how to set values
help view - help on how to view values
help load - help on how to load a lib
EOF
}
method _help_about_view {
print <<EOF
view headers - show the headers of the last request
view content - show the last content
view defined_headers - show the defined headers
EOF
}
method _help_about_set {
print <<EOF
set header key value - set the value for a header (global)
EOF
}
method _help_about_request {
print <<EOF
HTTP Method path - make a HTTP request on a path
EOF
}
method _help_about_load {
print <<EOF
load libname - load a MooseX::Net::API library
EOF
}
method _list_commands {
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 _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;
}
}
1;
|