| 1 | package Net::Blossom::URI; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use strictures 2; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use Net::Blossom::_ConstructorArgs (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 3 | ▶ | use Net::Blossom::_URL (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | 3 | ▶ | use Carp qw(croak); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 3 | ▶ | use Class::Tiny qw(sha256 sz), { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | extension => 'bin', | ||||||||||||||||||||||||||||||||||||||||||
| 11 | 8 | ▶ | xs => sub { [] }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 6 | ▶ | as => sub { [] }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 3 | }; | |||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | 3 | my $HEX64 = qr/\A[0-9a-f]{64}\z/; | |||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | 16 | ▶ | sub BUILDARGS { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BUILDARGS: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | 16 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||
| 19 | 16 | my %args = Net::Blossom::_ConstructorArgs::normalize(@_); | |||||||||||||||||||||||||||||||||||||||||
| 20 | 16 | my %known = map { $_ => 1 } qw(sha256 extension xs as sz); | |||||||||||||||||||||||||||||||||||||||||
| 21 | 16 | my @unknown = grep { !exists $known{$_} } keys %args; | |||||||||||||||||||||||||||||||||||||||||
| 22 | 16 | ▶ | croak "unknown argument(s): " . join(', ', sort @unknown) if @unknown; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | 16 | return \%args; | |||||||||||||||||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||
| 27 | 16 | ▶ | sub BUILD { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BUILD: called CC=22 SCAR=32.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | 16 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 29 | 16 | ▶ | croak "sha256 is required" unless defined $self->sha256; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 30 | 15 | ▶ | croak "sha256 must be 64-char lowercase hex" unless $self->sha256 =~ $HEX64; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||
| 32 | 14 | my $extension = $self->extension; | |||||||||||||||||||||||||||||||||||||||||
| 33 | 14 | ▶ | $extension = 'bin' unless defined $extension && length $extension; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $extension and length $extension
MC/DC0%0/2
defined $extension and length $extension
defined $extension
length $extension
Truth table33%1/3
A and B
A= defined $extensionB= length $extension
| |||||||||||||||||||||||||||||||||||||||||||
| 34 | 14 | $extension =~ s/\A\.//; | |||||||||||||||||||||||||||||||||||||||||
| 35 | 14 | ▶ | croak "extension must contain only letters and digits" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
length $extension and $extension =~ /\A[A-Za-z0-9]+\z/
MC/DC50%1/2
length $extension and $extension =~ /\A[A-Za-z0-9]+\z/
length $extension
$extension =~ /\A[A-Za-z0-9]+\z/
Truth table66%2/3
A and B
A= length $extensionB= $extension =~ /\A[A-Za-z0-9]+\z/
| |||||||||||||||||||||||||||||||||||||||||||
| 36 | unless length($extension) && $extension =~ /\A[A-Za-z0-9]+\z/; | ||||||||||||||||||||||||||||||||||||||||||
| 37 | 13 | $self->extension($extension); | |||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||
| 39 | 13 | ▶ | $self->xs([]) unless defined $self->xs; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 40 | 13 | ▶ | croak "xs must be an array reference" unless ref($self->xs) eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 41 | 12 | my @xs = @{$self->xs}; | |||||||||||||||||||||||||||||||||||||||||
| 42 | 12 | for my $server (@xs) { | |||||||||||||||||||||||||||||||||||||||||
| 43 | 7 | ▶ | croak "server hint must be a domain or http(s) root URL" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
defined $server and not ref $server and _valid_server_hint($server)
defined $server and not ref $server
MC/DC33%1/3
defined $server and not ref $server and _valid_server_hint($server)
defined $server
not ref $server
_valid_server_hint($server)
Truth table50%2/4
A and not(B) and C
A= defined $serverB= not ref $serverC= _valid_server_hint($server)
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | unless defined $server && !ref($server) && _valid_server_hint($server); | ||||||||||||||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | 11 | ▶ | $self->as([]) unless defined $self->as; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | 11 | ▶ | croak "as must be an array reference" unless ref($self->as) eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | 11 | my @as = @{$self->as}; | |||||||||||||||||||||||||||||||||||||||||
| 50 | 11 | for my $author (@as) { | |||||||||||||||||||||||||||||||||||||||||
| 51 | 7 | ▶ | croak "author hint must be 64-char lowercase hex" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
defined $author and not ref $author and $author =~ /$HEX64/
defined $author and not ref $author
MC/DC33%1/3
defined $author and not ref $author and $author =~ /$HEX64/
defined $author
not ref $author
$author =~ /$HEX64/
Truth table50%2/4
A and not(B) and C
A= defined $authorB= not ref $authorC= $author =~ /$HEX64/
| |||||||||||||||||||||||||||||||||||||||||||
| 52 | unless defined $author && !ref($author) && $author =~ $HEX64; | ||||||||||||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||
| 55 | 9 | ▶ | if (defined $self->sz) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 56 | 5 | ▶ | croak "size must be a positive integer" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not ref $self->sz and $self->sz =~ /\A[1-9][0-9]*\z/
MC/DC50%1/2
not ref $self->sz and $self->sz =~ /\A[1-9][0-9]*\z/
not ref $self->sz
$self->sz =~ /\A[1-9][0-9]*\z/
Truth table66%2/3
not(A) and B
A= not ref $self->szB= $self->sz =~ /\A[1-9][0-9]*\z/
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | unless !ref($self->sz) && $self->sz =~ /\A[1-9][0-9]*\z/; | ||||||||||||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||
| 60 | 7 | $self->xs(\@xs); | |||||||||||||||||||||||||||||||||||||||||
| 61 | 7 | $self->as(\@as); | |||||||||||||||||||||||||||||||||||||||||
| 62 | 7 | return; | |||||||||||||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||
| 65 | 14 | ▶ | sub parse { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse: called CC=13 SCAR=25.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 66 | 14 | my ($class, $value) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 67 | 14 | ▶ | croak "URI is required" unless defined $value && length $value; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $value and length $value
MC/DC0%0/2
defined $value and length $value
defined $value
length $value
Truth table33%1/3
A and B
A= defined $valueB= length $value
| |||||||||||||||||||||||||||||||||||||||||||
| 68 | 14 | ▶ | croak "URI must use blossom scheme" unless $value =~ s/\Ablossom://; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 69 | 13 | ▶ | croak "fragments are not allowed" if $value =~ /#/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | 13 | my ($path, $query) = split /\?/, $value, 2; | |||||||||||||||||||||||||||||||||||||||||
| 72 | 13 | my ($sha256, $extension) = _parse_path($path); | |||||||||||||||||||||||||||||||||||||||||
| 73 | 9 | my %args = ( | |||||||||||||||||||||||||||||||||||||||||
| 74 | sha256 => $sha256, | ||||||||||||||||||||||||||||||||||||||||||
| 75 | extension => $extension, | ||||||||||||||||||||||||||||||||||||||||||
| 76 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||
| 78 | 9 | ▶ | if (defined $query && length $query) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $query and length $query
MC/DC50%1/2
defined $query and length $query
defined $query
length $query
Truth table66%2/3
A and B
A= defined $queryB= length $query
| |||||||||||||||||||||||||||||||||||||||||||
| 79 | 7 | for my $pair (split /&/, $query) { | |||||||||||||||||||||||||||||||||||||||||
| 80 | 16 | ▶ | croak "query parameter must include value" unless $pair =~ /=/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 81 | 16 | my ($key, $raw_value) = split /=/, $pair, 2; | |||||||||||||||||||||||||||||||||||||||||
| 82 | 16 | $key = _pct_decode($key); | |||||||||||||||||||||||||||||||||||||||||
| 83 | 16 | my $decoded = _pct_decode($raw_value); | |||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||
| 85 | 15 | ▶ | if ($key eq 'xs') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 86 | 4 | push @{$args{xs}}, $decoded; | |||||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||||||
| 88 | elsif ($key eq 'as') { | ||||||||||||||||||||||||||||||||||||||||||
| 89 | 5 | push @{$args{as}}, $decoded; | |||||||||||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||||||||||||
| 91 | elsif ($key eq 'sz') { | ||||||||||||||||||||||||||||||||||||||||||
| 92 | 5 | ▶ | croak "duplicate size parameter" if defined $args{sz}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 93 | 4 | $args{sz} = $decoded; | |||||||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||||||
| 95 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 96 | 1 | croak "unknown query parameter: $key"; | |||||||||||||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||
| 101 | 6 | return $class->new(%args); | |||||||||||||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||
| 104 | 4 | ▶ | sub to_string { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
to_string: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 105 | 4 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 106 | 4 | my $value = 'blossom:' . $self->sha256 . '.' . $self->extension; | |||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||
| 108 | 4 | my @query; | |||||||||||||||||||||||||||||||||||||||||
| 109 | 4 | push @query, map { ['xs', $_] } @{$self->xs}; | |||||||||||||||||||||||||||||||||||||||||
| 110 | 4 | push @query, map { ['as', $_] } @{$self->as}; | |||||||||||||||||||||||||||||||||||||||||
| 111 | 4 | ▶ | push @query, ['sz', $self->sz] if defined $self->sz; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||
| 113 | 4 | ▶ | return $value unless @query; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 114 | 1 | return $value . '?' . join('&', map { _pct_encode($_->[0]) . '=' . _pct_encode($_->[1]) } @query); | |||||||||||||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||
| 117 | 13 | ▶ | sub _parse_path { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_parse_path: called CC=7 SCAR=20.4
| |||||||||||||||||||||||||||||||||||||||||||
| 118 | 13 | my ($path) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 119 | 13 | ▶ | croak "sha256 must be 64-char lowercase hex" unless defined $path && length $path; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $path and length $path
MC/DC0%0/2
defined $path and length $path
defined $path
length $path
Truth table33%1/3
A and B
A= defined $pathB= length $path
| |||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||
| 121 | 13 | my ($sha256, $extension) = split /\./, $path, 2; | |||||||||||||||||||||||||||||||||||||||||
| 122 | 13 | ▶ | croak "extension is required" unless defined $extension && length $extension; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $extension and length $extension
MC/DC50%1/2
defined $extension and length $extension
defined $extension
length $extension
Truth table66%2/3
A and B
A= defined $extensionB= length $extension
| |||||||||||||||||||||||||||||||||||||||||||
| 123 | 11 | ▶ | croak "sha256 must be 64-char lowercase hex" unless defined $sha256 && $sha256 =~ $HEX64; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $sha256 and $sha256 =~ /$HEX64/
MC/DC50%1/2
defined $sha256 and $sha256 =~ /$HEX64/
defined $sha256
$sha256 =~ /$HEX64/
Truth table66%2/3
A and B
A= defined $sha256B= $sha256 =~ /$HEX64/
| |||||||||||||||||||||||||||||||||||||||||||
| 124 | 9 | return ($sha256, $extension); | |||||||||||||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||
| 127 | 7 | ▶ | sub _valid_server_hint { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_valid_server_hint: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 128 | 7 | my ($server) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 129 | 7 | ▶ | return Net::Blossom::_URL::http_root_url($server) if $server =~ m{\Ahttps?://}i; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 130 | 4 | return $server =~ m{\A[A-Za-z0-9][A-Za-z0-9.-]*(?::[1-9][0-9]*)?\z}; | |||||||||||||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||
| 133 | 32 | ▶ | sub _pct_decode { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_pct_decode: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||
| 134 | 32 | my ($value) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 135 | 32 | ▶ | croak "invalid percent encoding" if $value =~ /%(?![0-9A-Fa-f]{2})/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 136 | 31 | $value =~ tr/+/ /; | |||||||||||||||||||||||||||||||||||||||||
| 137 | 0 | $value =~ s/%([0-9A-Fa-f]{2})/chr(hex($1))/eg; | |||||||||||||||||||||||||||||||||||||||||
| 138 | 31 | return $value; | |||||||||||||||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||
| 141 | 8 | ▶ | sub _pct_encode { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_pct_encode: called CC=1 SCAR=0.1
| |||||||||||||||||||||||||||||||||||||||||||
| 142 | 8 | my ($value) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 143 | 8 | $value = "$value"; | |||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | $value =~ s/([^A-Za-z0-9._~:\/-])/sprintf("%%%02X", ord($1))/ge; | |||||||||||||||||||||||||||||||||||||||||
| 145 | 8 | return $value; | |||||||||||||||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||
| 148 | 3 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||
| 150 | =pod | ||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||
| 152 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||
| 154 | Net::Blossom::URI - BUD-10 Blossom URI value object | ||||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||
| 156 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||
| 158 | use Net::Blossom::URI; | ||||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||
| 160 | my $uri = Net::Blossom::URI->new( | ||||||||||||||||||||||||||||||||||||||||||
| 161 | sha256 => $sha256, | ||||||||||||||||||||||||||||||||||||||||||
| 162 | extension => 'png', | ||||||||||||||||||||||||||||||||||||||||||
| 163 | xs => ['cdn.example.com'], | ||||||||||||||||||||||||||||||||||||||||||
| 164 | as => [$pubkey], | ||||||||||||||||||||||||||||||||||||||||||
| 165 | sz => 1234, | ||||||||||||||||||||||||||||||||||||||||||
| 166 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||
| 168 | my $string = $uri->to_string; | ||||||||||||||||||||||||||||||||||||||||||
| 169 | my $parsed = Net::Blossom::URI->parse($string); | ||||||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||||||
| 171 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||||
| 173 | C<Net::Blossom::URI> builds and parses BUD-10 C<blossom:> URIs. | ||||||||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||||||||
| 175 | =head1 CONSTRUCTORS | ||||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||
| 177 | =head2 new | ||||||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||||||
| 179 | my $uri = Net::Blossom::URI->new(%args); | ||||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||
| 181 | Required C<sha256> must be lowercase 64-character hex. | ||||||||||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||||||||
| 183 | Optional C<extension> defaults to C<bin> and must contain only letters and | ||||||||||||||||||||||||||||||||||||||||||
| 184 | digits. A leading dot is removed. | ||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||
| 186 | Optional C<xs> is an array reference of server hints. Each hint must be a domain | ||||||||||||||||||||||||||||||||||||||||||
| 187 | or HTTP/HTTPS root URL without a path. Optional C<as> is an array reference of | ||||||||||||||||||||||||||||||||||||||||||
| 188 | lowercase 64-character author public keys. Optional C<sz> is a positive integer | ||||||||||||||||||||||||||||||||||||||||||
| 189 | byte size. | ||||||||||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||||||||
| 191 | Unknown arguments or invalid values croak. | ||||||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||||||
| 193 | =head2 parse | ||||||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||||||
| 195 | my $uri = Net::Blossom::URI->parse($value); | ||||||||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||||||||
| 197 | Parses a C<blossom:> URI and returns a C<Net::Blossom::URI> object. Fragments | ||||||||||||||||||||||||||||||||||||||||||
| 198 | are rejected. Unknown query parameters, duplicate C<sz>, missing values, and | ||||||||||||||||||||||||||||||||||||||||||
| 199 | invalid percent encoding croak. | ||||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||
| 201 | =head1 ACCESSORS | ||||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||||
| 203 | =head2 sha256 | ||||||||||||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||||||||||
| 205 | Returns the lowercase SHA-256 hash. | ||||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||
| 207 | =head2 extension | ||||||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||||||
| 209 | Returns the extension without a leading dot. | ||||||||||||||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||||||||||||||
| 211 | =head2 xs | ||||||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||||||
| 213 | Returns the server hint array reference. | ||||||||||||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||||||||||||
| 215 | =head2 as | ||||||||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||||||
| 217 | Returns the author hint array reference. | ||||||||||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||||||||||
| 219 | =head2 sz | ||||||||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||||||||
| 221 | Returns the optional byte size. | ||||||||||||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||||||||||||
| 223 | =head1 METHODS | ||||||||||||||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||||||||||||||
| 225 | =head2 to_string | ||||||||||||||||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||||||||||||||||
| 227 | my $value = $uri->to_string; | ||||||||||||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||||||||||||
| 229 | Returns the C<blossom:> URI string. Query parameters are emitted in C<xs>, | ||||||||||||||||||||||||||||||||||||||||||
| 230 | C<as>, then C<sz> order. | ||||||||||||||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||||||||||||
| 232 | =head1 INTERNAL METHODS | ||||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||||
| 234 | =head2 BUILDARGS | ||||||||||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||||||||||
| 236 | Normalizes constructor arguments for Class::Tiny. | ||||||||||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||||||||||
| 238 | =head2 BUILD | ||||||||||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||||||||||
| 240 | Validates the constructed object for Class::Tiny. | ||||||||||||||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||||||||||||||
| 242 | =cut | ||||||||||||||||||||||||||||||||||||||||||