| 1 | package UserAgent::Any::Impl::MojoUserAgent; | ||
| 2 | |||
| 3 | use 5.036; | ||
| 4 | |||
| 5 | use Moo; | ||
| 6 | use UserAgent::Any::Impl::Helper ':all'; | ||
| 7 | |||
| 8 | use namespace::clean; | ||
| 9 | |||
| 10 | with 'UserAgent::Any::Impl'; | ||
| 11 | |||
| 12 | our $VERSION = 0.01; | ||
| 13 | |||
| 14 | sub call { | ||
| 15 | my ($self, $method, $url, $params, $content) = &get_call_args; | ||
| 16 | return new_response($self->{ua} | ||
| 17 | ->$method($url, params_to_hash(@{$params}), (defined ${$content} ? ${$content} : ()))->res); | ||
| 18 | } | ||
| 19 | |||
| 20 | sub call_cb { | ||
| 21 | my ($self, $method, $url, $params, $content) = &get_call_args; | ||
| 22 | return sub ($cb) { | ||
| 23 | $self->{ua}->$method( | ||
| 24 | $url, | ||
| 25 | params_to_hash(@{$params}), | ||
| 26 | (defined ${$content} ? ${$content} : ()), | ||
| 27 | sub ($, $tx) { $cb->(new_response($tx->res)) }); | ||
| 28 | return; | ||
| 29 | }; | ||
| 30 | } | ||
| 31 | |||
| 32 | sub call_p { | ||
| 33 | my ($self, $method, $url, $params, $content) = &get_call_args; | ||
| 34 | return $self->{ua}->${\"${method}_p"} | ||
| 35 | ($url, params_to_hash(@{$params}), (defined ${$content} ? ${$content} : ())) | ||
| 36 | ->then(sub ($tx) { new_response($tx->res) }); | ||
| 37 | } | ||
| 38 | |||
| 39 | BEGIN { generate_methods() } | ||
| 40 | |||
| 41 | 1; | ||
| 42 | |||
| 43 | __END__ |