Changeset 6487
- Timestamp:
- Feb 24, 2006, 2:09:28 PM (20 years ago)
- Location:
- trunk/DataStore
- Files:
-
- 1 added
- 2 edited
-
MANIFEST (modified) (1 diff)
-
lib/DataStore/File/Parser.pm (modified) (6 diffs)
-
t/03_file_parse.t (added)
Legend:
- Unmodified
- Added
- Removed
-
trunk/DataStore/MANIFEST
r6475 r6487 10 10 t/00_distribution.t 11 11 t/01_load.t 12 t/03_file_parse.t -
trunk/DataStore/lib/DataStore/File/Parser.pm
r6476 r6487 1 1 # Copyright (C) 2006 Joshua Hoblitt 2 2 # 3 # $Id: Parser.pm,v 1. 2 2006-02-24 03:19:28jhoblitt Exp $3 # $Id: Parser.pm,v 1.3 2006-02-25 00:09:10 jhoblitt Exp $ 4 4 5 5 package DataStore::File::Parser; … … 15 15 16 16 my $std_field = qr/^[a-z0-9-_.]+$/; 17 my $byte_field = qr/^\d+$/; 18 my $md5_field = qr/^[0-9a-f]{32}$/; 17 19 my %known_types = map { $_ => 1 } qw( chip ); 18 20 … … 100 102 } 101 103 102 # fields are not allowed to contain #104 # fields are not allowed to contain \# 103 105 foreach my $field (@fields) { 104 106 if ($field =~ /\#/) { … … 110 112 my ($fileid, $bytes, $md5sum, $type) = @fields; 111 113 112 # validate format of file d and type114 # validate format of fileid and type 113 115 foreach my $field ($fileid, $type) { 114 116 unless ($field =~ $std_field) { … … 120 122 121 123 # 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 } 122 129 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({ 136 139 fileid => $fileid, 137 140 bytes => $bytes, … … 152 155 use vars qw( @BASE_FIELDS ); 153 156 154 @BASE_FIELDS = qw( filed bytes md5sum type ); 157 @BASE_FIELDS = qw( fileid bytes md5sum type ); 158 159 __PACKAGE__->mk_accessors(@BASE_FIELDS); 155 160 156 161 1;
Note:
See TracChangeset
for help on using the changeset viewer.
