lib/PublicInbox/LEI.pm | 22 ++++++---------------- lib/PublicInbox/LeiConvert.pm | 6 +++--- lib/PublicInbox/LeiImport.pm | 6 +++--- lib/PublicInbox/LeiP2q.pm | 6 +++--- diff --git a/lib/PublicInbox/LEI.pm b/lib/PublicInbox/LEI.pm index bf97a6809ddb5a07fb266e531404255ac58743ad..b6d21af694f4488bdd1619c18c3084854b5245dd 100644 --- a/lib/PublicInbox/LEI.pm +++ b/lib/PublicInbox/LEI.pm @@ -598,7 +598,12 @@ $cmd = shift(@argv) // return _help($self, 'no command given'); } 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) { @@ -683,21 +688,6 @@ $self->{opt}->{'config-file'} and return fail $self, "config file switches not supported by `lei config'"; _config(@_); x_it($self, $?) if $?; -} - -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 { diff --git a/lib/PublicInbox/LeiConvert.pm b/lib/PublicInbox/LeiConvert.pm index fcc67f0bfe25ea3d2b72fee28e593cb1a3da3a6d..8d3b221a6eb9077869e812eee5cc84e2735b0240 100644 --- a/lib/PublicInbox/LeiConvert.pm +++ b/lib/PublicInbox/LeiConvert.pm @@ -77,11 +77,11 @@ delete $lei->{1}; 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 $self = $lei->{cnv} = bless {}, $cls; + my $self = $lei->{cnv} = bless {}, __PACKAGE__; my $in_fmt = $opt->{'in-format'}; my (@f, @d); $opt->{dedupe} //= 'none'; diff --git a/lib/PublicInbox/LeiImport.pm b/lib/PublicInbox/LeiImport.pm index ae24a1fa3a61dda651a1c5fdb82538bf654ded46..0e2a96e84a478ef8ab92aad33c2103b8696bcdc1 100644 --- a/lib/PublicInbox/LeiImport.pm +++ b/lib/PublicInbox/LeiImport.pm @@ -63,13 +63,13 @@ net_merge_complete($self) unless $lei->{auth}; 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 $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; diff --git a/lib/PublicInbox/LeiP2q.pm b/lib/PublicInbox/LeiP2q.pm index c5718603c672b158934fc6067c8717f6e93423ab..302d786492368c65f2c6f8cce5b09551e79820e4 100644 --- a/lib/PublicInbox/LeiP2q.pm +++ b/lib/PublicInbox/LeiP2q.pm @@ -174,9 +174,9 @@ } $lei->out(@q, "\n"); } -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 {