From: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
To: git@vger.kernel.org
Cc: "Junio C Hamano" <gitster@pobox.com>,
"Matthieu Moy" <git@matthieu-moy.fr>,
"Petr Baudis" <pasky@ucw.cz>, "Benoit Bourbie" <bbourbie@slb.com>,
"Jeff King" <peff@peff.net>,
"Johannes Schindelin" <Johannes.Schindelin@gmx.de>,
"Jari Aalto" <jari.aalto@cante.net>,
"Giuseppe Bilotta" <giuseppe.bilotta@gmail.com>,
"Marcus Griep" <marcus@griep.us>,
"Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Subject: [PATCH 3/8] perl: generalize the Git::LoadCPAN facility
Date: Wed, 14 Feb 2018 22:21:41 +0000 [thread overview]
Message-ID: <20180214222146.10655-4-avarab@gmail.com> (raw)
In-Reply-To: <20180214222146.10655-1-avarab@gmail.com>
Change the two wrappers to load from CPAN (local OS) or our own copy
to do so via the same codepath.
I added the Error.pm wrapper in 20d2a30f8f ("Makefile: replace
perl/Makefile.PL with simple make rules", 2017-12-10), and shortly
afterwards Matthieu Moy added a wrapper for Mail::Address in
bd869f67b9 ("send-email: add and use a local copy of Mail::Address",
2018-01-05).
His was simpler since Mail::Address doesn't have an "import" method,
but didn't do the same sanity checking, e.g. a missing FromCPAN
directory (which OS packages are likely not to have) wouldn't be
explicitly warned about.
Now both use a modification of the previously Error.pm-specific
codepath, which has been amended to take the module to load as
parameter, as well as whether or not that module has an import method.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
perl/Git/LoadCPAN.pm | 74 +++++++++++++++++++++++++++++++++++++++
perl/Git/LoadCPAN/Error.pm | 44 +++--------------------
perl/Git/LoadCPAN/Mail/Address.pm | 22 +++---------
3 files changed, 82 insertions(+), 58 deletions(-)
create mode 100644 perl/Git/LoadCPAN.pm
diff --git a/perl/Git/LoadCPAN.pm b/perl/Git/LoadCPAN.pm
new file mode 100644
index 0000000000..2262812654
--- /dev/null
+++ b/perl/Git/LoadCPAN.pm
@@ -0,0 +1,74 @@
+package Git::LoadCPAN;
+use 5.008;
+use strict;
+use warnings;
+
+=head1 NAME
+
+Git::LoadCPAN - Wrapper for loading modules from the CPAN (OS) or Git's own copy
+
+=head1 DESCRIPTION
+
+The Perl code in Git depends on some modules from the CPAN, but we
+don't want to make those a hard requirement for anyone building from
+source.
+
+Therefore the L<Git::LoadCPAN> namespace shipped with Git contains
+wrapper modules like C<Git::LoadCPAN::Module::Name> that will first
+attempt to load C<Module::Name> from the OS, and if that doesn't work
+will fall back on C<Git::FromCPAN::Module::Name> shipped with Git
+itself.
+
+Usually OS's will not ship with Git's Git::FromCPAN tree at all,
+preferring to use their own packaging of CPAN modules instead.
+
+This module is only intended to be used for code shipping in the
+C<git.git> repository. Use it for anything else at your peril!
+
+=cut
+
+sub import {
+ shift;
+ my $caller = caller;
+ my %args = @_;
+ my $module = exists $args{module} ? delete $args{module} : die "BUG: Expected 'module' parameter!";
+ my $import = exists $args{import} ? delete $args{import} : die "BUG: Expected 'import' parameter!";
+ die "BUG: Too many arguments!" if keys %args;
+
+ # Foo::Bar to Foo/Bar.pm
+ my $package_pm = $module;
+ $package_pm =~ s[::][/]g;
+ $package_pm .= '.pm';
+
+ eval {
+ require $package_pm;
+ 1;
+ } or do {
+ my $error = $@ || "Zombie Error";
+
+ my $Git_LoadCPAN_pm_path = $INC{"Git/LoadCPAN.pm"} || die "BUG: Should have our own path from %INC!";
+
+ require File::Basename;
+ my $Git_LoadCPAN_pm_root = File::Basename::dirname($Git_LoadCPAN_pm_path) || die "BUG: Can't figure out lib/Git dirname from '$Git_LoadCPAN_pm_path'!";
+
+ require File::Spec;
+ my $Git_pm_FromCPAN_root = File::Spec->catdir($Git_LoadCPAN_pm_root, 'FromCPAN');
+ die "BUG: '$Git_pm_FromCPAN_root' should be a directory!" unless -d $Git_pm_FromCPAN_root;
+
+ local @INC = ($Git_pm_FromCPAN_root, @INC);
+ require $package_pm;
+ };
+
+ if ($import) {
+ no strict 'refs';
+ *{"${caller}::import"}= sub {
+ shift;
+ use strict 'refs';
+ unshift @_, $module;
+ goto &{"${module}::import"};
+ };
+ use strict 'refs';
+ }
+}
+
+1;
diff --git a/perl/Git/LoadCPAN/Error.pm b/perl/Git/LoadCPAN/Error.pm
index 3513fe745b..9ba53cccf2 100644
--- a/perl/Git/LoadCPAN/Error.pm
+++ b/perl/Git/LoadCPAN/Error.pm
@@ -2,45 +2,9 @@ package Git::LoadCPAN::Error;
use 5.008;
use strict;
use warnings;
-
-=head1 NAME
-
-Git::LoadCPAN::Error - Wrapper for the L<Error> module, in case it's not installed
-
-=head1 DESCRIPTION
-
-Wraps the import function for the L<Error> module.
-
-This module is only intended to be used for code shipping in the
-C<git.git> repository. Use it for anything else at your peril!
-
-=cut
-
-sub import {
- shift;
- my $caller = caller;
-
- eval {
- require Error;
- 1;
- } or do {
- my $error = $@ || "Zombie Error";
-
- my $Git_Error_pm_path = $INC{"Git/LoadCPAN/Error.pm"} || die "BUG: Should have our own path from %INC!";
-
- require File::Basename;
- my $Git_Error_pm_root = File::Basename::dirname($Git_Error_pm_path) || die "BUG: Can't figure out lib/Git dirname from '$Git_Error_pm_path'!";
-
- require File::Spec;
- my $Git_pm_FromCPAN_root = File::Spec->catdir($Git_Error_pm_root, '..', 'FromCPAN');
- die "BUG: '$Git_pm_FromCPAN_root' should be a directory!" unless -d $Git_pm_FromCPAN_root;
-
- local @INC = ($Git_pm_FromCPAN_root, @INC);
- require Error;
- };
-
- unshift @_, $caller;
- goto &Error::import;
-}
+use Git::LoadCPAN (
+ module => 'Error',
+ import => 1,
+);
1;
diff --git a/perl/Git/LoadCPAN/Mail/Address.pm b/perl/Git/LoadCPAN/Mail/Address.pm
index 879c2f5cd1..a13f0e58cf 100644
--- a/perl/Git/LoadCPAN/Mail/Address.pm
+++ b/perl/Git/LoadCPAN/Mail/Address.pm
@@ -2,23 +2,9 @@ package Git::LoadCPAN::Mail::Address;
use 5.008;
use strict;
use warnings;
-
-=head1 NAME
-
-Git::LoadCPAN::Mail::Address - Wrapper for the L<Mail::Address> module, in case it's not installed
-
-=head1 DESCRIPTION
-
-This module is only intended to be used for code shipping in the
-C<git.git> repository. Use it for anything else at your peril!
-
-=cut
-
-eval {
- require Mail::Address;
- 1;
-} or do {
- require Git::FromCPAN::Mail::Address;
-};
+use Git::LoadCPAN (
+ module => 'Mail::Address',
+ import => 0,
+);
1;
--
2.15.1.424.g9478a66081
next prev parent reply other threads:[~2018-02-14 22:22 UTC|newest]
Thread overview: 66+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-02-14 22:21 [PATCH 0/8] various perl fixes Ævar Arnfjörð Bjarmason
2018-02-14 22:21 ` [PATCH 1/8] perl: *.pm files should not have the executable bit Ævar Arnfjörð Bjarmason
2018-02-14 22:41 ` Jonathan Nieder
2018-02-25 19:01 ` Ævar Arnfjörð Bjarmason
2018-02-14 22:21 ` [PATCH 2/8] perl: move CPAN loader wrappers to another namespace Ævar Arnfjörð Bjarmason
2018-02-14 22:43 ` Jonathan Nieder
2018-02-14 22:21 ` Ævar Arnfjörð Bjarmason [this message]
2018-02-14 22:57 ` [PATCH 3/8] perl: generalize the Git::LoadCPAN facility Jonathan Nieder
2018-02-15 5:09 ` Todd Zullinger
2018-02-25 18:56 ` Ævar Arnfjörð Bjarmason
2018-02-25 19:05 ` Randall S. Becker
2018-02-15 4:53 ` Todd Zullinger
2018-02-15 20:41 ` Ævar Arnfjörð Bjarmason
2018-02-15 21:23 ` Todd Zullinger
2018-02-16 14:39 ` Ævar Arnfjörð Bjarmason
2018-02-16 17:55 ` Todd Zullinger
2018-02-16 22:03 ` Jonathan Nieder
2018-02-17 0:47 ` Todd Zullinger
2018-02-17 5:40 ` Todd Zullinger
2018-02-14 22:21 ` [PATCH 4/8] perl: update our ancient copy of Error.pm Ævar Arnfjörð Bjarmason
2018-02-14 23:03 ` Jonathan Nieder
2018-02-15 20:46 ` Ævar Arnfjörð Bjarmason
2018-02-14 22:21 ` [PATCH 5/8] perl: update our copy of Mail::Address Ævar Arnfjörð Bjarmason
2018-02-14 23:46 ` Jonathan Nieder
2018-02-15 9:32 ` Matthieu Moy
2018-02-15 20:31 ` Ævar Arnfjörð Bjarmason
2018-02-14 22:21 ` [PATCH 6/8] git-send-email: unconditionally use Net::{SMTP,Domain} Ævar Arnfjörð Bjarmason
2018-02-14 23:49 ` Jonathan Nieder
2018-02-15 20:43 ` Ævar Arnfjörð Bjarmason
2018-02-14 22:21 ` [PATCH 7/8] gitweb: hard-depend on the Digest::MD5 5.8 module Ævar Arnfjörð Bjarmason
2018-02-14 23:52 ` Jonathan Nieder
2018-02-14 22:21 ` [PATCH 8/8] perl: hard-depend on the File::{Temp,Spec} modules Ævar Arnfjörð Bjarmason
2018-02-14 23:54 ` Jonathan Nieder
2018-02-15 20:42 ` Ævar Arnfjörð Bjarmason
2018-02-15 21:33 ` Junio C Hamano
2018-02-25 19:46 ` [PATCH v2 00/13] various perl fixes Ævar Arnfjörð Bjarmason
2018-03-03 15:38 ` [PATCH v3 " Ævar Arnfjörð Bjarmason
2018-03-05 19:01 ` Junio C Hamano
2018-03-03 15:38 ` [PATCH v3 01/13] perl: *.pm files should not have the executable bit Ævar Arnfjörð Bjarmason
2018-03-03 15:38 ` [PATCH v3 02/13] Git.pm: remove redundant "use strict" from sub-package Ævar Arnfjörð Bjarmason
2018-03-03 15:38 ` [PATCH v3 03/13] Git.pm: add the "use warnings" pragma Ævar Arnfjörð Bjarmason
2018-03-03 15:38 ` [PATCH v3 04/13] gitweb: hard-depend on the Digest::MD5 5.8 module Ævar Arnfjörð Bjarmason
2018-03-03 15:38 ` [PATCH v3 05/13] Git.pm: hard-depend on the File::{Temp,Spec} modules Ævar Arnfjörð Bjarmason
2018-03-03 15:38 ` [PATCH v3 06/13] git-send-email: unconditionally use Net::{SMTP,Domain} Ævar Arnfjörð Bjarmason
2018-03-03 15:38 ` [PATCH v3 07/13] perl: update our ancient copy of Error.pm Ævar Arnfjörð Bjarmason
2018-03-03 15:38 ` [PATCH v3 08/13] perl: update our copy of Mail::Address Ævar Arnfjörð Bjarmason
2018-03-03 15:38 ` [PATCH v3 09/13] perl: move CPAN loader wrappers to another namespace Ævar Arnfjörð Bjarmason
2018-03-03 15:38 ` [PATCH v3 10/13] perl: generalize the Git::LoadCPAN facility Ævar Arnfjörð Bjarmason
2018-03-03 15:38 ` [PATCH v3 11/13] perl: move the perl/Git/FromCPAN tree to perl/FromCPAN Ævar Arnfjörð Bjarmason
2018-03-03 15:38 ` [PATCH v3 12/13] Makefile: add NO_PERL_CPAN_FALLBACKS knob Ævar Arnfjörð Bjarmason
2018-03-03 15:38 ` [PATCH v3 13/13] perl Git::LoadCPAN: emit better errors under NO_PERL_CPAN_FALLBACKS Ævar Arnfjörð Bjarmason
2018-02-25 19:46 ` [PATCH v2 01/13] perl: *.pm files should not have the executable bit Ævar Arnfjörð Bjarmason
2018-02-25 19:46 ` [PATCH v2 02/13] Git.pm: remove redundant "use strict" from sub-package Ævar Arnfjörð Bjarmason
2018-02-25 19:46 ` [PATCH v2 03/13] Git.pm: add the "use warnings" pragma Ævar Arnfjörð Bjarmason
2018-02-25 19:46 ` [PATCH v2 04/13] gitweb: hard-depend on the Digest::MD5 5.8 module Ævar Arnfjörð Bjarmason
2018-02-25 20:00 ` Eric Sunshine
2018-02-25 19:46 ` [PATCH v2 05/13] Git.pm: hard-depend on the File::{Temp,Spec} modules Ævar Arnfjörð Bjarmason
2018-02-25 19:46 ` [PATCH v2 06/13] git-send-email: unconditionally use Net::{SMTP,Domain} Ævar Arnfjörð Bjarmason
2018-02-25 20:03 ` Eric Sunshine
2018-02-25 19:46 ` [PATCH v2 07/13] perl: update our ancient copy of Error.pm Ævar Arnfjörð Bjarmason
2018-02-25 19:46 ` [PATCH v2 08/13] perl: update our copy of Mail::Address Ævar Arnfjörð Bjarmason
2018-02-25 19:46 ` [PATCH v2 09/13] perl: move CPAN loader wrappers to another namespace Ævar Arnfjörð Bjarmason
2018-02-25 19:46 ` [PATCH v2 10/13] perl: generalize the Git::LoadCPAN facility Ævar Arnfjörð Bjarmason
2018-02-25 19:46 ` [PATCH v2 11/13] perl: move the perl/Git/FromCPAN tree to perl/FromCPAN Ævar Arnfjörð Bjarmason
2018-02-25 19:46 ` [PATCH v2 12/13] Makefile: add NO_PERL_CPAN_FALLBACKS knob Ævar Arnfjörð Bjarmason
2018-02-25 19:46 ` [PATCH v2 13/13] perl Git::LoadCPAN: emit better errors under NO_PERL_CPAN_FALLBACKS Ævar Arnfjörð Bjarmason
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180214222146.10655-4-avarab@gmail.com \
--to=avarab@gmail.com \
--cc=Johannes.Schindelin@gmx.de \
--cc=bbourbie@slb.com \
--cc=git@matthieu-moy.fr \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=giuseppe.bilotta@gmail.com \
--cc=jari.aalto@cante.net \
--cc=marcus@griep.us \
--cc=pasky@ucw.cz \
--cc=peff@peff.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.