Builder/UrlEncoded.pm

filter: Statementstmt 92.8% 39 / 42 Branchbran 75.0% 6 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 90.9% 10 / 11 Podpod 60.0% 3 / 5 totaltotal 87.8% 58 / 66 CC 7 SCAR 10.9
CC
7
Cov
90%
new
6.0
as_string
2.0
content_type
2.0
CRAP 3.0
« Builder/MultiPart.pm ↑ Summary Builder.pm »
1 package HTTP::Body::Builder::UrlEncoded;
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use 5.008_005;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use URI;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 4 ▶sub new {
Subroutine new: called CC=6 SCAR=18.0
Pod documented
11 4 my $class = shift;
12 0 ▶ my %args = @_==1 ? %{$_[0]} : @_;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 ? : 0 4 4
13 4 my $content = delete $args{content};
14 4 my $self = bless {
15 %args
16 }, $class;
17 4 ▶ if ($content) {
Branch: 1 branch
BranchTrueFalseTotal
if ($content) 1 3 4
18 1 for my $key (keys %{$content}) {
19 3 ▶ for my $value (ref $content->{$key} ? @{$content->{$key}} : $content->{$key}) {
Branch: 1 branch
BranchTrueFalseTotal
ref $content->{$key} ? : 1 2 3
20 4 $self->add_content($key => $value);
21 }
22 }
23 }
24 4 return $self;
25 }
26  
27 8 ▶sub add_content {
Subroutine add_content: called CC=1 SCAR=0.0
Pod documented
28 8 my ($self, $name, $value) = @_;
29 8 push @{$self->{content}}, $name, $value;
30 }
31  
32 0 ▶sub content_type {
Subroutine content_type: not called CC=1 SCAR=6.9
Pod undocumented
33 0 my $self = shift;
34 0 return 'application/x-www-form-urlencoded';
35 }
36  
37 1 ▶sub add_file {
Subroutine add_file: called CC=1 SCAR=0.0
Pod undocumented
38 1 Carp::croak "You cannot add file with application/x-www-form-urlencoded.";
39 }
40  
41 7 ▶sub as_string {
Subroutine as_string: called CC=2 SCAR=7.0
Pod documented
42 7 my ($self) = @_;
43  
44 7 my $uri = URI->new('http:');
45 7 $uri->query_form($self->{content});
46 7 my $content = $uri->query;
47  
48 # HTML/4.01 says that line breaks are represented as "CR LF" pairs (i.e., `%0D%0A')
49 7 ▶ $content =~ s/(?<!%0D)%0A/%0D%0A/g if defined($content);
Branch: 1 branch
BranchTrueFalseTotal
if defined $content 7 0 7
50 7 $content;
51 }
52  
53 1 1;
54 __END__
« Builder/MultiPart.pm ↑ Summary Builder.pm »