| 1 | package Data::Riak::Fast::Link; | ||||||||||||||
| 2 | |||||||||||||||
| 3 | 23 | ▶ | use Mouse; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 4 | |||||||||||||||
| 5 | 23 | ▶ | use URL::Encode qw/url_encode url_decode/; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 6 | 23 | ▶ | use HTTP::Headers::ActionPack::LinkHeader; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 7 | |||||||||||||||
| 8 | 23 | has bucket => ( | |||||||||||||
| 9 | is => 'ro', | ||||||||||||||
| 10 | isa => 'Str', | ||||||||||||||
| 11 | required => 1 | ||||||||||||||
| 12 | ); | ||||||||||||||
| 13 | |||||||||||||||
| 14 | 23 | has key => ( | |||||||||||||
| 15 | is => 'ro', | ||||||||||||||
| 16 | isa => 'Str', | ||||||||||||||
| 17 | predicate => 'has_key' | ||||||||||||||
| 18 | ); | ||||||||||||||
| 19 | |||||||||||||||
| 20 | 23 | has riaktag => ( | |||||||||||||
| 21 | is => 'ro', | ||||||||||||||
| 22 | isa => 'Str', | ||||||||||||||
| 23 | predicate => 'has_riaktag' | ||||||||||||||
| 24 | ); | ||||||||||||||
| 25 | |||||||||||||||
| 26 | has params => ( | ||||||||||||||
| 27 | is => 'ro', | ||||||||||||||
| 28 | isa => 'HashRef', | ||||||||||||||
| 29 | 0 | ▶ | default => sub { +{} } | ||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||
| 30 | 23 | ); | |||||||||||||
| 31 | |||||||||||||||
| 32 | 0 | ▶ | sub from_link_header { | ||||||||||||
|
Subroutine
from_link_header: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||
| 33 | 0 | my ($class, $link_header) = @_; | |||||||||||||
| 34 | |||||||||||||||
| 35 | 0 | my ($bucket, $key, $riaktag); | |||||||||||||
| 36 | |||||||||||||||
| 37 | # link to another key in riak | ||||||||||||||
| 38 | 0 | ▶ | if ($link_header->href =~ /^\/buckets\/(.*)\/keys\/(.*)/) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 39 | 0 | ($bucket, $key) = ($1, $2); | |||||||||||||
| 40 | } | ||||||||||||||
| 41 | # link to a bucket | ||||||||||||||
| 42 | elsif ($link_header->href =~ /^\/buckets\/(.*)/) { | ||||||||||||||
| 43 | 0 | $bucket = $1; | |||||||||||||
| 44 | } | ||||||||||||||
| 45 | else { | ||||||||||||||
| 46 | 0 | confess "Incompatible link header URL (" . $link_header->href . ")"; | |||||||||||||
| 47 | } | ||||||||||||||
| 48 | |||||||||||||||
| 49 | 0 | my %params = %{ $link_header->params }; | |||||||||||||
| 50 | |||||||||||||||
| 51 | $riaktag = url_decode( delete $params{'riaktag'} ) | ||||||||||||||
| 52 | 0 | ▶ | if exists $params{'riaktag'}; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 53 | |||||||||||||||
| 54 | 0 | ▶ | $class->new( | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 55 | bucket => $bucket, | ||||||||||||||
| 56 | ($key ? (key => $key) : ()), | ||||||||||||||
| 57 | ($riaktag ? (riaktag => $riaktag) : ()), | ||||||||||||||
| 58 | params => \%params | ||||||||||||||
| 59 | ); | ||||||||||||||
| 60 | } | ||||||||||||||
| 61 | |||||||||||||||
| 62 | 0 | ▶ | sub as_link_header { | ||||||||||||
|
Subroutine
as_link_header: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||
| 63 | 0 | my $self = shift; | |||||||||||||
| 64 | 0 | ▶ | if ($self->has_key) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 65 | return HTTP::Headers::ActionPack::LinkHeader->new( | ||||||||||||||
| 66 | sprintf('/buckets/%s/keys/%s', $self->bucket, $self->key), | ||||||||||||||
| 67 | ($self->has_riaktag ? (riaktag => url_encode($self->riaktag)) : ()), | ||||||||||||||
| 68 | 0 | ▶ | %{ $self->params } | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 69 | ); | ||||||||||||||
| 70 | } | ||||||||||||||
| 71 | else { | ||||||||||||||
| 72 | return HTTP::Headers::ActionPack::LinkHeader->new( | ||||||||||||||
| 73 | sprintf('/buckets/%s', $self->bucket), | ||||||||||||||
| 74 | ($self->has_riaktag ? (riaktag => url_encode($self->riaktag)) : ()), | ||||||||||||||
| 75 | 0 | ▶ | %{ $self->params } | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 76 | ); | ||||||||||||||
| 77 | } | ||||||||||||||
| 78 | } | ||||||||||||||
| 79 | |||||||||||||||
| 80 | |||||||||||||||
| 81 | 23 | __PACKAGE__->meta->make_immutable; | |||||||||||||
| 82 | 23 | ▶ | no Mouse; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 83 | |||||||||||||||
| 84 | 23 | 1; | |||||||||||||
| 85 | |||||||||||||||
| 86 | __END__ | ||||||||||||||