]> Sergey Matveev's repositories - public-inbox.git/blob - lib/PublicInbox/AltId.pm
add filter for RubyLang lists
[public-inbox.git] / lib / PublicInbox / AltId.pm
1 # Copyright (C) 2016 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
3
4 package PublicInbox::AltId;
5 use strict;
6 use warnings;
7 use URI::Escape qw(uri_unescape);
8
9 # spec: TYPE:PREFIX:param1=value1&param2=value2&...
10 # Example: serial:gmane:file=/path/to/altmsgmap.sqlite3
11 sub new {
12         my ($class, $inbox, $spec, $writable) = @_;
13         my ($type, $prefix, $query) = split(/:/, $spec, 3);
14         $type eq 'serial' or die "non-serial not supported, yet\n";
15
16         require PublicInbox::Msgmap;
17
18         my %params = map {
19                 my ($k, $v) = split(/=/, uri_unescape($_), 2);
20                 $v = '' unless defined $v;
21                 ($k, $v);
22         } split(/[&;]/, $query);
23         my $f = $params{file} or die "file: required for $type spec $spec\n";
24         unless (index($f, '/') == 0) {
25                 $f = "$inbox->{mainrepo}/public-inbox/$f";
26         }
27         bless {
28                 mm_alt => PublicInbox::Msgmap->new_file($f, $writable),
29                 xprefix => 'X'.uc($prefix),
30         }, $class;
31 }
32
33 sub mid2alt {
34         my ($self, $mid) = @_;
35         $self->{mm_alt}->num_for($mid);
36 }
37
38 1;