package sam; use strict; use Data::Dumper; use status; sub new{ my($class) = @_; my $this = { 'sample_id'=>undef, 'test_list'=>[], 'status'=>[], } ; bless($this, $class); return $this; } sub sample_id{ if(defined $_[1]){$_[0]->{'sample_id'}=$_[1];} else{return $_[0]->{'sample_id'}} } sub add_test{ my($this, $test) = @_; # Add test to sample push @{$this->{'test_list'}}, $test; $test->add_to_sample($this); } sub add_status{ my($this, $test) = @_; my $h = {}; $h->{'ref'} = ${$test->{'status'}}[(scalar(@{$test->{'status'}}) - 1)]; $h->{'src'} = $test; push @{$this->{'status'}}, $h; } sub status_history{ my($this) = @_; my $history = ""; foreach my $entry(@{$this->{'status'}}){ $history .= sprintf("%s\t%s\t%s\t%s\n", $entry->{src}->test_id(), $entry->{'ref'}->status(), $entry->{'ref'}->time(), $entry->{'ref'}->owner()); } return $history; } sub current_status{ my($this) = @_; my $top; foreach my $entry(@{$this->{'status'}}){ $top = $entry if(! defined $top || $entry->{'ref'}->status_code() > $top->{'ref'}->status_code()); } return $top->{'ref'}->status; } 1;