DORMANTno replies

[PATCH] Git.pm: do not break inheritance

From: Christian Jaeger <hidden>
Date: 2016-06-15 22:45:30
Subsystem: the rest · Maintainer: Linus Torvalds

Make it possible to write subclasses of Git.pm

Signed-off-by: Christian Jaeger <redacted>
---

 I don't really know what the reason for the _maybe_self behaviour
 was; I'm hoping this fix doesn't break anything, I haven't run any
 tests with it except with my own code; the fix works on the
 assumptions that if an object does indeed have Git.pm in it's
 ancestry, _maybe_self should work just as if the object is a 'Git'
 object without inheritance.

 I'm currently using the following hack to make my scripts be able to
 inherit from a non-patched Git.pm: I inherit instead from a wrapper
 around Git.pm which inherits from and patches the latter at runtime
 using this code:

 if (do {
     my @res= Git::_maybe_self ( (bless {}, __PACKAGE__) );
     not $res[0]
 }) {
     #warn "patching Git.pm";#
     no warnings;
     *Git::_maybe_self= sub {
	 UNIVERSAL::isa($_[0], 'Git') ? @_ : (undef, @_);
     }
 }

 While this currently works, a proper fix would of course be
 preferable (like: when in the future will the above hack break?..).


 perl/Git.pm |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)
diff --git a/perl/Git.pm b/perl/Git.pm
index 6aab712..ba94453 100644
--- a/perl/Git.pm
+++ b/perl/Git.pm
@@ -1203,8 +1203,7 @@ either version 2, or (at your option) any later version.
 # the method was called upon an instance and (undef, @args) if
 # it was called directly.
 sub _maybe_self {
-	# This breaks inheritance. Oh well.
-	ref $_[0] eq 'Git' ? @_ : (undef, @_);
+	UNIVERSAL::isa($_[0], 'Git') ? @_ : (undef, @_);
 }
 
 # Check if the command id is something reasonable.
-- 
1.6.0.2
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help