CfgTie

 view release on metacpan or  search on metacpan

lib/CfgTie/TieNamed.pm  view on Meta::CPAN

        ($fwd) = @Fwds;
     }

   #This pattern strips off the class stuff for the reversed addesses:
#   my $PatRevName= {s/\.$rev\.$//i};

   my ($Cnt,@R) = OurClass_machines($self,$fwd,$rev);
   $Cnt + Check_Bidir($self, $fwd, $rev, @R);
}

#Stuff for the config
sub HTML
{
   my ($self,$class)=@_;
   my $Ret="<table";
   if (defined $class) {$Ret .= " classname=$class";}
   $Ret .=">";
   foreach my $I (sort keys %{$self})
    {
       my $i = lc($I);
       # Skip the more complex ones...
       if ($i eq 'limit' || $i eq 'primary') {next;}
       $Ret .= "<tr><th align=right>$I</th><td>".$self->{$I}."</td></tr>\n";
    }
   if (exists $self->{limit})
     {
        $Ret .= "<tr><th align=right>Limits</th><td><table>".
         join "\n",
          map {"<tr><th align=right>$_</th><td>".$self->{limit}->{$_}.
               "</td></tr>";} (sort keys %{$self->{limit}});
        $Ret .="</table></td></tr>\n";
     }
   if (exists $self->{primary})
     {
        $Ret .= "<tr><th align=right>Domains:</th><td>".
         join "\n",
          map {"<a href=\"primary/$_/\">$_</a><br>"}
           (sort keys %{$self->{primary}});
        $Ret .="</td></tr>\n";
     }
   "$Ret</table>\n";
}

package CfgTie::TieNamed_primary;
@ISA=qw(CfgTie::Cfgfile);
#A tie hash for a single primary file...

my @days_per_month=(31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);

sub SerialNum_next($)
{
   # A routine to guess the human format of the serial number and come up with
   # the next one.  The minimal rule here is that the returned value will be
   # no matter what, greater than the previous one.
   # We are allowed 9 digits in base 10.
   my $SN = shift;

   my ($sec,$min,$hour,$MDay,$Month,$Year,$WDay,$YDay,$isDST)=localtime;

   #Try YEAR-MONTH-DayOfMonth-Rev
   #  We have to make general calendar boundary conditions, plus be at an
   #  earlier date than now.
   if ($SN =~ /^(\d\d\d\d)(\d\d)(\d\d)(\d)$/ &&
       $2 <= 12 && $3 <= $days_per_month[$2-1] &&
       ($1 < $Year ||
         ($1 == $Year && ($2 < $Month+1||($2==$Month+1&&$3<=$MDay+1)))))
     {
        # We passed the first part of the boundary conditions...
        my $NewSn = $Year.($Month+1).($MDay+1)."0";
        while ($NewSN <= $SN) {$NewSN++;}
        return $NewSN;
     }

   #Okay, try YEAR-WEEK-DayOfWeek-Rev
   my $Week;
   if ($YDay < $WDay) {$Week = 0;}
    else {$Week  = ($YDay-$WDay)/7;}

   if ($SN =~ /^(\d\d\d\d)(\d\d)(\d)(\d\d)$/ &&
       $2 <= 52 && $3 <= 7 &&
       ($1 < $Year ||
         ($1 == $Year && ($2 < $Week+1||($2==$Week+1&&$3<=$WDay+1)))
       ))
     {
        # We passed the first part of the boundary conditions...
        my $NewSn = $Year.($Week+1).($WDay+1)."00";
        while ($NewSN <= $SN) {$NewSN++;}
        return $NewSN;
     }

   #Okay try YEAR-DayOfYear-Rev
   if ($SN =~ /^(\d\d\d\d)(\d\d\d)(\d\d)$/ &&
       $2 <= 366  &&
       ($1 < $Year || ($1 == $Year && $2 <= $YDay+1)))
     {
        # We passed the first part of the boundary conditions...
        my $NewSn = $Year.($YDay+1)."000";
        while ($NewSN <= $SN) {$NewSN++;}
        return $NewSN;
     }

   #Didn't match anything... write a new one out.
   return $SN+1;
}

sub addrec
{
   my ($self,$key,$attr,$_val) = @_;

   #Convert the value to list notation
   my $val;
   if (lc($attr) eq 'txt')
     {$val = [$_val];}
    else
     {$val = [split(/\s+/,$_val)];}

   #If there is data already here we just append the data to the list
   if (!exists $self->{Contents} || !exists $self->{Contents}->{$key} ||
       !exists $self->{Contents}->{$key}->{$attr})
     {$self->{Contents}->{$key}->{$attr}=$val;}
    else



( run in 1.211 second using v1.01-cache-2.11-cpan-54e63673c56 )