All of lore.kernel.org
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Christian Jaeger <christian@jaeger.mine.nu>
Cc: git@vger.kernel.org, Petr Baudis <pasky@suse.cz>
Subject: Re: [PATCH] Git.pm: do not break inheritance
Date: Sat, 18 Oct 2008 13:50:30 -0700	[thread overview]
Message-ID: <7vabd1aaqx.fsf@gitster.siamese.dyndns.org> (raw)
In-Reply-To: <2980b5cead38d5ae3510e4ed9adc847c80be1075.1224360106.git.christian@jaeger.mine.nu> (Christian Jaeger's message of "Sat, 18 Oct 2008 20:25:12 +0200")

Christian Jaeger <christian@jaeger.mine.nu> writes:

> Make it possible to write subclasses of Git.pm
>
> Signed-off-by: Christian Jaeger <christian@jaeger.mine.nu>
> ---
>
>  I don't really know what the reason for the _maybe_self behaviour
>  was; I'm hoping this fix doesn't break anything,

That's how you would write class methods, isn't it?  IOW, your callers
can say:

	my $self = new Git();
        $self->method(qw(a b c));
        Git::method(qw(a b c))

and you can start your method like this:

	sub method {
        	my ($self, @args) = _maybe_self(@_)
                ...
	}

and use @args the same way for either form of the call in the
implementation.  Two obvious pitfalls are:

 - You cannot use $self if you set up your parameters with _maybe_self;

 - The second form of the call would call directly into Git::method, never
   your subclasses implementation, even if you write:

	use Git;
        package CJGit;
        our @ISA = qw(Git);

        sub method {
        	...
	}

>  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.

The patch looks Ok, as long as you have a working UNIVERSAL::isa() in your
version of Perl.  My reading of perl561delta,pod says that Perl 5.6.1 and
later should have a working implementation.

  reply	other threads:[~2008-10-18 20:52 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-10-18 18:25 [PATCH] Git.pm: do not break inheritance Christian Jaeger
2008-10-18 20:50 ` Junio C Hamano [this message]
2008-10-18 22:21   ` Christian Jaeger

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=7vabd1aaqx.fsf@gitster.siamese.dyndns.org \
    --to=gitster@pobox.com \
    --cc=christian@jaeger.mine.nu \
    --cc=git@vger.kernel.org \
    --cc=pasky@suse.cz \
    /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.