line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
2
|
|
|
2
|
|
39532
|
use strictures 2; |
|
2
|
|
|
|
|
2404
|
|
|
2
|
|
|
|
|
80
|
|
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package HTTP::Headers::Fancy; |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
# ABSTRACT: Fancy naming schema of HTTP headers |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.001'; # VERSION |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub decode_key { |
10
|
7
|
50
|
|
7
|
1
|
28
|
shift if $_[0] eq __PACKAGE__; |
11
|
7
|
|
|
|
|
10
|
my $k = shift; |
12
|
7
|
|
|
|
|
30
|
$k =~ s{^([^-]+)}{ucfirst(lc($1))}e; |
|
7
|
|
|
|
|
20
|
|
13
|
7
|
|
|
|
|
16
|
$k =~ s{-+([^-]+)}{ucfirst(lc($1))}ge; |
|
8
|
|
|
|
|
13
|
|
14
|
7
|
|
|
|
|
27
|
return ucfirst($k); |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub decode_hash { |
18
|
0
|
0
|
|
0
|
1
|
0
|
shift if $_[0] eq __PACKAGE__; |
19
|
0
|
0
|
|
|
|
0
|
my %headers = @_ == 1 ? %{ +shift } : @_; |
|
0
|
|
|
|
|
0
|
|
20
|
0
|
|
|
|
|
0
|
while ( my ( $old, $val ) = each %headers ) { |
21
|
0
|
|
|
|
|
0
|
my $new = decode_key($old); |
22
|
0
|
0
|
|
|
|
0
|
if ( $old ne $new ) { |
23
|
0
|
|
|
|
|
0
|
$headers{$new} = delete $headers{$old}; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
} |
26
|
0
|
0
|
|
|
|
0
|
wantarray ? %headers : \%headers; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub encode_key { |
30
|
10
|
50
|
|
10
|
1
|
35
|
shift if $_[0] eq __PACKAGE__; |
31
|
10
|
|
|
|
|
18
|
my $k = +shift =~ s{_}{-}gr; |
32
|
10
|
|
|
|
|
82
|
$k =~ s{([^-])([A-Z])}{$1-$2} while $k =~ m{([^-])([A-Z])}; |
33
|
10
|
|
|
|
|
46
|
return lc($k); |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub encode_hash { |
37
|
0
|
0
|
|
0
|
1
|
|
shift if $_[0] eq __PACKAGE__; |
38
|
0
|
0
|
|
|
|
|
my %headers = @_ == 1 ? %{ +shift } : @_; |
|
0
|
|
|
|
|
|
|
39
|
0
|
|
|
|
|
|
while ( my ( $old, $val ) = each %headers ) { |
40
|
0
|
0
|
|
|
|
|
delete $headers{$old} unless defined $val; |
41
|
0
|
|
|
|
|
|
my $new = encode_key($old); |
42
|
0
|
0
|
|
|
|
|
if ( $old ne $new ) { |
43
|
0
|
|
|
|
|
|
$headers{$new} = delete $headers{$old}; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
} |
46
|
0
|
0
|
|
|
|
|
wantarray ? %headers : \%headers; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
1; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
__END__ |