IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 6487


Ignore:
Timestamp:
Feb 24, 2006, 2:09:28 PM (20 years ago)
Author:
jhoblitt
Message:

complete first pass implimentation of DataStore::File::Parser

Location:
trunk/DataStore
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/DataStore/MANIFEST

    r6475 r6487  
    1010t/00_distribution.t
    1111t/01_load.t
     12t/03_file_parse.t
  • trunk/DataStore/lib/DataStore/File/Parser.pm

    r6476 r6487  
    11# Copyright (C) 2006  Joshua Hoblitt
    22#
    3 # $Id: Parser.pm,v 1.2 2006-02-24 03:19:28 jhoblitt Exp $
     3# $Id: Parser.pm,v 1.3 2006-02-25 00:09:10 jhoblitt Exp $
    44
    55package DataStore::File::Parser;
     
    1515
    1616my $std_field = qr/^[a-z0-9-_.]+$/;
     17my $byte_field = qr/^\d+$/;
     18my $md5_field = qr/^[0-9a-f]{32}$/;
    1719my %known_types = map { $_ => 1 } qw( chip );
    1820
     
    100102        }
    101103
    102         # fields are not allowed to contain #
     104        # fields are not allowed to contain \#
    103105        foreach my $field (@fields) {
    104106            if ($field =~ /\#/) {
     
    110112        my ($fileid, $bytes, $md5sum, $type) = @fields;
    111113
    112         # validate format of filed and type
     114        # validate format of fileid and type
    113115        foreach my $field ($fileid, $type) {
    114116            unless ($field =~ $std_field) {
     
    120122
    121123        # validate format of bytes
     124        unless ($bytes =~ $byte_field) {
     125            carp "line $lineno: field $bytes:"
     126               . " does not conform to $byte_field: $line";
     127            next LINE;
     128        }
    122129
    123         # validate format of md5sum
    124 #        unless ($datetime =~ $time_field) {
    125 #            carp "line $lineno: field $datetime:"
    126 #               . " does not conform to $time_field";
    127 #            next LINE;
    128 #        }
    129 #
    130 #        unless (exists $known_types{$type}) {
    131 #            carp "line $lineno: type $type unknown: $line";
    132 #            next LINE;
    133 #        }
    134 #
    135         unshift @data, DataStore::File::Record->new({
     130        # validate format of md5sum, hex encoded
     131        unless ($md5sum =~ $md5_field) {
     132            carp "line $lineno: field $md5sum:"
     133               . " does not conform to $md5_field: $line";
     134            next LINE;
     135        }
     136
     137        # lifo 
     138        push @data, DataStore::File::Record->new({
    136139            fileid  => $fileid,
    137140            bytes   => $bytes,
     
    152155use vars qw( @BASE_FIELDS );
    153156
    154 @BASE_FIELDS = qw( filed bytes md5sum type );
     157@BASE_FIELDS = qw( fileid bytes md5sum type );
     158
     159__PACKAGE__->mk_accessors(@BASE_FIELDS);
    155160
    1561611;
Note: See TracChangeset for help on using the changeset viewer.