]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/InboxWritable.pm
inboxwritable: drop {-importer} cyclic reference
[public-inbox.git] / lib / PublicInbox / InboxWritable.pm
index ab7b0ed5a7ba3fa82e62de4bcbe6704af70a0c3c..c73910acb30a754329bf5ce58e998a8775642b3f 100644 (file)
@@ -30,12 +30,19 @@ sub new {
        $self;
 }
 
+sub assert_usable_dir {
+       my ($self) = @_;
+       my $dir = $self->{inboxdir};
+       return $dir if defined($dir) && $dir ne '';
+       die "no inboxdir defined for $self->{name}\n";
+}
+
 sub init_inbox {
        my ($self, $shards, $skip_epoch, $skip_artnum) = @_;
        # TODO: honor skip_artnum
        my $v = $self->{version} || 1;
        if ($v == 1) {
-               my $dir = $self->{inboxdir} or die "no inboxdir in inbox\n";
+               my $dir = assert_usable_dir($self);
                PublicInbox::Import::init_bare($dir);
        } else {
                my $v2w = importer($self);
@@ -45,22 +52,20 @@ sub init_inbox {
 
 sub importer {
        my ($self, $parallel) = @_;
-       $self->{-importer} ||= do {
-               my $v = $self->{version} || 1;
-               if ($v == 2) {
-                       eval { require PublicInbox::V2Writable };
-                       die "v2 not supported: $@\n" if $@;
-                       my $opt = $self->{-creat_opt};
-                       my $v2w = PublicInbox::V2Writable->new($self, $opt);
-                       $v2w->{parallel} = $parallel;
-                       $v2w;
-               } elsif ($v == 1) {
-                       my @arg = (undef, undef, undef, $self);
-                       PublicInbox::Import->new(@arg);
-               } else {
-                       $! = 78; # EX_CONFIG 5.3.5 local configuration error
-                       die "unsupported inbox version: $v\n";
-               }
+       my $v = $self->{version} || 1;
+       if ($v == 2) {
+               eval { require PublicInbox::V2Writable };
+               die "v2 not supported: $@\n" if $@;
+               my $opt = $self->{-creat_opt};
+               my $v2w = PublicInbox::V2Writable->new($self, $opt);
+               $v2w->{parallel} = $parallel;
+               $v2w;
+       } elsif ($v == 1) {
+               my @arg = (undef, undef, undef, $self);
+               PublicInbox::Import->new(@arg);
+       } else {
+               $! = 78; # EX_CONFIG 5.3.5 local configuration error
+               die "unsupported inbox version: $v\n";
        }
 }