| 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.16'; | |||||||||||||||||
| 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 => { | |||||||||||||||||
| 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 | ▶ | }; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 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 { | |||||||||||||||||
| 39 | 24 | ▶ | my ($spec, $path) = @_; | ||||||||||||||||
|
Subroutine
bind_path: called CC=12 SCAR=24.9
Pod
documented
| |||||||||||||||||||
| 40 | 24 | my @parts = grep { $_ } split /\// => $path; | |||||||||||||||||
| 41 | 24 | my @spec = grep { $_ } split /\// => $spec; | |||||||||||||||||
| 42 | |||||||||||||||||||
| 43 | 24 | my @results; | |||||||||||||||||
| 44 | 24 | foreach my $i ( 0 .. $#spec ) { | |||||||||||||||||
| 45 | 46 | ▶ | if ( $spec[ $i ] =~ /^\*$/ ) { | ||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||
| 46 | 5 | push @results => @parts; | |||||||||||||||||
| 47 | 5 | @parts = (); | |||||||||||||||||
| 48 | 5 | last; | |||||||||||||||||
| 49 | } | ||||||||||||||||||
| 50 | elsif ( $spec[ $i ] =~ /^\:/ ) { | ||||||||||||||||||
| 51 | 18 | ▶ | return unless defined $parts[ 0 ]; | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 52 | 16 | 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 | 14 | ▶ | return unless defined $parts[ 0 ]; | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 60 | 14 | ▶ | return unless $spec[ $i ] eq $parts[ 0 ]; | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 61 | 13 | shift @parts; | |||||||||||||||||
| 62 | } | ||||||||||||||||||
| 63 | } | ||||||||||||||||||
| 64 | |||||||||||||||||||
| 65 | 21 | ▶ | return if @parts; | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 66 | |||||||||||||||||||
| 67 | wantarray | ||||||||||||||||||
| 68 | ? @results | ||||||||||||||||||
| 69 | 17 | ▶ | : (scalar @results == 1) | ||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||
| 70 | ? $results[0] | ||||||||||||||||||
| 71 | : @results; | ||||||||||||||||||
| 72 | } | ||||||||||||||||||
| 73 | |||||||||||||||||||
| 74 | 25 | 1; | |||||||||||||||||
| 75 | |||||||||||||||||||
| 76 | __END__ | ||||||||||||||||||