| 1 | package PONAPI::Client::UA::YAHC; | ||
| 2 | # ABSTRACT: A wrapper for a YAHC UA | ||
| 3 | |||
| 4 | ################################################################################ | ||
| 5 | ################################################################################ | ||
| 6 | |||
| 7 | use strict; | ||
| 8 | use warnings; | ||
| 9 | |||
| 10 | use Moose; | ||
| 11 | use YAHC; | ||
| 12 | |||
| 13 | with 'PONAPI::Client::Role::UA'; | ||
| 14 | |||
| 15 | ################################################################################ | ||
| 16 | ################################################################################ | ||
| 17 | |||
| 18 | has yahc => ( | ||
| 19 | is => 'ro', | ||
| 20 | isa => 'YAHC', | ||
| 21 | lazy => 1, | ||
| 22 | builder => '_build_yahc', | ||
| 23 | ); | ||
| 24 | |||
| 25 | has yahc_storage => ( | ||
| 26 | is => 'ro', | ||
| 27 | isa => 'Ref', | ||
| 28 | ); | ||
| 29 | |||
| 30 | has scheme => ( | ||
| 31 | is => 'ro', | ||
| 32 | isa => 'Str', | ||
| 33 | default => 'http', | ||
| 34 | ); | ||
| 35 | |||
| 36 | has ssl_options => ( | ||
| 37 | is => 'ro', | ||
| 38 | isa => 'HashRef', | ||
| 39 | deafult => sub { +{} }, | ||
| 40 | ); | ||
| 41 | |||
| 42 | ################################################################################ | ||
| 43 | ################################################################################ | ||
| 44 | |||
| 45 | sub _build_yahc { | ||
| 46 | my ($self) = @_; | ||
| 47 | my ($yahc, $yahc_storage) = YAHC->new(); | ||
| 48 | |||
| 49 | $self->yahc_storage($yahc_storage); | ||
| 50 | return $yahc; | ||
| 51 | } | ||
| 52 | |||
| 53 | ################################################################################ | ||
| 54 | ################################################################################ | ||
| 55 | |||
| 56 | sub send_http_request { | ||
| 57 | my ($self, $request) = @_; | ||
| 58 | |||
| 59 | my $ponapi_response; | ||
| 60 | |||
| 61 | my $callback = sub { | ||
| 62 | my ($conn) = @_; | ||
| 63 | my $response = $conn->{response}; | ||
| 64 | $ponapi_response = { | ||
| 65 | status => $response->{status}, | ||
| 66 | head => $response->{head}, | ||
| 67 | body => $response->{body}, | ||
| 68 | }; | ||
| 69 | }; | ||
| 70 | |||
| 71 | local $request->{callback} = $callback; | ||
| 72 | local $request->{scheme} = $self->scheme; | ||
| 73 | local $request->{ssl_options} = $self->ssl_options; | ||
| 74 | |||
| 75 | my $yahc = $self->yahc; | ||
| 76 | |||
| 77 | $yahc->request($request); | ||
| 78 | $yahc->run(); | ||
| 79 | |||
| 80 | return $ponapi_response; | ||
| 81 | } | ||
| 82 | |||
| 83 | ################################################################################ | ||
| 84 | ################################################################################ | ||
| 85 | |||
| 86 | sub before_request { } | ||
| 87 | |||
| 88 | ################################################################################ | ||
| 89 | ################################################################################ | ||
| 90 | |||
| 91 | sub after_request { } | ||
| 92 | |||
| 93 | ################################################################################ | ||
| 94 | ################################################################################ | ||
| 95 | |||
| 96 | no Moose; | ||
| 97 | __PACKAGE__->meta->make_immutable(); | ||
| 98 | |||
| 99 | 1; | ||
| 100 | |||
| 101 | ################################################################################ | ||
| 102 | ################################################################################ | ||
| 103 | |||
| 104 | __END__ | ||
| 105 | |||
| 106 | =pod | ||
| 107 | |||
| 108 | =encoding UTF-8 | ||
| 109 | |||
| 110 | =head1 NAME | ||
| 111 | |||
| 112 | PONAPI::Client::UA::YAHC - A wrapper for a YAHC UA | ||
| 113 | |||
| 114 | =head1 VERSION | ||
| 115 | |||
| 116 | version 0.002011 | ||
| 117 | |||
| 118 | =head1 AUTHORS | ||
| 119 | |||
| 120 | =over 4 | ||
| 121 | |||
| 122 | =item * | ||
| 123 | |||
| 124 | Mickey Nasriachi <mickey@cpan.org> | ||
| 125 | |||
| 126 | =item * | ||
| 127 | |||
| 128 | Stevan Little <stevan@cpan.org> | ||
| 129 | |||
| 130 | =item * | ||
| 131 | |||
| 132 | Brian Fraser <hugmeir@cpan.org> | ||
| 133 | |||
| 134 | =back | ||
| 135 | |||
| 136 | =head1 COPYRIGHT AND LICENSE | ||
| 137 | |||
| 138 | This software is copyright (c) 2019 by Mickey Nasriachi, Stevan Little, Brian Fraser. | ||
| 139 | |||
| 140 | This is free software; you can redistribute it and/or modify it under | ||
| 141 | the same terms as the Perl 5 programming language system itself. | ||
| 142 | |||
| 143 | =cut |