CDS
view release on metacpan or search on metacpan
$file .= $o->{defaultFile};
}
return $o->deliverFile($request, $file);
}
sub deliverFile {
my $o = shift;
my $request = shift;
my $file = shift;
my $contentType = shift // $o->guessContentType($file);
my $bytes = $o->readFile($file) // return $request->reply404;
return $request->reply(200, 'OK', {'Content-Type' => $contentType}, $bytes);
}
# Guesses the content type from the extension
sub guessContentType {
my $o = shift;
my $file = shift;
my $extension = $file =~ /\.([A-Za-z0-9]*)$/ ? lc($1) : '';
return $o->{mimeTypesByExtension}->{$extension} // 'application/octet-stream';
}
# Reads a file
sub readFile {
my $o = shift;
sub modify {
my $o = shift;
my $modifications = shift;
my $keyPair = shift; die 'wrong type '.ref($keyPair).' for $keyPair' if defined $keyPair && ref $keyPair ne 'CDS::KeyPair';
$o->{ui}->progress('MODIFY +', scalar @{$modifications->additions}, ' -', scalar @{$modifications->removals}, ' on ', $o->{url});
return $o->{store}->modify($modifications, $keyPair);
}
# Displays a record, and tries to guess the byte interpretation
package CDS::UI::Record;
sub display {
my $class = shift;
my $ui = shift;
my $record = shift; die 'wrong type '.ref($record).' for $record' if defined $record && ref $record ne 'CDS::Record';
my $storeUrl = shift;
my $o = bless {
ui => $ui,
$context eq 'p' ? $o->hexValue($bytes) :
$context eq 'q' ? $o->hexValue($bytes) :
$context eq 'encrypted for' ? $o->hexValue($bytes) :
$context eq 'updated by' ? $o->hexValue($bytes) :
$context =~ /(^| )id( |$)/ ? $o->hexValue($bytes) :
$context =~ /(^| )key( |$)/ ? $o->hexValue($bytes) :
$context =~ /(^| )signature( |$)/ ? $o->hexValue($bytes) :
$context =~ /(^| )revision( |$)/ ? $o->revisionValue($bytes) :
$context =~ /(^| )date( |$)/ ? $o->dateValue($bytes) :
$context =~ /(^| )expires( |$)/ ? $o->dateValue($bytes) :
$o->guessValue($bytes);
push @value, ' ', $o->{ui}->blue($hash->hex), $o->{onStore} if $hash && ($bytes && length $bytes != 32);
$o->{ui}->line(@value);
# Children
$o->{ui}->pushIndent;
for my $child (@children) { $o->record($child, $bytes); }
$o->{ui}->popIndent;
}
sub hexValue {
my $o = shift;
my $bytes = shift;
my $length = length $bytes;
return '#'.unpack('H*', substr($bytes, 0, $length)) if $length <= 64;
return '#'.unpack('H*', substr($bytes, 0, 64)), 'â¦', $o->{ui}->gray(' (', $length, ' bytes)');
}
sub guessValue {
my $o = shift;
my $bytes = shift;
my $length = length $bytes;
my $text = $length > 64 ? substr($bytes, 0, 64).'â¦' : $bytes;
$text =~ s/[\x00-\x1f\x7f-\xff]/·/g;
my @value = ($text);
if ($length <= 8) {
my $integer = CDS->integerFromBytes($bytes);
( run in 2.574 seconds using v1.01-cache-2.11-cpan-748bfb374f4 )