Body/UrlEncoded.pm

filter: Statementstmt 100% 32 / 32 Branchbran 87.5% 7 / 8 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 100% 4 / 4 Podpod 100% 1 / 1 totaltotal 94.0% 47 / 50 CC 7 SCAR 16.5
CC
7
Cov
95%
spin
7.0
BEGIN
1.0
BEGIN
1.0
CRAP 5.2
« Body/MultiPart.pm ↑ Summary Body/OctetStream.pm »
1 package HTTP::Body::UrlEncoded;
2 24 $HTTP::Body::UrlEncoded::VERSION = '1.24_01'; # TRIAL
3 24 $HTTP::Body::UrlEncoded::VERSION = '1.2401';
4 24 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 24 ▶use base 'HTTP::Body';
Subroutine BEGIN: called CC=1 SCAR=0.0
6 24 ▶use bytes;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 24 our $DECODE = qr/%([0-9a-fA-F]{2})/;
9  
10 24 our $max_params = 1000;
11  
12 24 our %hex_chr;
13  
14 24 for my $num ( 0 .. 255 ) {
15 6144 my $h = sprintf "%02X", $num;
16 6144 $hex_chr{ lc $h } = $hex_chr{ uc $h } = chr $num;
17 }
18  
19 =head1 NAME
20  
21 HTTP::Body::UrlEncoded - HTTP Body UrlEncoded Parser
22  
23 =head1 SYNOPSIS
24  
25 use HTTP::Body::UrlEncoded;
26  
27 =head1 DESCRIPTION
28  
29 HTTP Body UrlEncoded Parser.
30  
31 =head1 METHODS
32  
33 =over 4
34  
35 =item spin
36  
37 =cut
38  
39 46 ▶sub spin {
Subroutine spin: called CC=7 SCAR=19.5
Pod documented
40 46 my $self = shift;
41  
42 46 ▶ return unless $self->length == $self->content_length;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->length == $self->content_length 30 16 46
43
44 # I tested parsing this using APR::Request, but perl is faster
45 # Pure-Perl 2560/s
46 # APR::Request 2305/s
47
48 # Note: s/// appears faster than tr///
49 16 $self->{buffer} =~ s/\+/ /g;
50  
51 16 ▶ if ( $max_params && ( $self->{buffer} =~ tr/&;// ) >= $max_params ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($HTTP::Body::UrlEncoded::max_params and $self->{"buffer"} =~ tr/&;// >= $HTTP::Body::UrlEncoded::max_params) 1 15 16
Condition66%2/3
$HTTP::Body::UrlEncoded::max_params and $self->{"buffer"} =~ tr/&;// >= $HTTP::Body::UrlEncoded::max_params
!ll&&!rl&&r
0151
MC/DC50%1/2
$HTTP::Body::UrlEncoded::max_params and $self->{"buffer"} =~ tr/&;// >= $HTTP::Body::UrlEncoded::max_params
$HTTP::Body::UrlEncoded::max_params $self->{"buffer"} =~ tr/&;// >= $HTTP::Body::UrlEncoded::max_params
Truth table66%2/3
A and B
A= $HTTP::Body::UrlEncoded::max_paramsB= $self->{"buffer"} =~ tr/&;// >= $HTTP::Body::UrlEncoded::max_params
ABresult
0X0
100
111
52 1 Carp::croak("Too many parameters in request body (limit $max_params)");
53 }
54  
55 15 for my $pair ( split( /[&;](?:\s+)?/, $self->{buffer} ) ) {
56  
57 1034 my ( $name, $value ) = split( /=/, $pair , 2 );
58  
59 1034 ▶ next unless defined $name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name 0 1034 1034
60 1034 ▶ next unless defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 1 1033 1034
61
62 1033 $name =~ s/$DECODE/$hex_chr{ uc $1 }/gs;
63 1033 $value =~ s/$DECODE/$hex_chr{ uc $1 }/gs;
64  
65 1033 $self->param( $name, $value );
66 }
67  
68 15 $self->{buffer} = '';
69 15 $self->{state} = 'done';
70 }
71  
72 =back
73  
74 =head1 SUPPORT
75  
76 See L<HTTP::Body>
77  
78 =head1 AUTHORS
79  
80 Christian Hansen, C<ch@ngmedia.com>
81  
82 Andy Grundman, C<andy@hybridized.org>
83  
84 =head1 LICENSE
85  
86 This library is free software . You can redistribute it and/or modify
87 it under the same terms as perl itself.
88  
89 =cut
90  
91 24 1;
« Body/MultiPart.pm ↑ Summary Body/OctetStream.pm »