Changeset 6474
- Timestamp:
- Feb 23, 2006, 4:51:31 PM (20 years ago)
- Location:
- trunk/DataStore
- Files:
-
- 1 added
- 1 edited
-
lib/DataStore/FileSet/Parser.pm (modified) (3 diffs)
-
t/02_fileset_parse.t (added)
Legend:
- Unmodified
- Added
- Removed
-
trunk/DataStore/lib/DataStore/FileSet/Parser.pm
r6473 r6474 1 1 # Copyright (C) 2006 Joshua Hoblitt 2 2 # 3 # $Id: Parser.pm,v 1. 1 2006-02-24 00:52:14jhoblitt Exp $3 # $Id: Parser.pm,v 1.2 2006-02-24 02:51:31 jhoblitt Exp $ 4 4 5 5 package DataStore::FileSet::Parser; … … 13 13 use Carp qw( carp ); 14 14 use Params::Validate qw( validate_pos SCALAR); 15 16 my $time_field = qr/^ (\d{4})-(\d\d)-(\d\d) T (\d\d):(\d\d):(\d\d) Z $/x; 17 my $std_field = qr/^[a-z0-9-_.]+$/; 18 #my %known_types = map { $_ => 1 } qw( OBJECT DOMEFLAT SKYFLAT BIAS DARK ); 19 my %known_types = map { $_ => 1 } qw( object domeflat skyflat bias dark ); 15 20 16 21 =pod … … 80 85 ); 81 86 82 # @ = qw( OBJECT DOMEFLAT SKYFLAT BIAS DARK ); 87 my @data; 88 my $lineno = 1; 89 LINE: 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; 83 137 } 84 138 85 package DataStore::FileSet Record;139 package DataStore::FileSet::Record; 86 140 87 141 use base qw( Class::Accessor::Fast );
Note:
See TracChangeset
for help on using the changeset viewer.
