package PGF::GapResolution::ParseValidationSummary; =head1 NAME PGF::GapResolution::ParseValidationSummary =head1 SYNOPSIS use PGF::GapResolution::ParseValidationSummary; my $obj = PGF::GapResolution::ParseValidationSummary->new($validationFile); while ( $obj->getNextEntry() ) { my $subProjectDir = $obj->getPath(); my $status = $obj->getStatus(); my $isSuccessful = $obj->isSuccessful(); my $comment = $obj->getComment(); ... } =head1 DESCRIPTION This module parses a validation summary file generated by validateSubProject.pl as part of the Gap Resolution sub system and contains access methods to the data. The format of the validation summary file mentioned above are as follows, separated by a tab: 1. 2. PASS|FAIL 3. =head1 AUTHOR(s) Stephan Trong =head1 HISTORY =over =item * Stephan Trong 07/29/2009 Creation =back =cut #============================================================================# use strict; use warnings; use Carp; use Carp qw(cluck); use FindBin qw($RealBin); use lib "$FindBin::RealBin/../lib"; #============================================================================# sub new { my $class = shift; my $validationFile = shift; my $self = {}; bless $self, $class; $self->_parseFile($validationFile); $self->{_index} = -1; return $self; } #============================================================================# sub _parseFile { my $self = shift; my $file = shift; my @validationInfos = (); unless (open FH, $file ) { confess "ERROR: failed to open file $file: $!"; } while ( my $entry = ) { chomp $entry; next if !length $entry; my @entries = split /\t/, $entry; if ( @entries < 2 ) { confess "ERROR: $file does not contain a vaild entry $#entries < 2.\n"; } my $path = $entries[0]; my $status = $entries[1]; my $comment = @entries > 2 ? $entries[2] : ''; push @validationInfos, { path=>$path, status=>$status, comment=>$comment }; } close FH; $self->{_validationInfo} = \@validationInfos; $self->{_numEntries} = scalar(@validationInfos); } #============================================================================# sub getNextEntry { my $self = shift; $self->{_index}++; return $self->{_index} >= $self->{_numEntries} ? 0:1; } #============================================================================# sub getPath { my $self = shift; return $self->_getEntry('path'); } #============================================================================# sub isSuccessful { my $self = shift; return $self->getStatus eq 'PASS' ? 1:0; } #============================================================================# sub getStatus { my $self = shift; return $self->_getEntry('status'); } #============================================================================# sub getComment { my $self = shift; return $self->_getEntry('comment'); } #============================================================================# sub _getEntry { my $self = shift; my $type = shift; my $index = $self->{_index}; if ( $index < 0 ) { return ''; } else { return $self->{_validationInfo}[$index]{$type}; } } #============================================================================# 1;