Why is code in Net::SSL dereferencing typeglobs where I can't see the need?

111 Views Asked by At

Net::SSL is part of Crypt::SSLeay. While working on a bug report today, I was distracted by how many times the poor old * made an appearance.

For example, consider Net::SSL::configure:

*$self->{ssl_version} = $ssl_version;
*$self->{ssl_debug} = $ssl_debug;
*$self->{ssl_arg} = $arg;
*$self->{ssl_peer_addr} = $arg->{PeerAddr};
*$self->{ssl_peer_port} = $arg->{PeerPort};

Maybe it's because I am not that familiar with pre 5.8 Perl, but I just can't pinpoint whether there is a significant reason for using * on the LHS. Wouldn't just *$self->{ssl_peer_port} = $arg->{PeerPort}; be sufficient? Or, is there something deep going on here (e.g. local $_ versus local *_)?

2

There are 2 best solutions below

2
On BEST ANSWER

I don’t have the module installed, so can’t check easily enough, but I presume that it’s because the object is a globref; that is, a reference to a blessed typeglob.

There’s no aliasing going on here. When you write

 *$self->{ssl_debug} = $ssl_debug;

It first derefs the globref back to a full typeglob. It then grabs just the hashref aspect of the typeglob and proceeds to dereference that.

This isn’t a pre- or post-5.8 thing.

What was it you were thinking it was doing?

0
On

tchrist is (as always) on the right track. You can play around with IO::Socket and see what you can and can't do with references to blessed typeglobs.

use IO::Socket;
$foo = IO::Socket->new;

print $foo;                      # IO::Socket=GLOB(0x20467b18)
print *$foo;                     # *Symbol::GEN0
print ref($foo);                 # IO::Socket
print ref(*$foo);                # ""

*$foo->{key} = value;            # ok
$$foo->{key} = value;            # ok
$foo->{key} = value;             # Not a HASH reference at ...