line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package CGI::Header; |
2
|
3
|
|
|
3
|
|
36579
|
use 5.008_009; |
|
3
|
|
|
|
|
14
|
|
|
3
|
|
|
|
|
151
|
|
3
|
3
|
|
|
3
|
|
20
|
use strict; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
114
|
|
4
|
3
|
|
|
3
|
|
20
|
use warnings; |
|
3
|
|
|
|
|
29
|
|
|
3
|
|
|
|
|
140
|
|
5
|
3
|
|
|
3
|
|
21
|
use Carp qw/croak/; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
3317
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.63'; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub new { |
10
|
13
|
|
|
13
|
0
|
33017
|
my $class = shift; |
11
|
13
|
50
|
|
|
|
61
|
my %args = @_ == 1 ? %{$_[0]} : @_; |
|
0
|
|
|
|
|
0
|
|
12
|
13
|
|
|
|
|
55
|
( bless \%args => $class )->_rehash; |
13
|
|
|
|
|
|
|
} |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub header { |
16
|
60
|
|
100
|
60
|
1
|
703
|
$_[0]->{header} ||= {}; |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub query { |
20
|
6
|
|
|
6
|
1
|
9
|
my $self = shift; |
21
|
6
|
|
66
|
|
|
58
|
$self->{query} ||= $self->_build_query; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub _build_query { |
25
|
3
|
|
|
3
|
|
2415
|
require CGI; |
26
|
3
|
|
|
|
|
16334
|
CGI::self_or_default(); |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub _alias { |
30
|
39
|
|
|
39
|
|
42
|
my $self = shift; |
31
|
39
|
|
66
|
|
|
122
|
$self->{alias} ||= $self->_build_alias; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub _build_alias { |
35
|
|
|
|
|
|
|
+{ |
36
|
9
|
|
|
9
|
|
54
|
'content-type' => 'type', |
37
|
|
|
|
|
|
|
'cookie' => 'cookies', |
38
|
|
|
|
|
|
|
}; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub _normalize { |
42
|
39
|
|
|
39
|
|
482
|
my ( $self, $key ) = @_; |
43
|
39
|
|
|
|
|
71
|
my $alias = $self->_alias; |
44
|
39
|
|
|
|
|
60
|
my $prop = lc $key; |
45
|
39
|
|
|
|
|
68
|
$prop =~ s/^-//; |
46
|
39
|
|
|
|
|
44
|
$prop =~ tr/_/-/; |
47
|
39
|
100
|
|
|
|
91
|
$prop = $alias->{$prop} if exists $alias->{$prop}; |
48
|
39
|
|
|
|
|
93
|
$prop; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub _rehash { |
52
|
13
|
|
|
13
|
|
19
|
my $self = shift; |
53
|
13
|
|
|
|
|
32
|
my $header = $self->header; |
54
|
|
|
|
|
|
|
|
55
|
13
|
|
|
|
|
44
|
for my $key ( keys %$header ) { |
56
|
22
|
|
|
|
|
50
|
my $prop = $self->_normalize( $key ); |
57
|
22
|
100
|
|
|
|
53
|
next if $key eq $prop; # $key is normalized |
58
|
12
|
100
|
|
|
|
48
|
croak "Property '$prop' already exists" if exists $header->{$prop}; |
59
|
11
|
|
|
|
|
25
|
$header->{$prop} = delete $header->{$key}; # rename $key to $prop |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
12
|
|
|
|
|
40
|
$self; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub get { |
66
|
4
|
|
|
4
|
1
|
13
|
my ( $self, @keys ) = @_; |
67
|
4
|
|
|
|
|
8
|
my @props = map { $self->_normalize($_) } @keys; |
|
6
|
|
|
|
|
31
|
|
68
|
4
|
|
|
|
|
7
|
@{ $self->header }{ @props }; |
|
4
|
|
|
|
|
9
|
|
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub set { |
72
|
4
|
|
|
4
|
1
|
813
|
my ( $self, @pairs ) = @_; |
73
|
4
|
|
|
|
|
8
|
my $header = $self->header; |
74
|
|
|
|
|
|
|
|
75
|
4
|
100
|
|
|
|
28
|
croak 'Odd number of arguments passed to set()' if @pairs % 2; |
76
|
|
|
|
|
|
|
|
77
|
3
|
|
|
|
|
4
|
my @values; |
78
|
3
|
|
|
|
|
13
|
while ( my ($key, $value) = splice @pairs, 0, 2 ) { |
79
|
4
|
|
|
|
|
7
|
my $prop = $self->_normalize( $key ); |
80
|
4
|
|
|
|
|
21
|
push @values, $header->{$prop} = $value; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
3
|
100
|
|
|
|
20
|
wantarray ? @values : $values[-1]; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub exists { |
87
|
1
|
|
|
1
|
1
|
2
|
my ( $self, $key ) = @_; |
88
|
1
|
|
|
|
|
3
|
my $prop = $self->_normalize( $key ); |
89
|
1
|
|
|
|
|
3
|
exists $self->header->{$prop}; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
sub delete { |
93
|
3
|
|
|
3
|
1
|
10
|
my ( $self, @keys ) = @_; |
94
|
3
|
|
|
|
|
6
|
my @props = map { $self->_normalize($_) } @keys; |
|
4
|
|
|
|
|
8
|
|
95
|
3
|
|
|
|
|
4
|
delete @{ $self->header }{ @props }; |
|
3
|
|
|
|
|
7
|
|
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
sub clear { |
99
|
1
|
|
|
1
|
1
|
7
|
my $self = shift; |
100
|
1
|
|
|
|
|
1
|
undef %{ $self->header }; |
|
1
|
|
|
|
|
3
|
|
101
|
1
|
|
|
|
|
5
|
$self; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
# See also Moose::Meta::Method::Accessor::Native::Hash |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
BEGIN { |
107
|
3
|
|
|
3
|
|
14
|
for my $method (qw/ |
108
|
|
|
|
|
|
|
attachment |
109
|
|
|
|
|
|
|
charset |
110
|
|
|
|
|
|
|
cookies |
111
|
|
|
|
|
|
|
expires |
112
|
|
|
|
|
|
|
nph |
113
|
|
|
|
|
|
|
p3p |
114
|
|
|
|
|
|
|
status |
115
|
|
|
|
|
|
|
target |
116
|
|
|
|
|
|
|
type |
117
|
|
|
|
|
|
|
/) { |
118
|
|
|
|
|
|
|
my $body = sub { |
119
|
20
|
|
|
20
|
|
1147
|
my $self = shift; |
120
|
20
|
100
|
|
|
|
61
|
return $self->header->{$method} unless @_; |
121
|
10
|
|
|
|
|
21
|
$self->header->{$method} = shift; |
122
|
10
|
|
|
|
|
38
|
$self; |
123
|
27
|
|
|
|
|
119
|
}; |
124
|
|
|
|
|
|
|
|
125
|
3
|
|
|
3
|
|
20
|
no strict 'refs'; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
129
|
|
126
|
27
|
|
|
|
|
546
|
*$method = $body; |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
sub finalize { |
131
|
1
|
|
|
1
|
1
|
2
|
my $self = shift; |
132
|
1
|
|
|
|
|
3
|
my $query = $self->query; |
133
|
1
|
|
|
|
|
12
|
my $args = $self->header; |
134
|
|
|
|
|
|
|
|
135
|
1
|
|
|
|
|
10
|
$query->print( $query->header($args) ); |
136
|
|
|
|
|
|
|
|
137
|
1
|
|
|
|
|
1358
|
return; |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
sub clone { |
141
|
1
|
|
|
1
|
1
|
6
|
my $self = shift; |
142
|
1
|
|
|
|
|
3
|
my %header = %{ $self->header }; |
|
1
|
|
|
|
|
4
|
|
143
|
1
|
|
|
|
|
6
|
ref( $self )->new( %$self, header => \%header ); |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
1; |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
__END__ |