| 1 | package Web::Machine::Util; | ||||||||||||||||||||
| 2 | # ABSTRACT: General Utility module | ||||||||||||||||||||
| 3 | |||||||||||||||||||||
| 4 | 25 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 25 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | |||||||||||||||||||||
| 7 | 25 | our $VERSION = '0.17'; | |||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | 25 | ▶ | use Carp qw[ confess ]; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | 25 | ▶ | use Scalar::Util qw[ blessed ]; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | 25 | ▶ | use List::Util qw[ first ]; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | 25 | ▶ | use HTTP::Headers::ActionPack 0.07; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 14 | |||||||||||||||||||||
| 15 | 25 | ▶ | use Sub::Exporter -setup => { | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 16 | exports => [qw[ | ||||||||||||||||||||
| 17 | first | ||||||||||||||||||||
| 18 | pair_key | ||||||||||||||||||||
| 19 | pair_value | ||||||||||||||||||||
| 20 | bind_path | ||||||||||||||||||||
| 21 | create_date | ||||||||||||||||||||
| 22 | create_header | ||||||||||||||||||||
| 23 | inflate_headers | ||||||||||||||||||||
| 24 | ]] | ||||||||||||||||||||
| 25 | 25 | }; | |||||||||||||||||||
| 26 | |||||||||||||||||||||
| 27 | 230 | ▶ | sub pair_key { ( keys %{ $_[0] } )[0] } | ||||||||||||||||||
|
Subroutine
pair_key: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 28 | 63 | ▶ | sub pair_value { ( values %{ $_[0] } )[0] } | ||||||||||||||||||
|
Subroutine
pair_value: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 29 | |||||||||||||||||||||
| 30 | { | ||||||||||||||||||||
| 31 | 25 | my $ACTION_PACK = HTTP::Headers::ActionPack->new; | |||||||||||||||||||
| 32 | 153 | ▶ | sub create_header { $ACTION_PACK->create( @_ ) } | ||||||||||||||||||
|
Subroutine
create_header: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 33 | 28 | ▶ | sub create_date { $ACTION_PACK->create( 'DateHeader' => shift ) } | ||||||||||||||||||
|
Subroutine
create_date: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 34 | 138 | ▶ | sub inflate_headers { $ACTION_PACK->inflate( @_ ) } | ||||||||||||||||||
|
Subroutine
inflate_headers: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 35 | 24 | ▶ | sub get_action_pack { $ACTION_PACK } | ||||||||||||||||||
|
Subroutine
get_action_pack: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 36 | } | ||||||||||||||||||||
| 37 | |||||||||||||||||||||
| 38 | 25 | ▶ | sub bind_path { | ||||||||||||||||||
|
Subroutine
bind_path: called CC=14 SCAR=26.4
Pod
documented
| |||||||||||||||||||||
| 39 | 25 | my ($spec, $path) = @_; | |||||||||||||||||||
| 40 | 25 | ▶ | my @parts = grep { defined $_ && $_ ne q{} } split /\// => $path; | ||||||||||||||||||
|
Condition66%2/3
defined $_ && $_ ne ''
MC/DC50%1/2
defined $_ && $_ ne ''
defined $_
$_ ne ''
Truth table66%2/3
A && B
A= defined $_B= $_ ne ''
| |||||||||||||||||||||
| 41 | 25 | ▶ | my @spec = grep { defined $_ && $_ ne q{} } split /\// => $spec; | ||||||||||||||||||
|
Condition66%2/3
defined $_ && $_ ne ''
MC/DC50%1/2
defined $_ && $_ ne ''
defined $_
$_ ne ''
Truth table66%2/3
A && B
A= defined $_B= $_ ne ''
| |||||||||||||||||||||
| 42 | |||||||||||||||||||||
| 43 | 25 | my @results; | |||||||||||||||||||
| 44 | 25 | foreach my $i ( 0 .. $#spec ) { | |||||||||||||||||||
| 45 | 49 | ▶ | if ( $spec[ $i ] =~ /^\*$/ ) { | ||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||
| 46 | 5 | push @results => @parts; | |||||||||||||||||||
| 47 | 5 | @parts = (); | |||||||||||||||||||
| 48 | 5 | last; | |||||||||||||||||||
| 49 | } | ||||||||||||||||||||
| 50 | elsif ( $spec[ $i ] =~ /^\:/ ) { | ||||||||||||||||||||
| 51 | 20 | ▶ | return unless defined $parts[ 0 ]; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 52 | 18 | push @results => shift @parts; | |||||||||||||||||||
| 53 | } | ||||||||||||||||||||
| 54 | elsif ( $spec[ $i ] =~ /^\?\:/ ) { | ||||||||||||||||||||
| 55 | 9 | ▶ | push @results => shift @parts | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 56 | if defined $parts[ 0 ]; | ||||||||||||||||||||
| 57 | } | ||||||||||||||||||||
| 58 | else { | ||||||||||||||||||||
| 59 | 15 | ▶ | return unless defined $parts[ 0 ]; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 60 | 15 | ▶ | return unless $spec[ $i ] eq $parts[ 0 ]; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 61 | 14 | shift @parts; | |||||||||||||||||||
| 62 | } | ||||||||||||||||||||
| 63 | } | ||||||||||||||||||||
| 64 | |||||||||||||||||||||
| 65 | 22 | ▶ | return if @parts; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 66 | |||||||||||||||||||||
| 67 | wantarray | ||||||||||||||||||||
| 68 | ? @results | ||||||||||||||||||||
| 69 | 18 | ▶ | : (scalar @results == 1) | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 70 | ? $results[0] | ||||||||||||||||||||
| 71 | : @results; | ||||||||||||||||||||
| 72 | } | ||||||||||||||||||||
| 73 | |||||||||||||||||||||
| 74 | 25 | 1; | |||||||||||||||||||
| 75 | |||||||||||||||||||||
| 76 | __END__ | ||||||||||||||||||||