Aion-Surf
view release on metacpan or search on metacpan
# mock
*LWP::UserAgent::request = sub {
my ($ua, $request) = @_;
my $response = HTTP::Response->new(200, "OK");
given ($request->method . " " . $request->uri) {
$response->content("get") when $_ eq "GET http://example/ex";
$response->content("head") when $_ eq "HEAD http://example/ex";
$response->content("post") when $_ eq "POST http://example/ex";
$response->content("put") when $_ eq "PUT http://example/ex";
$response->content("patch") when $_ eq "PATCH http://example/ex";
$response->content("delete") when $_ eq "DELETE http://example/ex";
$response->content('{"a":10}') when $_ eq "PATCH http://example/json";
default {
$response = HTTP::Response->new(404, "Not Found");
$response->content("nf");
}
}
get "http://example/ex" # => get
surf "http://example/ex" # => get
head "http://example/ex" # -> 1
head "http://example/not-found" # -> ""
surf HEAD => "http://example/ex" # -> 1
surf HEAD => "http://example/not-found" # -> ""
[map { surf $_ => "http://example/ex" } qw/GET HEAD POST PUT PATCH DELETE/] # --> [qw/get 1 post put patch delete/]
patch "http://example/json" # --> {a => 10}
[map patch, qw! http://example/ex http://example/json !] # --> ["patch", {a => 10}]
get ["http://example/ex", headers => {Accept => "*/*"}] # => get
surf "http://example/ex", headers => [Accept => "*/*"] # => get
```
# DESCRIPTION
lib/Aion/Surf.md view on Meta::CPAN
# mock
*LWP::UserAgent::request = sub {
my ($ua, $request) = @_;
my $response = HTTP::Response->new(200, "OK");
given ($request->method . " " . $request->uri) {
$response->content("get") when $_ eq "GET http://example/ex";
$response->content("head") when $_ eq "HEAD http://example/ex";
$response->content("post") when $_ eq "POST http://example/ex";
$response->content("put") when $_ eq "PUT http://example/ex";
$response->content("patch") when $_ eq "PATCH http://example/ex";
$response->content("delete") when $_ eq "DELETE http://example/ex";
$response->content('{"a":10}') when $_ eq "PATCH http://example/json";
default {
$response = HTTP::Response->new(404, "Not Found");
$response->content("nf");
}
}
lib/Aion/Surf.md view on Meta::CPAN
get "http://example/ex" # => get
surf "http://example/ex" # => get
head "http://example/ex" # -> 1
head "http://example/not-found" # -> ""
surf HEAD => "http://example/ex" # -> 1
surf HEAD => "http://example/not-found" # -> ""
[map { surf $_ => "http://example/ex" } qw/GET HEAD POST PUT PATCH DELETE/] # --> [qw/get 1 post put patch delete/]
patch "http://example/json" # --> {a => 10}
[map patch, qw! http://example/ex http://example/json !] # --> ["patch", {a => 10}]
get ["http://example/ex", headers => {Accept => "*/*"}] # => get
surf "http://example/ex", headers => [Accept => "*/*"] # => get
```
# DESCRIPTION
lib/Aion/Surf.pm view on Meta::CPAN
my $content = $response->decoded_content;
eval { $content = Aion::Format::Json::from_json($content) } if $content =~ m!^\{!;
$content
}
sub head (;$) { my $x = @_ == 0? $_: shift; surf HEAD => ref $x? @{$x}: $x }
sub get (;$) { my $x = @_ == 0? $_: shift; surf GET => ref $x? @{$x}: $x }
sub post (@) { my $x = @_ == 0? $_: \@_; surf POST => ref $x? @{$x}: $x }
sub put (@) { my $x = @_ == 0? $_: \@_; surf PUT => ref $x? @{$x}: $x }
sub patch(@) { my $x = @_ == 0? $_: \@_; surf PATCH => ref $x? @{$x}: $x }
sub del (;$) { my $x = @_ == 0? $_: shift; surf DELETE => ref $x? @{$x}: $x }
use config TELEGRAM_BOT_TOKEN => undef;
# ÐÑпÑавлÑÐµÑ ÑообÑение ÑелегÑам
sub chat_message($$) {
my ($chat_id, $message) = @_;
lib/Aion/Surf.pm view on Meta::CPAN
# mock
*LWP::UserAgent::request = sub {
my ($ua, $request) = @_;
my $response = HTTP::Response->new(200, "OK");
given ($request->method . " " . $request->uri) {
$response->content("get") when $_ eq "GET http://example/ex";
$response->content("head") when $_ eq "HEAD http://example/ex";
$response->content("post") when $_ eq "POST http://example/ex";
$response->content("put") when $_ eq "PUT http://example/ex";
$response->content("patch") when $_ eq "PATCH http://example/ex";
$response->content("delete") when $_ eq "DELETE http://example/ex";
$response->content('{"a":10}') when $_ eq "PATCH http://example/json";
default {
$response = HTTP::Response->new(404, "Not Found");
$response->content("nf");
}
}
lib/Aion/Surf.pm view on Meta::CPAN
get "http://example/ex" # => get
surf "http://example/ex" # => get
head "http://example/ex" # -> 1
head "http://example/not-found" # -> ""
surf HEAD => "http://example/ex" # -> 1
surf HEAD => "http://example/not-found" # -> ""
[map { surf $_ => "http://example/ex" } qw/GET HEAD POST PUT PATCH DELETE/] # --> [qw/get 1 post put patch delete/]
patch "http://example/json" # --> {a => 10}
[map patch, qw! http://example/ex http://example/json !] # --> ["patch", {a => 10}]
get ["http://example/ex", headers => {Accept => "*/*"}] # => get
surf "http://example/ex", headers => [Accept => "*/*"] # => get
=head1 DESCRIPTION
t/aion/surf.t view on Meta::CPAN
# mock
*LWP::UserAgent::request = sub {
my ($ua, $request) = @_;
my $response = HTTP::Response->new(200, "OK");
given ($request->method . " " . $request->uri) {
$response->content("get") when $_ eq "GET http://example/ex";
$response->content("head") when $_ eq "HEAD http://example/ex";
$response->content("post") when $_ eq "POST http://example/ex";
$response->content("put") when $_ eq "PUT http://example/ex";
$response->content("patch") when $_ eq "PATCH http://example/ex";
$response->content("delete") when $_ eq "DELETE http://example/ex";
$response->content('{"a":10}') when $_ eq "PATCH http://example/json";
default {
$response = HTTP::Response->new(404, "Not Found");
$response->content("nf");
}
}
t/aion/surf.t view on Meta::CPAN
::is scalar do {get "http://example/ex"}, "get", 'get "http://example/ex" # => get';
::is scalar do {surf "http://example/ex"}, "get", 'surf "http://example/ex" # => get';
::is scalar do {head "http://example/ex"}, scalar do{1}, 'head "http://example/ex" # -> 1';
::is scalar do {head "http://example/not-found"}, scalar do{""}, 'head "http://example/not-found" # -> ""';
::is scalar do {surf HEAD => "http://example/ex"}, scalar do{1}, 'surf HEAD => "http://example/ex" # -> 1';
::is scalar do {surf HEAD => "http://example/not-found"}, scalar do{""}, 'surf HEAD => "http://example/not-found" # -> ""';
::is_deeply scalar do {[map { surf $_ => "http://example/ex" } qw/GET HEAD POST PUT PATCH DELETE/]}, scalar do {[qw/get 1 post put patch delete/]}, '[map { surf $_ => "http://example/ex" } qw/GET HEAD POST PUT PATCH DELETE/] # --> [qw/get 1 post put ...
::is_deeply scalar do {patch "http://example/json"}, scalar do {{a => 10}}, 'patch "http://example/json" # --> {a => 10}';
::is_deeply scalar do {[map patch, qw! http://example/ex http://example/json !]}, scalar do {["patch", {a => 10}]}, '[map patch, qw! http://example/ex http://example/json !] # --> ["patch", {a => 10}]';
::is scalar do {get ["http://example/ex", headers => {Accept => "*/*"}]}, "get", 'get ["http://example/ex", headers => {Accept => "*/*"}] # => get';
::is scalar do {surf "http://example/ex", headers => [Accept => "*/*"]}, "get", 'surf "http://example/ex", headers => [Accept => "*/*"] # => get';
#
# # DESCRIPTION
( run in 0.384 second using v1.01-cache-2.11-cpan-4e96b696675 )