Search code examples
perltypeglob

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


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 *_)?


Solution

  • 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?