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/Set.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 '')
| -rw-r--r-- | lib/Net/HTTP/Console/Dispatcher/Set.pm | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/lib/Net/HTTP/Console/Dispatcher/Set.pm b/lib/Net/HTTP/Console/Dispatcher/Set.pm new file mode 100644 index 0000000..9f23447 --- /dev/null +++ b/lib/Net/HTTP/Console/Dispatcher/Set.pm @@ -0,0 +1,45 @@ +package Net::HTTP::Console::Dispatcher::Set; + +use MooseX::Declare; + +class Net::HTTP::Console::Dispatcher::Set with Net::HTTP::Console::Dispatcher { + + method dispatch($input) { + (my $command, my $header, my $value) = + $input =~ /^([\w_]+)(?:\s([\w-]+))?(?:\s(.*))?$/; + + if ($command eq 'unset_header') { + $self->_unset_header($header); + } + elsif ($command eq 'set_header') { + $self->_set_header($header, $value); + } + elsif ($command eq 'show_defined_headers') { + $self->_show_defined_headers(); + } + } + + method pattern($input) { + $input =~ /(un)?set_header|show_defined_headers/ + ? return $input + : return 0; + } + + method _set_header($header, $value) { + $self->application->set_header($header, $value); + print "header $header set to $value\n"; + } + + method _unset_header($header) { + $self->application->delete_header($header); + print "header $header unset\n"; + } + + method _show_defined_headers { + foreach ($self->application->all_headers) { + print $_->[0].": ".$_->[1]."\n"; + } + } +} + +1; |
