On Sun, 13 Dec 2009 23:43:44 +0800, Xiao Lan (小兰) wrote: > Hello, > > my $obj; > > my $h; > foreach $h (@{ref($hosts) ? $hosts : [$hosts]}) { > $obj = $type->SUPER::new( > PeerAddr => ($host = $h), > PeerPort => $arg{Port} || 'smtp(25)', LocalAddr => > $arg{LocalAddr}, > LocalPort => $arg{LocalPort}, > Proto => 'tcp', > Timeout => defined $arg{Timeout} > ? $arg{Timeout} > : 120 > ) > and last; > } > > return undef > unless defined $obj; > > $obj->autoflush(1); > > $obj->debug(exists $arg{Debug} ? $arg{Debug} : undef); > > unless ($obj->response() == CMD_OK) { > $obj->close(); > return undef; > } > > ${*$obj}{'net_smtp_exact_addr'} = $arg{ExactAddresses}; > ${*$obj}{'net_smtp_host'} = $host; > > ---------------------------- > > What's the *$obj here?
This is by no stretch of the imagination a beginner's question. Your extract of the Net::SMTP constructor shows that the module creates an object by creating a object in the parent class. This turns out to be the constructor for IO::Handle, which returns a blessed reference to an anonymous glob formed with Symbol::gensym. *Named* globs are hard enough to grok, let alone anonymous ones. But that means that $obj can be dereferenced to the glob and thence variables can be populated in its package. This is how object attributes are done in this suite. The names are prefixed with net_smtp_ to avoid colliding with parent class attributes. This is not a common object implementation model. I do not suggest you emulate it. -- Peter Scott http://www.perlmedic.com/ http://www.perldebugged.com/ http://www.informit.com/store/product.aspx?isbn=0137001274 -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/