Net::RRP::Entity - rrp entity abstraction class


Net-RRP documentation Contained in the Net-RRP distribution.

Index


Code Index:

NAME

Top

Net::RRP::Entity - rrp entity abstraction class

SYNOPSIS

Top

 use Net::RRP::Entity;
 my $entity = new Net::RRP::Entity();

DESCRIPTION

Top

This is a base class for all Entity::* classes.

new

This is a constructor. Example:

 use Net::RRP::Entity;
 my $entity = new Net::RRP::Entity();
 my $entity1 = new Net::RRP::Entity( key => [ 'value' ] );

getName

Return a *real* name of this entity. You must overwrite this method at child class. Example:

 my $entityName = $entity->getName();
 print STDERR "EntityName is $entityName\n";

setAttribute

Setup attribte with name $attributeName to a $attributeValue. $attributeValue must be a array ref. Example:

 $entity->setAttribute ( $attributeName, $attributeValue );
 $entity->setAttribute ( 'DomainName', [ 'test.ru' ] );
 $entity->setAttribute ( 'NameServer', [ 'ns1.ttt.ru', 'ns2.qqq.ru' ] );

getAttribute

Return a value of $attributeName attribute. Example:

 print STDERR $entity->getAttribute ( 'NameServer' )->[ 0 ];

Can throw Net::RRP::Exception::MissingRequiredAttribute exception

getAttributes

Return the hash ref of the all entity attributes. Example:

 my $attributes = $entity->getAttributes();
 foreach my $attributeName ( keys %$attributes )
 {
      print $attributeName . ' ' . $attributes->{ $$attributeName }->[ 0 ];
 }

getPrimaryAttributeValue

return a "primary" attribute value

AUTHOR AND COPYRIGHT

Top

SEE ALSO

Top

Net::RRP::Request(3), Net::RRP::Response(3), Net::RRP::Codec(3), RFC 2832, Net::RRP::Exception::MissingRequiredAttribute(3)


Net-RRP documentation Contained in the Net-RRP distribution.
package Net::RRP::Entity;

use strict;
use Net::RRP::Exception::MissingRequiredAttribute;
use Net::RRP::Toolkit;

$Net::RRP::Entity::VERSION = '0.02';

sub new
{
    my $class = shift;
    bless { attributes => Net::RRP::Toolkit::lowerKeys ( { @_ } ) }, $class;
}

sub getName
{
    die "Must be implemented at child class";
}

sub setAttribute
{
    my ( $this, $attributeName, $attributeValue ) = @_;
    $attributeName = lc ( $attributeName );
    my $old = $this->{attributes}->{$attributeName};
    $this->{attributes}->{$attributeName} = $attributeValue;
    $old;
}

sub getAttribute
{
    my ( $this, $attributeName ) = @_;
    $this->{attributes}->{ lc ( $attributeName ) } || throw Net::RRP::Exception::MissingRequiredAttribute();
}

sub getAttributes
{
    my $this = shift;
    $this->{attributes};
}

sub getPrimaryAttributeValue
{
    my $this = shift;
    $this->getAttribute ( $this->getName . 'Name' );
}

1;

__END__