public-inbox.git  about / heads / tags
an "archives first" approach to mailing lists
blob 6a560d48f3243e1342ec9d9ed9d320702b53b7c4 1065 bytes (raw)
$ git show repobrowse:lib/PublicInbox/RepoGitQuery.pm	# shows this blob on the CLI

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
 
# Copyright (C) 2015 all contributors <meta@public-inbox.org>
# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>

# query parameter management for repobrowse
package PublicInbox::RepoGitQuery;
use strict;
use warnings;
use PublicInbox::Hval;
use URI::Escape qw(uri_unescape);
my @KNOWN_PARAMS = qw(ofs);

sub new {
	my ($class, $env) = @_;
	# we don't care about multi-value
	my %tmp = map {
		my ($k, $v) = split('=', uri_unescape($_), 2);
		$v = '' unless defined $v;
		$v =~ tr/+/ /;
		($k, $v)
	} split(/[&;]/, $env->{QUERY_STRING});

	my $self = {};
	foreach (@KNOWN_PARAMS) {
		my $v = $tmp{$_};
		$self->{$_} = defined $v ? $v : '';
	}
	bless $self, $class;
}

sub qs {
	my ($self, %over) = @_;

	if (keys %over) {
		my $tmp = bless { %$self }, ref($self);
		foreach my $k (keys %over) { $tmp->{$k} = $over{$k}; }
		$self = $tmp;
	}

	my @qs;
	foreach my $k (@KNOWN_PARAMS) {
		my $v = $self->{$k};

		next if ($v eq '');
		$v = PublicInbox::Hval->new($v)->as_href;
		push @qs, "$k=$v";
	}
	scalar(@qs) ? ('?' . join('&amp;', @qs)) : '';
}

1;

git clone https://public-inbox.org/public-inbox.git
git clone http://7fh6tueqddpjyxjmgtdiueylzoqt6pt7hec3pukyptlmohoowvhde4yd.onion/public-inbox.git