From: Stephen L Johnson Date: Wed, 29 Dec 1999 04:13:25 +0000 (+0000) Subject: Recoded functions to allow proper inheritance of the class. X-Git-Tag: spong-2_6b~14 X-Git-Url: http://git.etc.gen.nz/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=26a6b2e4adaa820e53b55d91807d8e7fe1a60ada;p=spong.git Recoded functions to allow proper inheritance of the class. --- diff --git a/src/lib/Spong/Service.pm b/src/lib/Spong/Service.pm index 79b93db..13db7c2 100755 --- a/src/lib/Spong/Service.pm +++ b/src/lib/Spong/Service.pm @@ -31,7 +31,8 @@ package Spong::Service; # ServiceList object for loading the information about it from the database. sub new { - my( $class, $host, $service ) = @_; + my( $proto, $host, $service ) = @_; + my( $class ) = ref($proto) || $proto; my $self = {}; # A hack to get around a local problem. @@ -47,7 +48,7 @@ sub new { $self->{'message'} = ""; $self->{'stime'} = ""; - bless $self; + bless ($self,$class); return $self; } @@ -108,14 +109,12 @@ sub rtime { my $var = 'rtime'; sub stime { my $var = 'stime'; if( $_[0]->{$var} eq "" ) { $_[0]->summary(); } return $_[0]->{$var}; } +# These functions handle the loading of of the service data from the +# database files -# These are both lazy loading functions. If we don't have summary and message -# information already loaded, then go out and grab it from the database and -# return that information to the user. - -sub summary { - my $self = shift; - my $file; +sub filename { + my( $self ) = shift; + my( $file ); # This is a local hack to get around the procs/jobs problems, first look # for the jobs service, if it is not there, look for procs... @@ -129,52 +128,40 @@ sub summary { $file = $self->host()."/services/".$self->name()."-".$self->rcolor(); } + return $file; +} - if( ! $self->{'summary'} ) { - open( FILE, "$main::SPONGDB/$file" ); - my $header = ; chomp $header; - # If a timestamp is present, read it and set start time - if ($header =~ /^timestamp (\d+) (\d+)/ ) { - $self->{'stime'} = $1; - $header = ; chomp $header; - } - ($self->{'rtime'}, $self->{'summary'}) = ( $header =~ /^(\d+) (.*)$/ ); - while( ) { $self->{'message'} .= $_; } - close( FILE ); +sub load { + my( $self ) = shift; + my $file = $self->filename(); + + open( FILE, "$main::SPONGDB/$file" ); + my $header = ; chomp $header; + # If a timestamp is present, read it and set start time + if ($header =~ /^timestamp (\d+) (\d+)/ ) { + $self->{'stime'} = $1; + $header = ; chomp $header; } + ($self->{'rtime'}, $self->{'summary'}) = ( $header =~ /^(\d+) (.*)$/ ); + while( ) { $self->{'message'} .= $_; } + close( FILE ); +} + +# These are both lazy loading functions. If we don't have summary and message +# information already loaded, then go out and grab it from the database and +# return that information to the user. +sub summary { + my $self = shift; + + if( ! $self->{'summary'} ) { $self->load(); } return $self->{'summary'}; } sub message { my $self = shift; - my $file; - - # This is a local hack to get around the procs/jobs problems, first look - # for the jobs service, if it is not there, look for procs... - - if( $self->name() eq "jobs" ) { - $file = $self->host()."/services/".$self->name()."-".$self->rcolor(); - if( ! -f $file ) { - $file = $self->host()."/services/procs-".$self->rcolor(); - } - } else { - $file = $self->host()."/services/".$self->name()."-".$self->rcolor(); - } - - if( ! $self->{'message'} ) { - open( FILE, "$main::SPONGDB/$file" ); - my $header = ; chomp $header; - # If timestamp header present, read it and set start time - if ($header =~ /^timestamp (\d+) (\d+)/ ) { - $self->{'stime'} = $1; - $header = ; chomp $header; - } - ($self->{'rtime'}, $self->{'summary'}) = ( $header =~ /^(\d+) (.*)$/ ); - while( ) { $self->{'message'} .= $_; } - close( FILE ); - } + if( ! $self->{'message'} ) { $self->load(); } return $self->{'message'}; } @@ -248,7 +235,7 @@ sub display_text { } elsif( $format eq "full" ) { $self->display_text( "standard" ); print "\nStatus unchanged in " . - &format_duration($self->stime(),$self->rtime) . "\n"; + $self->format_duration($self->stime(),$self->rtime) . "\n"; print "-"x78, "\n"; print $self->message(), "\n"; } @@ -326,7 +313,7 @@ sub display_html { print POSIX::strftime( "%H:%M, %D", localtime($self->rtime()) ); print "
Duration: "; - print &format_duration($self->stime(),$self->rtime()); + print $self->format_duration($self->stime(),$self->rtime()); print "
Summary: ", $self->summary(), "
\n"; print "
", $self->message(), "
\n"; @@ -372,7 +359,7 @@ sub escape { } sub format_duration { - my($stime,$rtime) = @_; + my($self,$stime,$rtime) = @_; my $duration = $rtime - $stime; my $units = "seconds";