Why is the code in Net :: SSL dereferencing globs types where I don't see the need?

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

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 because I am not familiar with pre 5.8 Perl, but I just can’t determine if there is a significant reason for using * in LHS. It would not be simple enough *$self->{ssl_peer_port} = $arg->{PeerPort}; ? Or is there something deep here (like local $_ compared to local *_ )?

+4
source share
2 answers

I do not have a module installed, so I can not check it easily enough, but I assume that this is because the object is globref; that is, a link to the blissful type glob.

There are no aliases here. When you write

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

First, it returns globref back to the full glob type. Then it captures only the hash aspect of type glob and proceeds to dereference it.

This is not a pre-or post-5.8 thing.

What did you think this was done?

+2
source

tchrist (as always) is on the right track. You can play with IO::Socket and see what you can and cannot do with links to blissful character types.

 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 ... 
+1
source

Source: https://habr.com/ru/post/1402555/


All Articles