Ilya Ketris > Net-NISplusTied-0.02 > Net::NISplusTied

Download:
Net-NISplusTied-0.02.tgz

Dependencies

Annotate this POD

View/Report Bugs
Module Version: 0.02   Source  

NAME ^

Net::NISplusTied -- TIEHASH() interface to NIS+ tables

SYNOPSIS ^

        use Net::NISplusTied;
  
        tie (%hash, Net::NISplusTied, 'your.table.domain.');
 
        ### lookups
        $arrayref = $hash {'field=key'};
        $arrayref = $hash {'field1=key1,field2=key2'};
        $arrayref = $hash {{field => $key}};
        $arrayref = $hash {{field1 => $key1, field2 => $key2}};

        $hashref = $hash {'field1=key'} [0];
        $value = $hash {'field1=key'} [0] {field2};
 
        ### modify value
        $hash {'field1=key'} = {field2 => $newvalue2, field3 => $newvalue3};
        $hash {{field1 => $key}} = {field2 => $newvalue2, field3 => $newvalue3};
 
        ### delete entry
        delete $hash {'field1=key'};
        delete $hash {{field => $key}};
 
        ### iterate through table
        # not implemented #

DESCRIPTION ^

The Net::NISplusTied allows you to treat NIS+ tables as if they were perl hashes, using tie() semantics. It has cultural links to Rick Harris (Rik.Harris@fulcrum.com.au) NISperl module, although the design goals were different. All you can do with Net::NISplusTied is to manipulate NIS+ tables. If you need faithful NIS+ API implementation, consider using NISperl instead. The assumption was that one would rarely need to create and delete NIS+ tables and groups from perl, at least not often enough to be seriously inconvenienced by system 'nistbladm' ... etc.

tie()

The third argument to tie() is the fully qualified name of the table you wish to tie. The module disregards NIS_PATH settings.

FETCH()

Hash lookups should have NIS+ indexes as the keys, with no square brackets. The following are shell and perl eqivavlents:

shell:

        nismatch [name=bob,age=33],users.my.domain.

perl:

        tie (%users, Net::NISplusTied, 'users.my.domain.');
        $results = $users {'name=bob,age=33'};

The value returned from a lookup is an array ref. Array elements are hash refs representing the individual entries. Hashes are keyed by the table columns. The following would print user bob's login shell setting from the stock passwd.org_dir file:

        tie (%passwd, Net::NISplusTied, 'passwd.org_dir.your.domain.');
        print $passwd {'name=bob'} [0] {shell};

STORE()

The STORE() method need some explanations. It takes scalar as a key and hash ref as a value. If the result of key lookup returns exactly one entry, this entry is replaced. If there is none or more than one, entry is added to the table. It is up to you to ensure that the indexes stay unique, since the module will not do this. Consider the following table:

        field1          field2          field3
        ---------------------------------------------
        apple           cat             ...
        apple           dog             ...
        orange          cat             ...

        tie (%table, Net::NISplusTied, ...);

The following piece of code

        $table {'field1=apple,field2=cat'} = {field3 => 'whatever'};

will chnage entry [1], but

        $table {'field1=apple'} = {field2 => 'cat', field3 => 'whatever'};

will add a new entry to the table, since field1=apple is not unique.

DELETE()

        delete $passwd {'name=bob'}

does what you think it does. Be careful however, REM_MULTIPLE flag is set, and running

        delete $passwd {''}

will remove ALL ENTRIES from the table.

DESTROY()

destroy $passwd; frees up the memory taken by the hash. You should not normally need this.

NOTE ^

Copyright (c) 1998 Ilya Ketris. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

AUTHOR ^

Ilya Ketris, ilya@gde.to

SEE ALSO ^

perl(1), perlguts(1), nis(1)

syntax highlighting: