Changeset 9758
- Timestamp:
- Oct 26, 2006, 4:15:45 PM (20 years ago)
- Location:
- trunk/PS-IPP-Metadata-Config
- Files:
-
- 4 edited
-
Changes (modified) (1 diff)
-
config_grammar.txt (modified) (4 diffs)
-
lib/PS/IPP/Metadata/Config.pm (modified) (3 diffs)
-
t/05_time.t (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/PS-IPP-Metadata-Config/Changes
r9757 r9758 3 3 0.09 4 4 - fix a bug in Build.PL where a rebuilt grammar was not installed 5 - fix time tests that were dependent on MULTI times being broken 6 - fix MULTI time 7 - no longer require the 'Z' and the end of ISO8601 times 8 - implement NULL time support 5 9 6 10 0.08 Wed Oct 11 16:09:26 HST 2006 -
trunk/PS-IPP-Metadata-Config/config_grammar.txt
r9495 r9758 1 1 # Copyright (c) 2005 Joshua Hoblitt 2 2 # 3 # $Id: config_grammar.txt,v 1. 6 2006-10-12 02:08:51jhoblitt Exp $3 # $Id: config_grammar.txt,v 1.7 2006-10-27 02:15:45 jhoblitt Exp $ 4 4 5 5 { … … 146 146 $return->{comment} = $item{'comment(?)'}[0] 147 147 if $item{'comment(?)'}[0]; 148 149 if ( defined $thisparser->{local}{name}{ $item{name} } ) { 150 $return->{multi}++ 151 if $thisparser->{local}{name}{ $item{name} } =~ /MULTI/; 152 } else { 153 $thisparser->{local}{name}{ $item{name} }++; 154 } 148 155 } 149 156 … … 362 369 iso8601 363 370 | utc_epoch 371 | NULL 364 372 365 373 UT1: 366 374 iso8601 367 375 | epoch 376 | NULL 368 377 369 378 TAI: 370 379 iso8601 371 380 | epoch 381 | NULL 372 382 373 383 TT: 374 384 iso8601 375 385 | epoch 386 | NULL 376 387 377 388 iso8601: 378 389 # based on code from DateTime::Format::ISO8601 379 / \d{4} -?? \d\d -?? \d\d T?? \d\d :?? \d\d :?? \d\d (?:[\.,] (\d+))? Z /x390 / \d{4} -?? \d\d -?? \d\d T?? \d\d :?? \d\d :?? \d\d (?:[\.,] (\d+))? Z?/x 380 391 { DateTime::Format::ISO8601->parse_datetime( $item[1] ) } 381 392 … … 394 405 nsec => $2, 395 406 }} 407 NULL: 408 /NULL/ 409 { $return = "NULL" } 396 410 397 411 eofile: -
trunk/PS-IPP-Metadata-Config/lib/PS/IPP/Metadata/Config.pm
r9496 r9758 1 1 # Copyright (c) 2005 Joshua Hoblitt 2 2 # 3 # $Id: Config.pm,v 1.2 6 2006-10-12 02:09:10jhoblitt Exp $3 # $Id: Config.pm,v 1.27 2006-10-27 02:15:45 jhoblitt Exp $ 4 4 5 5 package PS::IPP::Metadata::Config; … … 49 49 # multi-symbols 50 50 $self->_merge_duplicates( $tree ) or return undef; 51 52 # translate NULL values into perl undefs (Parse::RecDescent can't return 53 # undefs, args) 54 $self->_fix_nulls( $tree ) or return undef; 51 55 52 56 #print Dumper($tree); … … 106 110 } 107 111 112 sub _fix_nulls { 113 my ( $self, $tree ) = @_; 114 115 # Iteratate through the parse tree looking for values of NULL and 116 # translating them into Perl undefs 117 for (my $i = 0; $i < @{$tree}; $i++) { 118 my $elem = $tree->[$i]; 119 120 # recurse through nested metadata 121 if ( $elem->{class} eq "metadata" ) { 122 $self->_fix_nulls( $elem->{value} ); 123 } 124 125 # force stringification of $elem->{value} -- specifically because you 126 # can't compare a DateTime object to a string value 127 if ("$elem->{value}" eq "NULL") { 128 $elem->{value} = undef; 129 } 130 } 131 132 return 1; 133 } 134 108 135 1; 109 136 -
trunk/PS-IPP-Metadata-Config/t/05_time.t
r8940 r9758 3 3 # Copyright (C) 2005 Joshua Hoblitt 4 4 # 5 # $Id: 05_time.t,v 1. 3 2006-09-25 21:49:42jhoblitt Exp $5 # $Id: 05_time.t,v 1.4 2006-10-27 02:15:45 jhoblitt Exp $ 6 6 7 7 use strict; … … 12 12 #$::RD_TRACE = 1; 13 13 14 use Test::More tests => 1 0;14 use Test::More tests => 17; 15 15 use PS::IPP::Metadata::Config; 16 16 … … 19 19 { 20 20 my $example =<<END; 21 mytime MULTI 22 mytime UTC NULL 23 mytime UT1 NULL 24 mytime TAI NULL 25 mytime TT NULL 26 END 27 28 my $config = $config_parser->parse( $example ); 29 ok( defined( $config ), "NULL times parsed"); 30 31 my $tree = [ 32 { 33 name => 'mytime', 34 class => 'time', 35 type => 'UTC', 36 value => undef, 37 }, 38 { 39 name => 'mytime', 40 class => 'time', 41 type => 'UT1', 42 value => undef, 43 }, 44 { 45 name => 'mytime', 46 class => 'time', 47 type => 'TAI', 48 value => undef, 49 }, 50 { 51 name => 'mytime', 52 class => 'time', 53 type => 'TT', 54 value => undef, 55 }, 56 ]; 57 58 is_deeply( $config, $tree, "NULL times structure" ); 59 } 60 61 { 62 my $example =<<END; 63 mytime MULTI 64 mytime UTC NULL # comment 65 mytime UT1 NULL # comment 66 mytime TAI NULL # comment 67 mytime TT NULL # comment 68 END 69 70 my $config = $config_parser->parse( $example ); 71 ok( defined( $config ), "NULL times with comments parsed"); 72 73 my $tree = [ 74 { 75 name => 'mytime', 76 class => 'time', 77 type => 'UTC', 78 value => undef, 79 comment => 'comment', 80 }, 81 { 82 name => 'mytime', 83 class => 'time', 84 type => 'UT1', 85 value => undef, 86 comment => 'comment', 87 }, 88 { 89 name => 'mytime', 90 class => 'time', 91 type => 'TAI', 92 value => undef, 93 comment => 'comment', 94 }, 95 { 96 name => 'mytime', 97 class => 'time', 98 type => 'TT', 99 value => undef, 100 comment => 'comment', 101 }, 102 ]; 103 104 is_deeply( $config, $tree, "NULL times with comments structure" ); 105 } 106 107 { 108 my $example =<<END; 109 recently MULTI 110 recently UTC 2005-03-18T16:05:00 111 recently UT1 2005-03-18T16:05:00 112 recently TAI 2005-03-18T16:05:00 113 recently TT 2005-03-18T16:05:00 114 END 115 116 my $config = $config_parser->parse( $example ); 117 ok( defined( $config ), "basic ISO8601 parsed"); 118 119 my $tree = [ 120 { 121 name => 'recently', 122 class => 'time', 123 type => 'UTC', 124 value => DateTime::Format::ISO8601->parse_datetime("2005-03-18T16:05:00Z"), 125 }, 126 { 127 name => 'recently', 128 class => 'time', 129 type => 'UT1', 130 value => DateTime::Format::ISO8601->parse_datetime("2005-03-18T16:05:00Z"), 131 }, 132 { 133 name => 'recently', 134 class => 'time', 135 type => 'TAI', 136 value => DateTime::Format::ISO8601->parse_datetime("2005-03-18T16:05:00Z"), 137 }, 138 { 139 name => 'recently', 140 class => 'time', 141 type => 'TT', 142 value => DateTime::Format::ISO8601->parse_datetime("2005-03-18T16:05:00Z"), 143 }, 144 ]; 145 146 is_deeply( $config, $tree, "basic ISO8601 structure" ); 147 } 148 149 { 150 my $example =<<END; 151 recently MULTI 21 152 recently UTC 2005-03-18T16:05:00Z 22 153 recently UT1 2005-03-18T16:05:00Z … … 24 155 recently TT 2005-03-18T16:05:00Z 25 156 END 26 my $config = $config_parser->parse( $example ); 27 ok( defined( $config ), "basic IS8601"); 28 } 29 30 { 31 my $example =<<END; 157 158 my $config = $config_parser->parse( $example ); 159 ok( defined( $config ), "basic ISO8601 w/Z parsed"); 160 161 my $tree = [ 162 { 163 name => 'recently', 164 class => 'time', 165 type => 'UTC', 166 value => DateTime::Format::ISO8601->parse_datetime("2005-03-18T16:05:00Z"), 167 }, 168 { 169 name => 'recently', 170 class => 'time', 171 type => 'UT1', 172 value => DateTime::Format::ISO8601->parse_datetime("2005-03-18T16:05:00Z"), 173 }, 174 { 175 name => 'recently', 176 class => 'time', 177 type => 'TAI', 178 value => DateTime::Format::ISO8601->parse_datetime("2005-03-18T16:05:00Z"), 179 }, 180 { 181 name => 'recently', 182 class => 'time', 183 type => 'TT', 184 value => DateTime::Format::ISO8601->parse_datetime("2005-03-18T16:05:00Z"), 185 }, 186 ]; 187 188 is_deeply( $config, $tree, "basic ISO8601 w/Z structure" ); 189 } 190 191 { 192 my $example =<<END; 193 recently MULTI 32 194 recently UTC 2005-03-18T16:05:00.000001Z 33 195 recently UT1 2005-03-18T16:05:00.000001Z … … 36 198 END 37 199 my $config = $config_parser->parse( $example ); 38 ok( defined( $config ), "basic IS8601 with fractional seconds"); 39 } 40 41 { 42 my $example =<<END; 200 ok( defined( $config ), "basic IS8601 with fractional seconds parsed"); 201 } 202 203 { 204 my $example =<<END; 205 recently MULTI 43 206 recently UTC 2005-03-18T16:05:00Z # foo 44 207 recently UT1 2005-03-18T16:05:00Z # bar … … 47 210 END 48 211 my $config = $config_parser->parse( $example ); 49 ok( defined( $config ), "ISO8601 with comments"); 50 } 51 52 { 53 my $example =<<END; 212 ok( defined( $config ), "ISO8601 with comments parsed"); 213 } 214 215 { 216 my $example =<<END; 217 recently MULTI 54 218 recently UTC 2005-03-18T16:05:00.000001Z # foo 55 219 recently UT1 2005-03-18T16:05:00.000001Z # bar … … 58 222 END 59 223 my $config = $config_parser->parse( $example ); 60 ok( defined( $config ), "ISO8601 with comments and fractional seconds"); 61 } 62 63 { 64 my $example =<<END; 224 ok( defined( $config ), "ISO8601 with comments and fractional seconds parsed"); 225 } 226 227 diag("epoch time format maybe deprecated"); 228 229 { 230 my $example =<<END; 231 recently MULTI 65 232 recently UTC 123456, 5000, 1 66 233 recently UT1 123456, 5000 … … 69 236 END 70 237 my $config = $config_parser->parse( $example ); 71 ok( defined( $config ), "basic epoch time"); 72 } 73 74 { 75 my $example =<<END; 238 ok( defined( $config ), "basic epoch time parsed"); 239 } 240 241 { 242 my $example =<<END; 243 recently MULTI 76 244 recently UTC 123456, 5000, 1 # foo 77 245 recently UT1 123456, 5000 # bar … … 80 248 END 81 249 my $config = $config_parser->parse( $example ); 82 ok( defined( $config ), "epoch time with comments ");83 } 84 85 { 86 my $example =<<END; 87 broken UTC 2005-03-18 T16:05:0088 END 89 my $config = $config_parser->parse( $example ); 90 ok( !defined( $config ), "bad format"); 91 } 92 93 { 94 my $example =<<END; 95 broken UT1 2005-03-18 T16:05:0096 END 97 my $config = $config_parser->parse( $example ); 98 ok( !defined( $config ), "bad format"); 99 } 100 101 { 102 my $example =<<END; 103 broken TAI 2005-03-18 T16:05:00104 END 105 my $config = $config_parser->parse( $example ); 106 ok( !defined( $config ), "bad format"); 107 } 108 109 { 110 my $example =<<END; 111 broken TT 2005-03-18 T16:05:00112 END 113 my $config = $config_parser->parse( $example ); 114 ok( !defined( $config ), "bad format"); 115 } 250 ok( defined( $config ), "epoch time with comments parsed"); 251 } 252 253 { 254 my $example =<<END; 255 broken UTC 2005-03-18 16:05:00 256 END 257 my $config = $config_parser->parse( $example ); 258 ok( !defined( $config ), "bad format"); 259 } 260 261 { 262 my $example =<<END; 263 broken UT1 2005-03-18 16:05:00 264 END 265 my $config = $config_parser->parse( $example ); 266 ok( !defined( $config ), "bad format"); 267 } 268 269 { 270 my $example =<<END; 271 broken TAI 2005-03-18 16:05:00 272 END 273 my $config = $config_parser->parse( $example ); 274 ok( !defined( $config ), "bad format"); 275 } 276 277 { 278 my $example =<<END; 279 broken TT 2005-03-18 16:05:00 280 END 281 my $config = $config_parser->parse( $example ); 282 ok( !defined( $config ), "bad format"); 283 }
Note:
See TracChangeset
for help on using the changeset viewer.
