| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | use strict; | 
| 2 | 18 |  |  | 18 |  | 4403 | use warnings; | 
|  | 18 |  |  |  |  | 64 |  | 
|  | 18 |  |  |  |  | 563 |  | 
| 3 | 18 |  |  | 18 |  | 94 | use parent qw/Plack::Request/; | 
|  | 18 |  |  |  |  | 35 |  | 
|  | 18 |  |  |  |  | 506 |  | 
| 4 | 18 |  |  | 18 |  | 1689 | use Encode (); | 
|  | 18 |  |  |  |  | 1311 |  | 
|  | 18 |  |  |  |  | 100 |  | 
| 5 | 18 |  |  | 18 |  | 1104527 | use Carp (); | 
|  | 18 |  |  |  |  | 52 |  | 
|  | 18 |  |  |  |  | 294 |  | 
| 6 | 18 |  |  | 18 |  | 94 | use URI::QueryParam; | 
|  | 18 |  |  |  |  | 38 |  | 
|  | 18 |  |  |  |  | 335 |  | 
| 7 | 18 |  |  | 18 |  | 7996 | use Hash::MultiValue; | 
|  | 18 |  |  |  |  | 14466 |  | 
|  | 18 |  |  |  |  | 606 |  | 
| 8 | 18 |  |  | 18 |  | 131 |  | 
|  | 18 |  |  |  |  | 45 |  | 
|  | 18 |  |  |  |  | 16105 |  | 
| 9 |  |  |  |  |  |  | my ($class, $env, $context_class) = @_; | 
| 10 |  |  |  |  |  |  | my $self = $class->SUPER::new($env); | 
| 11 | 50 |  |  | 50 | 1 | 30213 | if (@_==3) { | 
| 12 | 50 |  |  |  |  | 277 | $self->{_web_pkg} = $context_class; | 
| 13 | 50 | 100 |  |  |  | 568 | } | 
| 14 | 22 |  |  |  |  | 71 | return $self; | 
| 15 |  |  |  |  |  |  | } | 
| 16 | 50 |  |  |  |  | 202 |  | 
| 17 |  |  |  |  |  |  | my $self = shift; | 
| 18 |  |  |  |  |  |  | return $self->{_web_pkg} ? $self->{_web_pkg}->context->encoding : Amon2->context->encoding; | 
| 19 |  |  |  |  |  |  | } | 
| 20 | 3 |  |  | 3 |  | 5 |  | 
| 21 | 3 | 50 |  |  |  | 23 | # ------------------------------------------------------------------------- | 
| 22 |  |  |  |  |  |  | # This object returns decoded parameter values by default | 
| 23 |  |  |  |  |  |  |  | 
| 24 |  |  |  |  |  |  | my ($self) = @_; | 
| 25 |  |  |  |  |  |  | $self->{'amon2.body_parameters'} ||= $self->_decode_parameters($self->SUPER::body_parameters()); | 
| 26 |  |  |  |  |  |  | } | 
| 27 |  |  |  |  |  |  |  | 
| 28 | 1 |  |  | 1 | 1 | 4 | my ($self) = @_; | 
| 29 | 1 |  | 33 |  |  | 12 | $self->{'amon2.query_parameters'} ||= $self->_decode_parameters($self->SUPER::query_parameters()); | 
| 30 |  |  |  |  |  |  | } | 
| 31 |  |  |  |  |  |  |  | 
| 32 |  |  |  |  |  |  | my ($self, $stuff) = @_; | 
| 33 | 2 |  |  | 2 | 1 | 623 |  | 
| 34 | 2 |  | 66 |  |  | 18 | my $encoding = $self->_encoding(); | 
| 35 |  |  |  |  |  |  | my @flatten = $stuff->flatten(); | 
| 36 |  |  |  |  |  |  | my @decoded; | 
| 37 |  |  |  |  |  |  | while ( my ($k, $v) = splice @flatten, 0, 2 ) { | 
| 38 | 2 |  |  | 2 |  | 493 | push @decoded, Encode::decode($encoding, $k), Encode::decode($encoding, $v); | 
| 39 |  |  |  |  |  |  | } | 
| 40 | 2 |  |  |  |  | 7 | return Hash::MultiValue->new(@decoded); | 
| 41 | 2 |  |  |  |  | 11 | } | 
| 42 | 2 |  |  |  |  | 30 | my $self = shift; | 
| 43 | 2 |  |  |  |  | 11 |  | 
| 44 | 3 |  |  |  |  | 200 | $self->env->{'amon2.request.merged'} ||= do { | 
| 45 |  |  |  |  |  |  | my $query = $self->query_parameters; | 
| 46 | 2 |  |  |  |  | 66 | my $body  = $self->body_parameters; | 
| 47 |  |  |  |  |  |  | Hash::MultiValue->new( $query->flatten, $body->flatten ); | 
| 48 |  |  |  |  |  |  | }; | 
| 49 | 3 |  |  | 3 | 1 | 1647 | } | 
| 50 |  |  |  |  |  |  |  | 
| 51 | 3 |  | 66 |  |  | 14 | # ------------------------------------------------------------------------- | 
| 52 | 1 |  |  |  |  | 13 | # raw parameter values are also available. | 
| 53 | 1 |  |  |  |  | 50 |  | 
| 54 | 1 |  |  |  |  | 31 | shift->SUPER::body_parameters(); | 
| 55 |  |  |  |  |  |  | } | 
| 56 |  |  |  |  |  |  | shift->SUPER::query_parameters(); | 
| 57 |  |  |  |  |  |  | } | 
| 58 |  |  |  |  |  |  | my $self = shift; | 
| 59 |  |  |  |  |  |  |  | 
| 60 |  |  |  |  |  |  | $self->env->{'plack.request.merged'} ||= do { | 
| 61 |  |  |  |  |  |  | my $query = $self->SUPER::query_parameters(); | 
| 62 | 0 |  |  | 0 | 1 | 0 | my $body  = $self->SUPER::body_parameters(); | 
| 63 |  |  |  |  |  |  | Hash::MultiValue->new( $query->flatten, $body->flatten ); | 
| 64 |  |  |  |  |  |  | }; | 
| 65 | 0 |  |  | 0 | 1 | 0 | } | 
| 66 |  |  |  |  |  |  | my $self = shift; | 
| 67 |  |  |  |  |  |  |  | 
| 68 | 2 |  |  | 2 | 1 | 494 | return keys %{ $self->parameters_raw } if @_ == 0; | 
| 69 |  |  |  |  |  |  |  | 
| 70 | 2 |  | 66 |  |  | 7 | my $key = shift; | 
| 71 | 1 |  |  |  |  | 16 | return $self->parameters_raw->{$key} unless wantarray; | 
| 72 | 1 |  |  |  |  | 9 | return $self->parameters_raw->get_all($key); | 
| 73 | 1 |  |  |  |  | 8 | } | 
| 74 |  |  |  |  |  |  |  | 
| 75 |  |  |  |  |  |  |  | 
| 76 |  |  |  |  |  |  | # ------------------------------------------------------------------------- | 
| 77 | 1 |  |  | 1 | 1 | 3834 | # uri_with funcition.  The code was taken from Catalyst::Request | 
| 78 |  |  |  |  |  |  | my( $self, $args, $behavior) = @_; | 
| 79 | 1 | 50 |  |  |  | 9 |  | 
|  | 0 |  |  |  |  | 0 |  | 
| 80 |  |  |  |  |  |  | Carp::carp( 'No arguments passed to uri_with()' ) unless $args; | 
| 81 | 1 |  |  |  |  | 3 |  | 
| 82 | 1 | 50 |  |  |  | 7 | my $append = 0; | 
| 83 | 0 |  |  |  |  | 0 | if((ref($behavior) eq 'HASH') && defined($behavior->{mode}) && ($behavior->{mode} eq 'append')) { | 
| 84 |  |  |  |  |  |  | $append = 1; | 
| 85 |  |  |  |  |  |  | } | 
| 86 |  |  |  |  |  |  |  | 
| 87 |  |  |  |  |  |  | my $params = do { | 
| 88 |  |  |  |  |  |  | foreach my $value ( values %$args ) { | 
| 89 |  |  |  |  |  |  | next unless defined $value; | 
| 90 | 2 |  |  | 2 | 1 | 55 | for ( ref $value eq 'ARRAY' ? @$value : $value ) { | 
| 91 |  |  |  |  |  |  | $_ = "$_"; | 
| 92 | 2 | 50 |  |  |  | 6 | utf8::encode($_) if utf8::is_utf8($_); | 
| 93 |  |  |  |  |  |  | } | 
| 94 | 2 |  |  |  |  | 4 | } | 
| 95 | 2 | 0 | 33 |  |  | 6 |  | 
|  |  |  | 33 |  |  |  |  | 
| 96 | 0 |  |  |  |  | 0 | my %params = %{ $self->uri->query_form_hash }; | 
| 97 |  |  |  |  |  |  | foreach my $key ( keys %{$args} ) { | 
| 98 |  |  |  |  |  |  | my $val = $args->{$key}; | 
| 99 | 2 |  |  |  |  | 4 | if (utf8::is_utf8($key)) { | 
| 100 | 2 |  |  |  |  | 7 | $key = Encode::encode($self->_encoding(), $key); | 
| 101 | 2 | 50 |  |  |  | 7 | } | 
| 102 | 2 | 50 |  |  |  | 6 | if ( defined($val) ) { | 
| 103 | 2 |  |  |  |  | 5 |  | 
| 104 | 2 | 50 |  |  |  | 19 | if ( $append && exists( $params{$key} ) ) { | 
| 105 |  |  |  |  |  |  |  | 
| 106 |  |  |  |  |  |  | # This little bit of heaven handles appending a new value onto | 
| 107 |  |  |  |  |  |  | # an existing one regardless if the existing value is an array | 
| 108 | 2 |  |  |  |  | 4 | # or not, and regardless if the new value is an array or not | 
|  | 2 |  |  |  |  | 11 |  | 
| 109 | 2 |  |  |  |  | 8450 | $params{$key} = [ | 
|  | 2 |  |  |  |  | 9 |  | 
| 110 | 2 |  |  |  |  | 4 | ref( $params{$key} ) eq 'ARRAY' | 
| 111 | 2 | 100 |  |  |  | 9 | ? @{ $params{$key} } | 
| 112 | 1 |  |  |  |  | 13 | : $params{$key}, | 
| 113 |  |  |  |  |  |  | ref($val) eq 'ARRAY' ? @{$val} : $val | 
| 114 | 2 | 50 |  |  |  | 40 | ]; | 
| 115 |  |  |  |  |  |  |  | 
| 116 | 2 | 50 | 33 |  |  | 7 | } | 
| 117 |  |  |  |  |  |  | else { | 
| 118 |  |  |  |  |  |  | $params{$key} = $val; | 
| 119 |  |  |  |  |  |  | } | 
| 120 |  |  |  |  |  |  | } | 
| 121 |  |  |  |  |  |  | else { | 
| 122 |  |  |  |  |  |  |  | 
| 123 | 0 |  |  |  |  | 0 | # If the param wasn't defined then we delete it. | 
| 124 |  |  |  |  |  |  | delete( $params{$key} ); | 
| 125 | 0 | 0 |  |  |  | 0 | } | 
|  | 0 | 0 |  |  |  | 0 |  | 
| 126 |  |  |  |  |  |  | } | 
| 127 |  |  |  |  |  |  | \%params; | 
| 128 |  |  |  |  |  |  | }; | 
| 129 |  |  |  |  |  |  |  | 
| 130 | 2 |  |  |  |  | 7 | my $uri = $self->uri->clone; | 
| 131 |  |  |  |  |  |  | $uri->query_form($params); | 
| 132 |  |  |  |  |  |  |  | 
| 133 |  |  |  |  |  |  | return $uri; | 
| 134 |  |  |  |  |  |  | } | 
| 135 |  |  |  |  |  |  |  | 
| 136 | 0 |  |  |  |  | 0 | 1; | 
| 137 |  |  |  |  |  |  |  | 
| 138 |  |  |  |  |  |  | =encoding utf-8 | 
| 139 | 2 |  |  |  |  | 6 |  | 
| 140 |  |  |  |  |  |  | =head1 NAME | 
| 141 |  |  |  |  |  |  |  | 
| 142 | 2 |  |  |  |  | 6 | Amon2::Web::Request - Amon2 Request Class | 
| 143 | 2 |  |  |  |  | 511 |  | 
| 144 |  |  |  |  |  |  | =head1 DESCRIPTION | 
| 145 | 2 |  |  |  |  | 296 |  | 
| 146 |  |  |  |  |  |  | This is a child class of L<Plack::Request>. Please see L<Plack::Request> for more details. | 
| 147 |  |  |  |  |  |  |  | 
| 148 |  |  |  |  |  |  | =head1 AUTOMATIC DECODING | 
| 149 |  |  |  |  |  |  |  | 
| 150 |  |  |  |  |  |  | This class decode query/body parameters automatically. | 
| 151 |  |  |  |  |  |  | Return value of C<< $req->param() >>, C<< $req->body_parameters >>, etc. is the decoded value. | 
| 152 |  |  |  |  |  |  |  | 
| 153 |  |  |  |  |  |  | =head1 METHODS | 
| 154 |  |  |  |  |  |  |  | 
| 155 |  |  |  |  |  |  | =over 4 | 
| 156 |  |  |  |  |  |  |  | 
| 157 |  |  |  |  |  |  | =item C<< $req->uri_with($args, $behavior) >> | 
| 158 |  |  |  |  |  |  |  | 
| 159 |  |  |  |  |  |  | Returns a rewritten URI object for the current request. Key/value pairs passed in will override existing parameters. You can remove an existing parameter by passing in an undef value. Unmodified pairs will be preserved. | 
| 160 |  |  |  |  |  |  |  | 
| 161 |  |  |  |  |  |  | You may also pass an optional second parameter that puts uri_with into append mode: | 
| 162 |  |  |  |  |  |  |  | 
| 163 |  |  |  |  |  |  | $req->uri_with( { key => 'value' }, { mode => 'append' } ); | 
| 164 |  |  |  |  |  |  |  | 
| 165 |  |  |  |  |  |  | =item C<< $req->body_parameters_raw() >> | 
| 166 |  |  |  |  |  |  |  | 
| 167 |  |  |  |  |  |  | =item C<< $req->query_parameters_raw() >> | 
| 168 |  |  |  |  |  |  |  | 
| 169 |  |  |  |  |  |  | =item C<< $req->parameters_raw() >> | 
| 170 |  |  |  |  |  |  |  | 
| 171 |  |  |  |  |  |  | =item C<< $req->param_raw() >> | 
| 172 |  |  |  |  |  |  |  | 
| 173 |  |  |  |  |  |  | =item C<< $req->param_raw($key) >> | 
| 174 |  |  |  |  |  |  |  | 
| 175 |  |  |  |  |  |  | =item C<< $req->param_raw($key => $val) >> | 
| 176 |  |  |  |  |  |  |  | 
| 177 |  |  |  |  |  |  | These methods are the accessor to raw values. 'raw' means the value is not decoded. | 
| 178 |  |  |  |  |  |  |  | 
| 179 |  |  |  |  |  |  | =back | 
| 180 |  |  |  |  |  |  |  | 
| 181 |  |  |  |  |  |  | =cut | 
| 182 |  |  |  |  |  |  |  |