pavan
pavan

Reputation: 314

hide attributes in object oriented perl

Recently I am using chilkat perl library for sending email

http://www.example-code.com/perl/smtp_simpleSend.asp

when i create new object

use chilkat();

#  The mailman object is used for sending and receiving email.
$mailman = new chilkat::CkMailMan();
$mailman->put_SmtpHost("smtp.chilkatsoft.com");
#  Set the SMTP login/password (if required)
$mailman->put_SmtpUsername("myUsername");
$mailman->put_SmtpPassword("myPassword");

when i try to print the object using Dumper method it returns nothing.

print Dumper($mailMan);
$VAR1 = bless( {}, 'chilkat::CkMailMan' );

how can we hide the data in blessed object like above?

Upvotes: 0

Views: 156

Answers (1)

simbabque
simbabque

Reputation: 54371

Take a look at the code. It loads a C library (dll on Windows) with DynaLoader. The rest is only constructors. The properties (like SmptHost) are not kept in the Perl datastructure. It is just passed on to C function calls. I'm not even sure you can have several distinct objects at the same time. That's why there is nothing in the blessed hash.


You cannot just hide the data. There are no private methods in normal Perl objects. There is always a way to get to the stuff. There are object frameworks that make it harder to serialize it with Data::Dumper, but that is not the purpose of these. Take a look at Class::Std::Fast::Storable for example.

Upvotes: 6

Related Questions