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