| 1 | package HTTP::Headers::ActionPack::LinkHeader; | ||||||||||
| 2 | # ABSTRACT: A Link | ||||||||||
| 3 | |||||||||||
| 4 | 7 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 7 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | 7 | our $VERSION = '0.10'; | |||||||||
| 8 | |||||||||||
| 9 | 7 | ▶ | use URI::Escape qw[ uri_escape uri_unescape ]; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 7 | ▶ | use HTTP::Headers::ActionPack::Util qw[ join_header_words ]; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | |||||||||||
| 12 | 7 | ▶ | use parent 'HTTP::Headers::ActionPack::Core::BaseHeaderType'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | |||||||||||
| 14 | 28 | ▶ | sub BUILDARGS { | ||||||||
|
Subroutine
BUILDARGS: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 15 | 28 | my $class = shift; | |||||||||
| 16 | 28 | my ($href, @params) = @_; | |||||||||
| 17 | |||||||||||
| 18 | 28 | $href =~ s/^<//; | |||||||||
| 19 | 28 | $href =~ s/>$//; | |||||||||
| 20 | |||||||||||
| 21 | 28 | $class->SUPER::BUILDARGS( $href, @params ); | |||||||||
| 22 | } | ||||||||||
| 23 | |||||||||||
| 24 | 28 | ▶ | sub BUILD { | ||||||||
|
Subroutine
BUILD: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 25 | 28 | my $self = shift; | |||||||||
| 26 | 28 | foreach my $param ( grep { /\*$/ } @{ $self->_param_order } ) { | |||||||||
| 27 | 2 | my ($encoding, $language, $content) = ( $self->params->{ $param } =~ /^(.*)\'(.*)\'(.*)$/); | |||||||||
| 28 | 2 | $self->params->{ $param } = { | |||||||||
| 29 | encoding => $encoding, | ||||||||||
| 30 | language => $language, | ||||||||||
| 31 | content => uri_unescape( $content ) | ||||||||||
| 32 | }; | ||||||||||
| 33 | } | ||||||||||
| 34 | } | ||||||||||
| 35 | |||||||||||
| 36 | 40 | ▶ | sub href { (shift)->subject } | ||||||||
|
Subroutine
href: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 37 | 6 | ▶ | sub rel { (shift)->params->{'rel'} } | ||||||||
|
Subroutine
rel: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 38 | |||||||||||
| 39 | 11 | ▶ | sub relation_matches { | ||||||||
|
Subroutine
relation_matches: called CC=5 SCAR=16.3
Pod
undocumented
| |||||||||||
| 40 | 11 | my ($self, $relation) = @_; | |||||||||
| 41 | |||||||||||
| 42 | 11 | ▶ | if ( my $rel = $self->params->{'rel'} ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 43 | # if it is an extension rel type | ||||||||||
| 44 | # then it is a URI and it should | ||||||||||
| 45 | # not be compared in a case-insensitive | ||||||||||
| 46 | # manner ... | ||||||||||
| 47 | 11 | ▶ | if ( $rel =~ m!^\w+\://! ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 48 | 2 | ▶ | $self->params->{'rel'} eq $relation ? 1 : 0; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 49 | } | ||||||||||
| 50 | # if it is not a URI, then compare | ||||||||||
| 51 | # it case-insensitively | ||||||||||
| 52 | else { | ||||||||||
| 53 | 9 | ▶ | (lc $self->params->{'rel'} ) eq (lc $relation) ? 1 : 0; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 54 | } | ||||||||||
| 55 | } | ||||||||||
| 56 | } | ||||||||||
| 57 | |||||||||||
| 58 | 34 | ▶ | sub as_string { | ||||||||
|
Subroutine
as_string: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||
| 59 | 34 | my $self = shift; | |||||||||
| 60 | |||||||||||
| 61 | 34 | my @params; | |||||||||
| 62 | 34 | foreach my $param ( @{ $self->_param_order } ) { | |||||||||
| 63 | 52 | ▶ | if ( $param =~ /\*$/ ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 64 | 2 | my $complex = $self->params->{ $param }; | |||||||||
| 65 | push @params => ( $param, | ||||||||||
| 66 | join "'" => ( | ||||||||||
| 67 | $complex->{'encoding'}, | ||||||||||
| 68 | $complex->{'language'}, | ||||||||||
| 69 | 2 | uri_escape( $complex->{'content'} ), | |||||||||
| 70 | ) | ||||||||||
| 71 | ); | ||||||||||
| 72 | } | ||||||||||
| 73 | else { | ||||||||||
| 74 | 50 | push @params => ( $param, $self->params->{ $param } ); | |||||||||
| 75 | } | ||||||||||
| 76 | 52 | my ($encoding, $language, $content) = ( $self->params->{ $param } =~ /^(.*)\'(.*)\'(.*)$/); | |||||||||
| 77 | } | ||||||||||
| 78 | |||||||||||
| 79 | 34 | join_header_words( '<' . $self->href . '>', @params ); | |||||||||
| 80 | } | ||||||||||
| 81 | |||||||||||
| 82 | 7 | 1; | |||||||||
| 83 | |||||||||||
| 84 | __END__ | ||||||||||