The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Net::Whois::Object - Object encapsulating RPSL data returned by Whois queries

SYNOPSIS

    use Net::Whois::RIPE;
    use Net::Whois::Object;

    my @objects = Net::Whois::Object->query('AS30781');


    # Or you can use the previous way

    my $whois = Net::Whois::RIPE->new( %options );
    $iterator = $whois->query('AS30781');

    push @objects, Net::Whois::Object->new($iterator);

    for my $object (@objects) {
        # process Net::Whois::Object::xxx objects... 
        # Type of object is available via class() method
    }

USAGE

Get the data

    # Get the Class we want to modify
    my $whois = Net::Whois::RIPE->new( %options );
    $iterator = $whois->query('POLK-RIPE');

Filter objects

Before you had to filter objects using the class() method.

    # Then to only get the Person object (and ignore Information objects)
    my ($person) = grep {$_->class() eq 'Person'} Net::Whois::Object->new($iterator);

But now the query() method allows you to filter more easily

    my ($person) = Net::Whois::Object->query('POLK-RIPE', { type => 'person' });

You can even use the query() filtering capabilities a little further

    my @emails = Net::Whois::Object->query('POLK-RIPE', { type => 'person', attribute => 'e_mail' });

Please note, that as soon as you use the attribute filter, the values returned are strings and no more Net::Whois::Objects.

Modify the data

    # Add a phone number
    $person->phone(' +33 4 88 00 65 15');

Some attributes can have multiple value (remarks, mnt-by...) first implementation allowed only to add one value

    # Add one maintener
    $person->mnt_by('CPNY-MNT');
    

New implementation (post 2.00020) allow to do:

    $person->mnt_by({mode => 'append', value => 'CPNY-MNT'});

Which is a verbose way to do exactly as the default mode above, but also

    # Append multiple values at once
    $person->mnt_by({mode => 'append', value => ['CPNY-MNT2','CPNY-MNT3']});

Or even

    # Replace CPNY-MNT2 by REPL-MNT
    $person->mnt_by({mode => 'replace', value => {old => 'CPNY-MNT2', old => 'REPL-MNT'}});

Dump the current state of the data

The dump() method, enable to print the object under the classic text form, made of 'attribute: value' lines.

    # Dump the modified data
    my $to_be_mailed = $person->dump();

dump() handle the 'align' parameter passed though a hash ref.

    my $to_be_mailed = $person->dump( { align => 15 });

Update the RIPE database

The RIPE database update is currently under heavy development. *The update code is to be considered as experimental.*

We plan to offer several ways to update the RIPE database

Update through the web interface

RIPE provides several web interfaces

SyncUpdates (*Experimental*)

Although not the latest one, this simple interface is the first to be wrapped by this module.

CAUTION: SyncUpdates features require LWP::UserAgent to be installed.

Create

Once the object has been modified, locally, you can create it in the database calling the syncupdates_create() method.

The parameters are passed through a hash ref, and can be the maintener authentication credentials ('password' or 'pgpkey') and the 'align' parameter

    $object->person('John Doe');
    ...
    my $primary_key = $object->syncupdates_create( { password => $password } );
    # or
    my $primary_key = $object->syncupdates_create( { pgpkey   => $keyID, align => 8 } );

The pgp key must be an eight digit hexadecimal key ID known to the local gpg executable.

If the pgpkey key is present in the hash reference passed to syncupdates_create, you can also pass in the pgpexec key to chose a program to execute for signing (gpg by default), and pgpopts, which must be an array reference of additional options to pass to the signing binary.

The primary key of the object created is returned. The attribute used as primary key can be obtained through $object->attribute('primary')

Update

An object existing in the RIPE database, can be retrieved, modified locally and then updated through the syncupdates_update() method.

Parameters are passed through a hash ref, and can be the maintener authentication credentials ('password' or 'pgpkey') and the 'align' parameter See "Create" for more information on the authentication methods.

    $object->person('John Doe');
    ...
    $object->syncupdates_update( { password => $password } );

Delete

An object existing in the RIPE database, can be retrieved, and deleted in the databased through the syncupdates_delete() method. Parameters are passed through a hash ref, and can be the maintener authentication credentials ('password' or 'pgpkey') and the 'reason' parameter See "Create" for more information on the authentication methods.

    $object->syncupdates_delete( { pgpkey => $keyID } );

An additional parameter can be used as a reason for the deletion.

    $object->syncupdates_delete( { pgpkey => $keyID, reason =>  'Obsoleted by XXX' } );

If no reason is provided, a default one ('Not needed anymore') is used.

Update through email.

Not implemented yet.

SUBROUTINES/METHODS

new( @lines|$iterator )

The constructor is a factory returning the appropriate Net::Whois::Objects based on the first attribute of the block. You can pass an array of lines or an iterator returned by Net::Whois::RIPE as argument.

The two following ways of using the constructor are possible

    my $whois = Net::Whois::RIPE->new( %options );
    $iterator = $whois->query('AS30781');

    # Using the iterator way
    push @objects, Net::Whois::Object->new($iterator);

or

    # Using the previous (more circonvoluted) @lines way

    while ( ! $iterator->is_exhausted() ) {
        my @lines = map { "$_\n"} split '\n',  $iterator->value();
        push @objects, Net::Whois::Object->new(@lines,"\n");
    }

clone( [\%options] )

Return a clone from a Net::Whois::RIPE object

Current allowed option is remove => [attribute1, ..., attributen] where the specified attribute AREN'T copied to the clone object (for example to ignore the 'changed' values)

attributes( [$type [, \@attributes]] )

Accessor to the attributes of the object. $type can be

    'primary'   Primary/Lookup key
    'mandatory' Required for update creation
    'optional' Optionnal for update/creation
    'multiple'  Can have multiple values
    'single'    Have only one value
    'all'       You can't specify attributes for this special type
                which provides all the attributes which have a type

If no $type is specified, 'all' is assumed. Returns a list of attributes of the required type.

class ( )

This method return the RIPE class associated to the current object.

attribute_is ( $attribute, $type )

This method return true if $attribute is of type $type.

hidden_attributes( $attribute )

Accessor to the filtered_attributes attribute (attributes to be hidden) Accepts an optional attribute to be added to the filtered_attributes array, always return the current filtered_attributes array.

displayed_attributes( $attribute )

Accessor to the displayed_attributes attribute which should be displayed. Accepts an optional attribute to be added to the displayed_attributes array, always return the current displayed_attributes array.

dump( [\%options] )

Simple naive way to display a text form of the class. Try to be as close as possible as the submited text.

Currently the only option available is 'align' which accept a $column number as parameter so that all $self->dump produces values that are aligned vertically on column $column.

syncupdates_update([\%options] )

Update the RIPE database through the web syncupdates interface. Use the password passed as parameter to authenticate.

syncupdates_delete( \%options )

Delete the object in the RIPE database through the web syncupdates interface. Use the password passed as parameter to authenticate. The optional parmeter reason is used to explain why the object is deleted.

syncupdates_create( \%options )

Create an object in the the RIPE database through the web syncupdates interface. See "Create" for more information on the authentication methods.

The available options are 'pgpkey', 'password' and 'align'

Return the primary key of the object created.

query( $query, [\%options] )

 ******************************** EXPERIMENTAL ************************************
   This method is a work in progress, the API and behaviour are subject to change
 **********************************************************************************

Query the RIPE database and return Net::Whois::Objects

This method accepts 2 optional parameters

'type' which is a regex used to filter the query result : Only the object whose type matches the 'type' parameter are returned

'attribute' which is a regex used to filter the query result : Only the value of the attributes matching the 'attribute' parameter are returned

Note that if 'attribute' is specified strings are returned, instead of Net::Whois::Objects

TODO

The update part (in RIPE database) still needs a lot of work.

Enhance testing without network

Enhance test coverage

AUTHOR

Arnaud "Arhuman" Assad, <arhuman at gmail.com>

ACKNOWLEDGEMENTS

Thanks to Jaguar Network for allowing me to work on this during some of my office hours.

Thanks to Luis Motta Campos for his trust when allowing me to publish this release.

Thanks to Moritz Lenz for all his contributions (Thanks also to 'Noris Network AG', his employer, for allowing him to contribute in the office hours)