IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 6474


Ignore:
Timestamp:
Feb 23, 2006, 4:51:31 PM (20 years ago)
Author:
jhoblitt
Message:

first pass DateStore::FileSet::Parser->parse() implementation

Location:
trunk/DataStore
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/DataStore/lib/DataStore/FileSet/Parser.pm

    r6473 r6474  
    11# Copyright (C) 2006  Joshua Hoblitt
    22#
    3 # $Id: Parser.pm,v 1.1 2006-02-24 00:52:14 jhoblitt Exp $
     3# $Id: Parser.pm,v 1.2 2006-02-24 02:51:31 jhoblitt Exp $
    44
    55package DataStore::FileSet::Parser;
     
    1313use Carp qw( carp );
    1414use Params::Validate qw( validate_pos SCALAR);
     15
     16my $time_field = qr/^ (\d{4})-(\d\d)-(\d\d) T (\d\d):(\d\d):(\d\d) Z $/x;
     17my $std_field = qr/^[a-z0-9-_.]+$/;
     18#my %known_types = map { $_ => 1 } qw( OBJECT DOMEFLAT SKYFLAT BIAS DARK );
     19my %known_types = map { $_ => 1 } qw( object domeflat skyflat bias dark );
    1520
    1621=pod
     
    8085    );
    8186
    82 #    @ = qw( OBJECT DOMEFLAT SKYFLAT BIAS DARK );
     87    my @data;
     88    my $lineno = 1;
     89LINE: foreach my $line (split /\n/, $doc) {
     90        # blank lines
     91        next LINE if $line =~ /^\s*$/;
     92
     93        # comment lines   
     94        next LINE if $line =~ /^\s*\#/;
     95
     96        my @fields = split /\|/, $line;
     97
     98        # at least fileset, datatime, and type fields are required
     99        if (scalar @fields < 3) {
     100            carp "line $lineno: not enough fields: $line";
     101            next LINE;
     102        }
     103
     104        my ($fileset, $datetime, $type) = @fields;
     105
     106        # validate format of fileset and type
     107        foreach my $field ($fileset, $type) {
     108            unless ($field =~ $std_field) {
     109                carp "line $lineno: field $field:"
     110                   . " does not conform to $std_field: $line";
     111                next LINE;
     112            }
     113        }
     114
     115        # validate format of datetime
     116        unless ($datetime =~ $time_field) {
     117            carp "line $lineno: field $datetime:"
     118               . " does not conform to $time_field";
     119            next LINE;
     120        }
     121
     122        unless (exists $known_types{$type}) {
     123            carp "line $lineno: type $type unknown: $line";
     124            next LINE;
     125        }
     126
     127        unshift @data, DataStore::FileSet::Record->new({
     128            fileset     => $fileset,
     129            datetime    => $datetime,
     130            type        => $type,
     131        });
     132    } continue {
     133        $lineno++;
     134    }
     135
     136    return @data ? \@data : undef;
    83137}
    84138
    85 package DataStore::FileSetRecord;
     139package DataStore::FileSet::Record;
    86140
    87141use base qw( Class::Accessor::Fast );
Note: See TracChangeset for help on using the changeset viewer.