From: "Chhabria, Kavita - Apogent" <[EMAIL PROTECTED]>
> Can someone kindly explain me what this piece of perl code is doing
> step by step, I am new to Perl and am unable to understand this piece
> of code contained within a module.
>
> sub new {
> my ( $class, %args ) = @_;
This is a constructor. You are supposed to call it like this:
$obj = The::Object::Type->new( Cache => $cache, Expire => $expire);
or
$obj = new The::Object::Type( Cache => $cache, Expire => $expire);
The command above sets the
$class = 'The::Object::Type';
and
%args = (
Cache => $cache, Expire => $expire
);
> my $self = {};
The object will keep its data in a hash, $self is set to a reference
to an anonymous hash.
> $self->{ _PARSERS } = \%PARSERS;
> $self->{ _DOMAIN_ASSOC } = \%DOMAIN_ASSOC;
> $self->{ _WHOIS_PARSER } = \%WHOIS_PARSER;
This sets some internal (starting with _) properties of the object to
some defaults (capital leters in a variable name usualy mean that the
variable is global). The \%PARSERS is a reference to the global hash
%PARSERS, etc.
> $self->{ _CACHE } = $args{Cache} || \$CACHE;
The internal property _CACHE will either be set to the cache you
passed in or to a reference to some global cache.
> $self->{ _EXPIRE } = $args{Expire} || \$EXPIRE;
Dto for expiration.
> $self->{ _ARGS } = \%ARGS;
Again some defaults.
> bless $self, $class;
In Perl object is just a reference that is "blesses" into a package,
that is a reference that knows to which class it belongs to.
> $self->personality ( %args );
Call the personality() method on the created object with the
agruments.
> $self->lookup () if $self->{ Domain };
If the personality() method set the Domain property of the object
call the lookup() method.
> return $self;
return the created and initialized object.
Jenda
===== [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =====
When it comes to wine, women and song, wizards are allowed
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery
_______________________________________________
ActivePerl mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs