This makes it slightly easier to implement future commands,
since there'll be a couple more relatively self-contained
ones.
}
my $func = "lei_$cmd";
$func =~ tr/-/_/;
}
my $func = "lei_$cmd";
$func =~ tr/-/_/;
- if (my $cb = __PACKAGE__->can($func)) {
+ my $cb = __PACKAGE__->can($func) // ($CMD{$cmd} ? do {
+ my $mod = "PublicInbox::Lei\u$cmd";
+ ($INC{"PublicInbox/Lei\u$cmd.pm"} //
+ eval("require $mod")) ? $mod->can($func) : undef;
+ } : undef);
+ if ($cb) {
optparse($self, $cmd, \@argv) or return;
if (my $chdir = $self->{opt}->{C}) {
for my $d (@$chdir) {
optparse($self, $cmd, \@argv) or return;
if (my $chdir = $self->{opt}->{C}) {
for my $d (@$chdir) {
-sub lei_import {
- require PublicInbox::LeiImport;
- PublicInbox::LeiImport->call(@_);
-}
-
-sub lei_convert {
- require PublicInbox::LeiConvert;
- PublicInbox::LeiConvert->call(@_);
-}
-
-sub lei_p2q {
- require PublicInbox::LeiP2q;
- PublicInbox::LeiP2q->call(@_);
-}
-
sub lei_init {
my ($self, $dir) = @_;
my $cfg = _lei_cfg($self, 1);
sub lei_init {
my ($self, $dir) = @_;
my $cfg = _lei_cfg($self, 1);
delete $self->{wcb}; # commit
}
delete $self->{wcb}; # commit
}
-sub call { # the main "lei convert" method
- my ($cls, $lei, @inputs) = @_;
+sub lei_convert { # the main "lei convert" method
+ my ($lei, @inputs) = @_;
my $opt = $lei->{opt};
$opt->{kw} //= 1;
my $opt = $lei->{opt};
$opt->{kw} //= 1;
- my $self = $lei->{cnv} = bless {}, $cls;
+ my $self = $lei->{cnv} = bless {}, __PACKAGE__;
my $in_fmt = $opt->{'in-format'};
my (@f, @d);
$opt->{dedupe} //= 'none';
my $in_fmt = $opt->{'in-format'};
my (@f, @d);
$opt->{dedupe} //= 'none';
while ($op && $op->{sock}) { $op->event_step }
}
while ($op && $op->{sock}) { $op->event_step }
}
-sub call { # the main "lei import" method
- my ($cls, $lei, @inputs) = @_;
+sub lei_import { # the main "lei import" method
+ my ($lei, @inputs) = @_;
my $sto = $lei->_lei_store(1);
$sto->write_prepare($lei);
my ($net, @f, @d);
$lei->{opt}->{kw} //= 1;
my $sto = $lei->_lei_store(1);
$sto->write_prepare($lei);
my ($net, @f, @d);
$lei->{opt}->{kw} //= 1;
- my $self = $lei->{imp} = bless { inputs => \@inputs }, $cls;
+ my $self = $lei->{imp} = bless { inputs => \@inputs }, __PACKAGE__;
if ($lei->{opt}->{stdin}) {
@inputs and return $lei->fail("--stdin and @inputs do not mix");
$lei->check_input_format or return;
if ($lei->{opt}->{stdin}) {
@inputs and return $lei->fail("--stdin and @inputs do not mix");
$lei->check_input_format or return;
-sub call { # the "lei patch-to-query" entry point
- my ($cls, $lei, $input) = @_;
- my $self = $lei->{p2q} = bless {}, $cls;
+sub lei_p2q { # the "lei patch-to-query" entry point
+ my ($lei, $input) = @_;
+ my $self = $lei->{p2q} = bless {}, __PACKAGE__;
if ($lei->{opt}->{stdin}) {
$self->{0} = delete $lei->{0}; # guard from lei_atfork_child
} else {
if ($lei->{opt}->{stdin}) {
$self->{0} = delete $lei->{0}; # guard from lei_atfork_child
} else {