[git/perl] unusual syntax?

4 messages, 4 authors, 2016-06-15 · open the first message on its own page

[git/perl] unusual syntax?

From: Ray Chuan <hidden>
Date: 2016-06-15 22:45:06

Hi,

i noticed that this doesn't work for me (Perl 5.10):

sub _close_hash_and_insert_object {
	my ($self) = @_;

	return unless defined($self->{hash_object_pid});

	my @vars = map { 'hash_object_' . $_ } qw(pid in out ctx);

	command_close_bidi_pipe($self->{@vars});
	delete $self->{@vars};
}


$self->{@vars} evaluates to undef. i can't find any mention of using
arrays to dereference objects in the manual and elsewhere; is this a
mistake?

-- 
Cheers,
Ray Chuan

[PATCH] Fix hash slice syntax error

From: Abhijit Menon-Sen <hidden>
Date: 2016-06-15 22:45:06

Signed-off-by: Abhijit Menon-Sen <redacted>
---

At 2008-08-04 12:49:27 +0800, rctay89@gmail.com wrote:
$self->{@vars} evaluates to undef. i can't find any mention of using
arrays to dereference objects in the manual and elsewhere; is this a
mistake?
Yes, @vars would be interpreted in scalar context, which certainly isn't
the intended effect.

-- ams

 perl/Git.pm |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/perl/Git.pm b/perl/Git.pm
index 087d3d0..2ef437f 100644
--- a/perl/Git.pm
+++ b/perl/Git.pm
@@ -839,8 +839,8 @@ sub _close_hash_and_insert_object {
 
 	my @vars = map { 'hash_object_' . $_ } qw(pid in out ctx);
 
-	command_close_bidi_pipe($self->{@vars});
-	delete $self->{@vars};
+	command_close_bidi_pipe(@$self{@vars});
+	delete @$self{@vars};
 }
 
 =item cat_blob ( SHA1, FILEHANDLE )
@@ -928,8 +928,8 @@ sub _close_cat_blob {
 
 	my @vars = map { 'cat_blob_' . $_ } qw(pid in out ctx);
 
-	command_close_bidi_pipe($self->{@vars});
-	delete $self->{@vars};
+	command_close_bidi_pipe(@$self{@vars});
+	delete @$self{@vars};
 }
 
 =back
-- 
1.6.0.rc0.43.g2aa74

[PATCH] Git.pm: Fix internal git_command_bidi_pipe() users

From: Petr Baudis <hidden>
Date: 2016-06-15 22:45:06

The hash_and_insert_object() and cat_blob() helpers were using
an incorrect slice-from-ref Perl syntax. This patch fixes that up
in the _close_*() helpers and make the _open_*() helpers use the
same syntax for consistnecy.

Signed-off-by: Petr Baudis <redacted>
---

  Wow, the command_bidi_pipe API really is dirty. Of course, it is
my fault as anyone's since I didn't get around to review the patches
introducing it.

 perl/Git.pm |   16 ++++++----------
 1 files changed, 6 insertions(+), 10 deletions(-)
diff --git a/perl/Git.pm b/perl/Git.pm
index 087d3d0..0624428 100644
--- a/perl/Git.pm
+++ b/perl/Git.pm
@@ -827,8 +827,7 @@ sub _open_hash_and_insert_object_if_needed {
 
 	return if defined($self->{hash_object_pid});
 
-	($self->{hash_object_pid}, $self->{hash_object_in},
-	 $self->{hash_object_out}, $self->{hash_object_ctx}) =
+	@$self{map { "hash_object_$_" } qw(pid in out ctx)} =
 		command_bidi_pipe(qw(hash-object -w --stdin-paths));
 }
 
@@ -837,9 +836,8 @@ sub _close_hash_and_insert_object {
 
 	return unless defined($self->{hash_object_pid});
 
-	my @vars = map { 'hash_object_' . $_ } qw(pid in out ctx);
-
-	command_close_bidi_pipe($self->{@vars});
+	my @vars = map { "hash_object_$_" } qw(pid in out ctx);
+	command_close_bidi_pipe(@$self{@vars});
 	delete $self->{@vars};
 }
 
@@ -916,8 +914,7 @@ sub _open_cat_blob_if_needed {
 
 	return if defined($self->{cat_blob_pid});
 
-	($self->{cat_blob_pid}, $self->{cat_blob_in},
-	 $self->{cat_blob_out}, $self->{cat_blob_ctx}) =
+	@$self{map { "cat_blob_$_" } qw(pid in out ctx)} =
 		command_bidi_pipe(qw(cat-file --batch));
 }
 
@@ -926,9 +923,8 @@ sub _close_cat_blob {
 
 	return unless defined($self->{cat_blob_pid});
 
-	my @vars = map { 'cat_blob_' . $_ } qw(pid in out ctx);
-
-	command_close_bidi_pipe($self->{@vars});
+	my @vars = map { "cat_blob_$_" } qw(pid in out ctx);
+	command_close_bidi_pipe(@$self{@vars});
 	delete $self->{@vars};
 }
 

Re: [git/perl] unusual syntax?

From: David Christensen <hidden>
Date: 2016-06-15 22:45:06

sub _close_hash_and_insert_object {
	my ($self) = @_;

	return unless defined($self->{hash_object_pid});

	my @vars = map { 'hash_object_' . $_ } qw(pid in out ctx);

	command_close_bidi_pipe($self->{@vars});
	delete $self->{@vars};
}
$self->{@vars} evaluates to undef. i can't find any mention of using
arrays to dereference objects in the manual and elsewhere; is this a
mistake?

This is a hash slice notation, returning an array of hash values  
matching the corresponding keys.  5.10 removed some syntax warts in  
the case of hash slices; this is more portably expressed as @{$self} 
{@vars}; this should work in 5.10 and earlier versions, and so is the  
preferred syntax.

Regards,

David
--
David Christensen
End Point Corporation
david@endpoint.com
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help