Aion-Surf
view release on metacpan or search on metacpan
# SUBROUTINES
## surf (\[$method], $url, \[$data], %params)
Send request by LWP::UserAgent and adapt response.
`@params` maybe:
* `query` - add query params to `$url`.
* `json` - body request set in json format. Add header `Content-Type: application/json; charset=utf-8`.
* `form` - body request set in url params format. Add header `Content-Type: application/x-www-form-urlencoded`.
* `headers` - add headers. If `header` is array ref, then add in the order specified. If `header` is hash ref, then add in the alphabet order.
* `cookies` - add cookies. Same as: `cookies => {go => "xyz", session => ["abcd", path => "/page"]}`.
* `response` - returns response (as HTTP::Response) by this reference.
```perl
my $req = "MAYBE_ANY_METHOD https://ya.ru/page?z=30&x=10&y=%1F9E8
Accept: */*,image/*
Content-Type: application/x-www-form-urlencoded
lib/Aion/Surf.md view on Meta::CPAN
# SUBROUTINES
## surf (\[$method], $url, \[$data], %params)
Send request by LWP::UserAgent and adapt response.
`@params` maybe:
* `query` - add query params to `$url`.
* `json` - body request set in json format. Add header `Content-Type: application/json; charset=utf-8`.
* `form` - body request set in url params format. Add header `Content-Type: application/x-www-form-urlencoded`.
* `headers` - add headers. If `header` is array ref, then add in the order specified. If `header` is hash ref, then add in the alphabet order.
* `cookies` - add cookies. Same as: `cookies => {go => "xyz", session => ["abcd", path => "/page"]}`.
* `response` - returns response (as HTTP::Response) by this reference.
```perl
my $req = "MAYBE_ANY_METHOD https://ya.ru/page?z=30&x=10&y=%1F9E8
Accept: */*,image/*
Content-Type: application/x-www-form-urlencoded
lib/Aion/Surf.pm view on Meta::CPAN
die "surf: data has already been provided!" if defined $data;
die "surf: sended data in $method!" if $method =~ /^(HEAD|GET)\z/;
};
# УÑÑанавливаем даннÑе
my $json = delete $set{json};
$json = $data, undef $data if not defined $json and ref $data eq "HASH";
if(defined $json) {
$validate_data->();
$request->header('Content-Type' => 'application/json; charset=utf-8');
$data = Aion::Format::Json::to_json $json;
utf8::encode($data) if utf8::is_utf8($data);
$request->content($data);
}
my $form = delete $set{form};
$form = $data, undef $data if not defined $form and ref $data eq "ARRAY";
if(defined $form) {
$validate_data->();
$data = 1;
lib/Aion/Surf.pm view on Meta::CPAN
=head2 surf ([$method], $url, [$data], %params)
Send request by LWP::UserAgent and adapt response.
C<@params> maybe:
=over
=item * C<query> - add query params to C<$url>.
=item * C<json> - body request set in json format. Add header C<Content-Type: application/json; charset=utf-8>.
=item * C<form> - body request set in url params format. Add header C<Content-Type: application/x-www-form-urlencoded>.
=item * C<headers> - add headers. If C<header> is array ref, then add in the order specified. If C<header> is hash ref, then add in the alphabet order.
=item * C<cookies> - add cookies. Same as: C<< cookies =E<gt> {go =E<gt> "xyz", session =E<gt> ["abcd", path =E<gt> "/page"]} >>.
=item * C<response> - returns response (as HTTP::Response) by this reference.
=back
t/aion/surf.t view on Meta::CPAN
#
# # SUBROUTINES
#
# ## surf (\[$method], $url, \[$data], %params)
#
# Send request by LWP::UserAgent and adapt response.
#
# `@params` maybe:
#
# * `query` - add query params to `$url`.
# * `json` - body request set in json format. Add header `Content-Type: application/json; charset=utf-8`.
# * `form` - body request set in url params format. Add header `Content-Type: application/x-www-form-urlencoded`.
# * `headers` - add headers. If `header` is array ref, then add in the order specified. If `header` is hash ref, then add in the alphabet order.
# * `cookies` - add cookies. Same as: `cookies => {go => "xyz", session => ["abcd", path => "/page"]}`.
# * `response` - returns response (as HTTP::Response) by this reference.
#
done_testing; }; subtest 'surf (\[$method], $url, \[$data], %params)' => sub {
my $req = "MAYBE_ANY_METHOD https://ya.ru/page?z=30&x=10&y=%1F9E8
Accept: */*,image/*
Content-Type: application/x-www-form-urlencoded
( run in 0.284 second using v1.01-cache-2.11-cpan-4d50c553e7e )