| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package WWW::OAuth::Request::Basic; | 
| 2 |  |  |  |  |  |  |  | 
| 3 | 3 |  |  | 3 |  | 18911 | use strict; | 
|  | 3 |  |  |  |  | 5 |  | 
|  | 3 |  |  |  |  | 86 |  | 
| 4 | 3 |  |  | 3 |  | 12 | use warnings; | 
|  | 3 |  |  |  |  | 4 |  | 
|  | 3 |  |  |  |  | 135 |  | 
| 5 | 3 |  |  | 3 |  | 993 | use Class::Tiny::Chained 'method', 'url', 'content', { headers => sub { {} } }; | 
|  | 3 |  |  |  |  | 7069 |  | 
|  | 3 |  |  |  |  | 51 |  | 
|  | 3 |  |  |  |  | 321 |  | 
| 6 |  |  |  |  |  |  |  | 
| 7 | 3 |  |  | 3 |  | 1693 | use Carp 'croak'; | 
|  | 3 |  |  |  |  | 5 |  | 
|  | 3 |  |  |  |  | 211 |  | 
| 8 | 3 |  |  | 3 |  | 14 | use List::Util 'first'; | 
|  | 3 |  |  |  |  | 4 |  | 
|  | 3 |  |  |  |  | 236 |  | 
| 9 | 3 |  |  | 3 |  | 13 | use Scalar::Util 'blessed'; | 
|  | 3 |  |  |  |  | 4 |  | 
|  | 3 |  |  |  |  | 122 |  | 
| 10 | 3 |  |  | 3 |  | 398 | use WWW::OAuth::Util 'form_urlencode'; | 
|  | 3 |  |  |  |  | 4 |  | 
|  | 3 |  |  |  |  | 131 |  | 
| 11 |  |  |  |  |  |  |  | 
| 12 | 3 |  |  | 3 |  | 1372 | use Role::Tiny::With; | 
|  | 3 |  |  |  |  | 664 |  | 
|  | 3 |  |  |  |  | 1365 |  | 
| 13 |  |  |  |  |  |  | with 'WWW::OAuth::Request'; | 
| 14 |  |  |  |  |  |  |  | 
| 15 |  |  |  |  |  |  | our $VERSION = '0.005'; | 
| 16 |  |  |  |  |  |  |  | 
| 17 |  |  |  |  |  |  | sub content_is_form { | 
| 18 | 6 |  |  | 6 | 1 | 623 | my $self = shift; | 
| 19 | 6 |  |  |  |  | 20 | my $content_type = $self->header('Content-Type'); | 
| 20 | 6 | 100 | 100 |  |  | 74 | return 0 unless defined $content_type and $content_type =~ m!application/x-www-form-urlencoded!i; | 
| 21 | 2 |  |  |  |  | 14 | return 1; | 
| 22 |  |  |  |  |  |  | } | 
| 23 |  |  |  |  |  |  |  | 
| 24 |  |  |  |  |  |  | sub header { | 
| 25 | 24 |  |  | 24 | 1 | 533 | my $self = shift; | 
| 26 | 24 |  |  |  |  | 36 | my $name = shift; | 
| 27 | 24 | 50 |  |  |  | 81 | croak 'No header to set/retrieve' unless defined $name; | 
| 28 | 24 |  |  |  |  | 832 | my $headers = $self->headers; | 
| 29 | 24 | 100 |  |  |  | 204 | unless (@_) { | 
| 30 |  |  |  |  |  |  | # workaround for TEMP bug in first/lc | 
| 31 | 15 |  |  |  |  | 56 | my @names = keys %$headers; | 
| 32 | 15 |  |  | 16 |  | 131 | my $key = first { lc $_ eq lc $name } @names; | 
|  | 16 |  |  |  |  | 53 |  | 
| 33 | 15 | 100 |  |  |  | 107 | return undef unless defined $key; | 
| 34 | 10 | 100 |  |  |  | 48 | my @values = ref $headers->{$key} eq 'ARRAY' ? @{$headers->{$key}} : $headers->{$key}; | 
|  | 1 |  |  |  |  | 5 |  | 
| 35 | 10 |  |  |  |  | 26 | return join ', ', grep { defined } @values; | 
|  | 12 |  |  |  |  | 112 |  | 
| 36 |  |  |  |  |  |  | } | 
| 37 | 9 |  |  |  |  | 18 | my $value = shift; | 
| 38 | 9 |  |  |  |  | 37 | my @existing = grep { lc $_ eq lc $name } keys %$headers; | 
|  | 14 |  |  |  |  | 50 |  | 
| 39 | 9 | 100 |  |  |  | 43 | delete @$headers{@existing} if @existing; | 
| 40 | 9 |  |  |  |  | 24 | $headers->{$name} = $value; | 
| 41 | 9 |  |  |  |  | 27 | return $self; | 
| 42 |  |  |  |  |  |  | } | 
| 43 |  |  |  |  |  |  |  | 
| 44 |  |  |  |  |  |  | sub set_form { | 
| 45 | 1 |  |  | 1 | 1 | 4 | my ($self, $form) = @_; | 
| 46 | 1 |  |  |  |  | 5 | $self->header('Content-Type' => 'application/x-www-form-urlencoded'); | 
| 47 | 1 |  |  |  |  | 8 | $self->content(form_urlencode $form); | 
| 48 | 1 |  |  |  |  | 8 | return $self; | 
| 49 |  |  |  |  |  |  | } | 
| 50 |  |  |  |  |  |  |  | 
| 51 |  |  |  |  |  |  | sub request_with { | 
| 52 | 0 |  |  | 0 | 1 |  | my ($self, $ua) = @_; | 
| 53 | 0 | 0 | 0 |  |  |  | croak 'Unknown user-agent object' unless blessed $ua and $ua->isa('HTTP::Tiny'); | 
| 54 | 0 |  |  |  |  |  | return $ua->request($self->method, $self->url, { headers => $self->headers, content => $self->content }); | 
| 55 |  |  |  |  |  |  | } | 
| 56 |  |  |  |  |  |  |  | 
| 57 |  |  |  |  |  |  | 1; | 
| 58 |  |  |  |  |  |  |  | 
| 59 |  |  |  |  |  |  | =head1 NAME | 
| 60 |  |  |  |  |  |  |  | 
| 61 |  |  |  |  |  |  | WWW::OAuth::Request::Basic - HTTP Request container for HTTP::Tiny | 
| 62 |  |  |  |  |  |  |  | 
| 63 |  |  |  |  |  |  | =head1 SYNOPSIS | 
| 64 |  |  |  |  |  |  |  | 
| 65 |  |  |  |  |  |  | my $req = WWW::OAuth::Request::Basic->new(method => 'POST', url => $url, content => $content); | 
| 66 |  |  |  |  |  |  | $req->request_with(HTTP::Tiny->new); | 
| 67 |  |  |  |  |  |  |  | 
| 68 |  |  |  |  |  |  | =head1 DESCRIPTION | 
| 69 |  |  |  |  |  |  |  | 
| 70 |  |  |  |  |  |  | L is a request container for L that | 
| 71 |  |  |  |  |  |  | stores the request parameters directly, for use with user-agents that do not | 
| 72 |  |  |  |  |  |  | use request objects like L. It performs the role | 
| 73 |  |  |  |  |  |  | L. | 
| 74 |  |  |  |  |  |  |  | 
| 75 |  |  |  |  |  |  | =head1 ATTRIBUTES | 
| 76 |  |  |  |  |  |  |  | 
| 77 |  |  |  |  |  |  | L implements the following attributes. | 
| 78 |  |  |  |  |  |  |  | 
| 79 |  |  |  |  |  |  | =head2 content | 
| 80 |  |  |  |  |  |  |  | 
| 81 |  |  |  |  |  |  | my $content = $req->content; | 
| 82 |  |  |  |  |  |  | $req        = $req->content('foo=1&bar=2'); | 
| 83 |  |  |  |  |  |  |  | 
| 84 |  |  |  |  |  |  | Request content string. | 
| 85 |  |  |  |  |  |  |  | 
| 86 |  |  |  |  |  |  | =head2 headers | 
| 87 |  |  |  |  |  |  |  | 
| 88 |  |  |  |  |  |  | my $headers = $req->headers; | 
| 89 |  |  |  |  |  |  | $req        = $req->headers({}); | 
| 90 |  |  |  |  |  |  |  | 
| 91 |  |  |  |  |  |  | Hashref of request headers. Must be updated carefully as headers are | 
| 92 |  |  |  |  |  |  | case-insensitive. Values can be array references to specify multi-value | 
| 93 |  |  |  |  |  |  | headers. | 
| 94 |  |  |  |  |  |  |  | 
| 95 |  |  |  |  |  |  | =head2 method | 
| 96 |  |  |  |  |  |  |  | 
| 97 |  |  |  |  |  |  | my $method = $req->method; | 
| 98 |  |  |  |  |  |  | $req       = $req->method('GET'); | 
| 99 |  |  |  |  |  |  |  | 
| 100 |  |  |  |  |  |  | Request method. | 
| 101 |  |  |  |  |  |  |  | 
| 102 |  |  |  |  |  |  | =head2 url | 
| 103 |  |  |  |  |  |  |  | 
| 104 |  |  |  |  |  |  | my $url = $req->url; | 
| 105 |  |  |  |  |  |  | $req    = $req->url('http://example.com/api/'); | 
| 106 |  |  |  |  |  |  |  | 
| 107 |  |  |  |  |  |  | Request URL. | 
| 108 |  |  |  |  |  |  |  | 
| 109 |  |  |  |  |  |  | =head1 METHODS | 
| 110 |  |  |  |  |  |  |  | 
| 111 |  |  |  |  |  |  | L composes all methods from L, | 
| 112 |  |  |  |  |  |  | and implements the following new ones. | 
| 113 |  |  |  |  |  |  |  | 
| 114 |  |  |  |  |  |  | =head2 content_is_form | 
| 115 |  |  |  |  |  |  |  | 
| 116 |  |  |  |  |  |  | my $bool = $req->content_is_form; | 
| 117 |  |  |  |  |  |  |  | 
| 118 |  |  |  |  |  |  | Check whether L"headers"> contains a C header set to | 
| 119 |  |  |  |  |  |  | C. | 
| 120 |  |  |  |  |  |  |  | 
| 121 |  |  |  |  |  |  | =head2 header | 
| 122 |  |  |  |  |  |  |  | 
| 123 |  |  |  |  |  |  | my $header = $req->header('Content-Type'); | 
| 124 |  |  |  |  |  |  | $req       = $req->header(Authorization => 'Basic foobar'); | 
| 125 |  |  |  |  |  |  |  | 
| 126 |  |  |  |  |  |  | Set or return a request header in L"headers">. | 
| 127 |  |  |  |  |  |  |  | 
| 128 |  |  |  |  |  |  | =head2 set_form | 
| 129 |  |  |  |  |  |  |  | 
| 130 |  |  |  |  |  |  | $req = $req->set_form({foo => 'bar'}); | 
| 131 |  |  |  |  |  |  |  | 
| 132 |  |  |  |  |  |  | Convenience method to set L"content"> to a urlencoded form. Equivalent to: | 
| 133 |  |  |  |  |  |  |  | 
| 134 |  |  |  |  |  |  | use WWW::OAuth::Util 'form_urlencode'; | 
| 135 |  |  |  |  |  |  | $req->header('Content-Type' => 'application/x-www-form-urlencoded'); | 
| 136 |  |  |  |  |  |  | $req->content(form_urlencode $form); | 
| 137 |  |  |  |  |  |  |  | 
| 138 |  |  |  |  |  |  | =head2 request_with | 
| 139 |  |  |  |  |  |  |  | 
| 140 |  |  |  |  |  |  | my $res = $req->request_with(HTTP::Tiny->new); | 
| 141 |  |  |  |  |  |  |  | 
| 142 |  |  |  |  |  |  | Run request with passed L user-agent object, and return response | 
| 143 |  |  |  |  |  |  | hashref, as in L. | 
| 144 |  |  |  |  |  |  |  | 
| 145 |  |  |  |  |  |  | =head1 BUGS | 
| 146 |  |  |  |  |  |  |  | 
| 147 |  |  |  |  |  |  | Report any issues on the public bugtracker. | 
| 148 |  |  |  |  |  |  |  | 
| 149 |  |  |  |  |  |  | =head1 AUTHOR | 
| 150 |  |  |  |  |  |  |  | 
| 151 |  |  |  |  |  |  | Dan Book | 
| 152 |  |  |  |  |  |  |  | 
| 153 |  |  |  |  |  |  | =head1 COPYRIGHT AND LICENSE | 
| 154 |  |  |  |  |  |  |  | 
| 155 |  |  |  |  |  |  | This software is Copyright (c) 2015 by Dan Book. | 
| 156 |  |  |  |  |  |  |  | 
| 157 |  |  |  |  |  |  | This is free software, licensed under: | 
| 158 |  |  |  |  |  |  |  | 
| 159 |  |  |  |  |  |  | The Artistic License 2.0 (GPL Compatible) | 
| 160 |  |  |  |  |  |  |  | 
| 161 |  |  |  |  |  |  | =head1 SEE ALSO | 
| 162 |  |  |  |  |  |  |  | 
| 163 |  |  |  |  |  |  | L |