From 70207d974c5a965ef849b58c27b63fd644b3293e Mon Sep 17 00:00:00 2001 From: "Eric Wong (Contractor, The Linux Foundation)" Date: Mon, 19 Mar 2018 20:49:30 +0000 Subject: introduce InboxWritable class This code will be shared with future mass-import tools. --- lib/PublicInbox/InboxWritable.pm | 57 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 lib/PublicInbox/InboxWritable.pm (limited to 'lib/PublicInbox/InboxWritable.pm') diff --git a/lib/PublicInbox/InboxWritable.pm b/lib/PublicInbox/InboxWritable.pm new file mode 100644 index 00000000..0a976ea2 --- /dev/null +++ b/lib/PublicInbox/InboxWritable.pm @@ -0,0 +1,57 @@ +# Copyright (C) 2018 all contributors +# License: AGPL-3.0+ + +# Extends read-only Inbox for writing +package PublicInbox::InboxWritable; +use strict; +use warnings; +use base qw(PublicInbox::Inbox); +use PublicInbox::Import; + +sub new { + my ($class, $ibx) = @_; + bless $ibx, $class; +} + +sub importer { + my ($self, $parallel) = @_; + $self->{-importer} ||= eval { + my $v = $self->{version} || 1; + if ($v == 2) { + eval { require PublicInbox::V2Writable }; + die "v2 not supported: $@\n" if $@; + my $v2w = PublicInbox::V2Writable->new($self); + $v2w->{parallel} = $parallel; + $v2w; + } elsif ($v == 1) { + my $git = $self->git; + my $name = $self->{name}; + my $addr = $self->{-primary_address}; + PublicInbox::Import->new($git, $name, $addr, $self); + } else { + die "unsupported inbox version: $v\n"; + } + } +} + +sub filter { + my ($self) = @_; + my $f = $self->{filter}; + if ($f && $f =~ /::/) { + my @args = (-inbox => $self); + # basic line splitting, only + # Perhaps we can have proper quote splitting one day... + ($f, @args) = split(/\s+/, $f) if $f =~ /\s+/; + + eval "require $f"; + if ($@) { + warn $@; + } else { + # e.g: PublicInbox::Filter::Vger->new(@args) + return $f->new(@args); + } + } + undef; +} + +1; -- cgit v1.2.3-24-ge0c7