Furl/Headers.pm

filter: Statementstmt 69.8% 44 / 63 Branchbran 75.0% 15 / 20 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 50.0% 10 / 20 Podpod 93.7% 15 / 16 totaltotal 70.5% 84 / 119 CC 14 SCAR 12.5
CC
14
Cov
71%
header
7.1
new
6.0
flatten
3.0
CRAP 3.5
« Furl/Response.pm ↑ Summary Furl/ZlibStream.pm »
1 package Furl::Headers;
2 14 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 14 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 14 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 14 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 9 ▶sub new {
Subroutine new: called CC=6 SCAR=18.0
Pod documented
8 9 my ($class, $headers) = @_; # $headers is HashRef or ArrayRef
9 9 my $self = {};
10 9 ▶ if (ref $headers eq 'ARRAY') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $headers eq 'ARRAY') { } 1 8 9
elsif (ref $headers eq 'HASH') { } 8 0 8
11 1 my @h = @$headers; # copy
12 1 ▶ while (my ($k, $v) = splice @h, 0, 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = splice(@h, 0, 2)) 2 1 3
13 2 push @{$self->{lc $k}}, $v;
14 }
15 }
16 elsif(ref $headers eq 'HASH') {
17 8 ▶ while (my ($k, $v) = each %$headers) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$headers) 30 8 38
18 30 ▶ push @{$self->{$k}}, ref($v) eq 'ARRAY' ? @$v : $v;
Branch: 1 branch
BranchTrueFalseTotal
ref $v eq 'ARRAY' ? : 16 14 30
19 }
20 }
21 else {
22 0 Carp::confess($class . ': $headers must be an ARRAY or HASH reference');
23 }
24  
25 9 bless $self, $class;
26 }
27  
28 6 ▶sub header {
Subroutine header: called CC=5 SCAR=19.6
Pod documented
29 6 my ($self, $key, $new) = @_;
30 6 ▶ if ($new) { # setter
Branch: 1 branch
BranchTrueFalseTotal
if ($new) { } 0 6 6
31 0 ▶ $new = [$new] unless ref $new;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $new 0 0 0
32 0 $self->{lc $key} = $new;
33 0 return;
34 } else {
35 6 my $val = $self->{lc $key};
36 6 ▶ return unless $val;
Branch: 1 branch
BranchTrueFalseTotal
unless $val 0 6 6
37 6 ▶ return wantarray ? @$val : join(", ", @$val);
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 4 2 6
38 }
39 }
40  
41 0 ▶sub remove_header {
Subroutine remove_header: not called CC=1 SCAR=6.9
Pod documented
42 0 my ($self, $key) = @_;
43 0 delete $self->{lc $key};
44 }
45  
46 3 ▶sub flatten {
Subroutine flatten: called CC=3 SCAR=11.0
Pod documented
47 3 my $self = shift;
48 3 my @ret;
49 3 ▶ while (my ($k, $v) = each %$self) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$self) 13 3 16
50 13 for my $e (@$v) {
51 13 push @ret, $k, $e;
52 }
53 }
54 3 return @ret;
55 }
56  
57 0 ▶sub keys :method {
Subroutine keys: not called CC=1 SCAR=6.9
Pod documented
58 0 my $self = shift;
59 0 keys %$self;
60 }
61 0 ▶sub header_field_names { shift->keys }
Subroutine header_field_names: not called CC=1 SCAR=6.9
Pod documented
62  
63 2 ▶sub as_string {
Subroutine as_string: called CC=3 SCAR=11.0
Pod documented
64 2 my $self = shift;
65 2 my $ret = '';
66 2 for my $k (sort keys %$self) {
67 8 for my $e (@{$self->{$k}}) {
68 8 $ret .= "$k: $e\015\012";
69 }
70 }
71 2 return $ret;
72 }
73  
74 0 ▶sub as_http_headers {
Subroutine as_http_headers: not called CC=1 SCAR=6.9
Pod undocumented
75 0 my ($self, $key) = @_;
76 0 require HTTP::Headers;
77 0 return HTTP::Headers->new($self->flatten);
78 }
79  
80 # shortcut for popular headers.
81 0 ▶sub referer { [ shift->header( 'Referer' => @_ ) ]->[0] }
Subroutine referer: not called CC=1 SCAR=6.9
Pod documented
82 0 ▶sub expires { [ shift->header( 'Expires' => @_ ) ]->[0] }
Subroutine expires: not called CC=1 SCAR=6.9
Pod documented
83 0 ▶sub last_modified { [ shift->header( 'Last-Modified' => @_ ) ]->[0] }
Subroutine last_modified: not called CC=1 SCAR=6.9
Pod documented
84 0 ▶sub if_modified_since { [ shift->header( 'If-Modified-Since' => @_ ) ]->[0] }
Subroutine if_modified_since: not called CC=1 SCAR=6.9
Pod documented
85 2 ▶sub content_type { [ shift->header( 'Content-Type' => @_ ) ]->[0] }
Subroutine content_type: called CC=1 SCAR=0.0
Pod documented
86 2 ▶sub content_length { [ shift->header( 'Content-Length' => @_ ) ]->[0] }
Subroutine content_length: called CC=1 SCAR=0.0
Pod documented
87 0 ▶sub content_encoding { [ shift->header( 'Content-Encoding' => @_ ) ]->[0] }
Subroutine content_encoding: not called CC=1 SCAR=6.9
Pod documented
88  
89 0 ▶sub clone {
Subroutine clone: not called CC=1 SCAR=6.9
Pod documented
90 0 require Storable;
91 0 Storable::dclone($_[0]);
92 }
93  
94 14 1;
95 __END__
« Furl/Response.pm ↑ Summary Furl/ZlibStream.pm »