Scoped - Class encapsulating scope properties


 package Unix::Sysadmin::Something;
 use strict;
 @Unix::Sysadmin::Something::ISA = qw ( Unix::Sysadmin::Scoped );


This class provides scope properties to Unix::Sysadmin entity classes. A class inheriting from Unix::Sysadmin::Scoped gains methods that supplement the _init(), load() and dump() methods. These supplementary methods implement three class properties. They are scope(), expt_allow() and expt_deny(). Unix::Sysadmin::Scoped doesn't care what values theseproperties have. It merely sets and gets them, and loads and dumps them to and from disk. It's up to the derived class to provide a has_access() method that makes sense out of the values stored in these properties.


Here is part of an entity class called 'Unix::Sysadmin::Something' that wants to inherit from ::Scoped:

 package Unix::Sysadmin::Something;
 use strict;
 @Unix::Sysadmin::Something::ISA = qw ( Unix::Sysadmin::Scoped );

The _init method loads a new object with data passed in by a hashref. If we pass this ref off to SUPER::_init, ::Scoped can deal with the scope=, expt_allow= and expt_deny clauses:

 sub _init { # standard initializer called from new()
   my $self=shift;
   my $init=shift; # initializer hashref
   $self->SUPER::_init($init); # call base class's init. (::Scoped in this case)

The load() method loads data from a file handle into a new object. If we pass lines we don't recognize off to SUPER::load(), ::Scoped can maybe deal with them:

 sub load {
   my $self=shift;
   my $fh = shift;
   my $something =Unix::Sysadmin::Something->new();;
   while (<$fh>) {

     if (/^somethingiwant=\s*\#*$/){
     } elseif (/^somethingelseiwant=\s*\#*$/){
     } else { # pass line to base class for processing
       $self->SUPER::load( {NEWOBJ=>$something,LINE=>$_} );

Similarly, the dump() method dumps the object to STDOUT. If we call SUPER::dump(), ::Scoped can add its properties to the dump:

 sub dump {
   my $self = shift;
  print "somethingiwant=".$self->iwant()."\n";
  print "somethingelseiwant=".$self->elseiwant()."\n";
  $self->SUPER::dump(); # Let base class have it's say

Finally, to add some semantics to all this syntax, we should implement a has_access() method that makes sense of the properties ::Scoped has been looking after for us:

  sub hasAccess {
    my $self=shift;
    my $towhat=shift; # what we want access to
    my $sref=$self->scope();
    my $dref=$self->expt_deny();
    my $aref=$self->expt_allow();
    if ($sref->[0] eq 'ALL'){
      print "Come on in! Glad to see you! .. just a minute .. ";
      my $name =$self->name();
      my $match = join "|",@$dref;
      if ($name=~/$match/) {
         print "sorry, there's been some mistake. Keep moving. Next?\n";
         return 0;
      print "Right this way. Your table is waiting!\n";
      return 1;


Man(3) pages (programmer's docs):

the Unix::Sysadmin::Host manpage, the Unix::Sysadmin::User manpage, the Unix::Sysadmin::Automount manpage, the Unix::Sysadmin::Group manpage, the Unix::Sysadmin::Netgroup manpage, the Unix::Sysadmin::List manpage, the Unix::Sysadmin::Cmds manpage, the Unix::Sysadmin::Files manpage the Unix::Sysadmin::Utility manpage the Unix::Sysadmin::Config manpage, the Unix::Sysadmin::Scoped manpage

Man(4) pages (file formats):

the Unix::Sysadmin::Host.list manpage, the Unix::Sysadmin::User.list manpage, the Unix::Sysadmin::Automount.list manpage, the Unix::Sysadmin::Group.list manpage, the Unix::Sysadmin::Netgroup.list manpage

Man(1m) pages (manager's docs):

the Unix::Sysadmin manpage, the Unix::Sysadmin::Setup manpage the usasetup manpage

the usatest manpage

the usabackup manpage

the usaupdate manpage

the usapush manpage


Howard Owen <> =cut