NIS-DBM

 view release on metacpan or  search on metacpan

lib/NIS/DBM.pm  view on Meta::CPAN

}

sub DESTROY {
  my $self = shift;

  if($self->{'options'}->{'FLUSH'}) {
    $self->flush;
  }

  # push_db handles the case of PUSH => 0
  $self->push_db(no_reopen => 1);

  $self->finish;
}

sub locked {
  my $self = shift;

  return 1 if $self->{'locked'};

  if(lock($self->{'options'}->{'yp_lock_file'})) {
    $self->{'locked'} = 1;
  } else {
    $self->{'locked'} = 0;
    carp "Unable to lock yp files: $!";
  }
  return $self->{'locked'};
}

sub unlocked {
  my $self = shift;

  return 1 unless $self->{'locked'};

  if(unlock($self->{'options'}->{'yp_lock_file'})) {
    $self->{'locked'} = 0;
  } else {
    $self->{'locked'} = 1;
    carp "Unable to unlock yp files: $!";
  }
  return $self->{'locked'};
}
  
1;
__END__

=head1 NAME

NIS::DBM - Perl module implementing a NIS daemon.

=head1 SYNOPSIS

  use NIS::DBM;

=head1 DESCRIPTION

NIS::DBM trivializes the implementation of daemons and other scripts
which maintain the NIS databases by presenting them as a hash keyed by
both username and user id.  If a numeric username exists in the byname
databases, the number associated with that username will be used as the
user id.  This is the same behavior as B<chown> and B<chgrp>.

NIS::DBM maintains three caches of information to construct an accurate
view of the NIS databases as modified by the program.  The caches are
for actual records from the database, modifications to the database, and 
deletions from the database.  The caches have the following precedence: 
deletions, modifications, and general cache.  The caches may be flushed to 
the database files at any time or upon object destruction.

=head1 NIS::DBM API

=over 4

=item NIS::DBM constructor

This will construct a new NIS::DBM object.  The arguments may be given
in a variaty of ways:

    tie %nis, NIS::DBM, ( 'config filename' );
    tie %nis, NIS::DBM, ( { config_file => 'filename',
                            sections   => [ 'sec1', ... ],
                            default_keys => { keys1 => value1, ... },
                            required_keys => [ key1, key2, ... ]
                          } );
    tie %nis, NIS::DBM, ( config_file => 'filename',
                          sections   => [ 'sec1', ... ],
                          default_keys => { keys1 => value1, ... },
                          required_keys => [ key1, key2, ... ]
                          );
    tie %nis, NIS::DBM, ( filename => '/path/to/conf/file'
                          program_tag => 'string'
                          defaults => { keys1 => value1, ... },
                          required => [ key1, key2, ... ]
                          );

=item FETCH

Given a username or user id, B<FETCH> will return the NIS record as a
hash reference.  B<FETCH> will first consult any caches maintained by the
tied object to provide current information that may not be available in the
database files.

=item STORE

Given a username or user id, B<STORE> will make any modifications to the
caches necessary for the databases to reflect the changes when flushed.  These
same chaches are consulted by B<FETCH>.

=item DELETE

Given a username or user id, B<DELETE> marks the record for deletion.  The
record is not available for B<FETCH>ing or testing for B<EXIST>ance.

=item CLEAR

This is called when the hash is assigned an empty hash or array.  This
function is not implemented.  You cannot remove the NIS user databases
using this module.

=item EXISTS



( run in 2.459 seconds using v1.01-cache-2.11-cpan-71847e10f99 )