Puzzlement #1)
This code comes from Msg.pm. It is the first sub in the file,
following some glocal hashes and such.
Connect lists 4 paramaters, 3 are used here.# Send side routines sub connect { my ($pkg, $to_host, $to_port, $rcvd_notification_proc) = @_; # Create a new internet socket my $sock = IO::Socket::INET->new ( PeerAddr => $to_host, PeerPort => $to_port, Proto => 'tcp', Reuse => 1);
use Msg; ... foreach $prog (@ARGV) { my $conn = Msg->connect($host, $port, \&rcvd_msg_from_server); die "Client could not connect to $host:$port\n" unless $conn; print "Connection successful.\n";
From the comment, an object was created. The reference is the anonymous hash with 2 members, and the class name is what? $pkg appears to be an undefined scalar?# Create a connection end-point object my $conn = bless { sock => $sock, rcvd_notification_proc => $rcvd_notification_proc, }, $pkg;
Puzzlement #2
Further down in the code is a small subroutine that sets the flush
value to true for the 'conn':
From the prior 'bless', a $conn has no methods, but thesub send_now { my ($conn, $msg) = @_; _enqueue ($conn, $msg); $conn->_send (1); # 1 ==> flush ?????? }
looks like _send is a method of the $conn object. Is that a shorthand or alternate form of$conn->_send (1);
of a Perl convention to have a non object method work with this object._send ($conn,1);
This --server code listens on only one port, and I am trying to generalize it to manage multiple listen sockets and support UDP as well as TCP.
It is always better to have seen your target for yourself, rather than depend upon someone else's description.
In reply to Perl semi-object without a constructor by Wiggins
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |