Changeset 6497
- Timestamp:
- Feb 24, 2006, 6:48:25 PM (20 years ago)
- Location:
- trunk/DataStore
- Files:
-
- 2 edited
-
lib/DataStore/FileSet/Parser.pm (modified) (6 diffs)
-
t/02_fileset_parse.t (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/DataStore/lib/DataStore/FileSet/Parser.pm
r6489 r6497 1 1 # Copyright (C) 2006 Joshua Hoblitt 2 2 # 3 # $Id: Parser.pm,v 1. 4 2006-02-25 00:11:19jhoblitt Exp $3 # $Id: Parser.pm,v 1.5 2006-02-25 04:48:25 jhoblitt Exp $ 4 4 5 5 package DataStore::FileSet::Parser; … … 11 11 $VERSION = '0.01'; 12 12 13 use base qw( Class::Accessor::Fast ); 14 13 15 use Carp qw( carp ); 14 use Params::Validate qw( validate_pos SCALAR); 16 use Data::Validate::URI qw( is_http_uri ); 17 use Params::Validate qw( validate validate_pos SCALAR); 15 18 16 19 my $time_field = qr/^ (\d{4})-(\d\d)-(\d\d) T (\d\d):(\d\d):(\d\d) Z $/x; … … 18 21 #my %known_types = map { $_ => 1 } qw( OBJECT DOMEFLAT SKYFLAT BIAS DARK ); 19 22 my %known_types = map { $_ => 1 } qw( object domeflat skyflat bias dark ); 23 24 __PACKAGE__->mk_ro_accessors(qw(base_uri)); 20 25 21 26 =pod … … 58 63 my $class = shift; 59 64 60 my $self = bless {}, ref $class || $class; 65 my %p = validate(@_, 66 { 67 base_uri => { 68 type => SCALAR, 69 callbacks => { 70 'is valid http uri' => sub { is_http_uri($_[0]) }, 71 'uri ends with /' => sub { $_[0] =~ m|/$| }, 72 }, 73 default => 'http://example.org/', 74 }, 75 }, 76 ); 77 78 my $self = bless \%p, ref $class || $class; 61 79 62 80 return $self; 63 81 } 64 65 82 66 83 =back … … 138 155 datetime => $datetime, 139 156 type => $type, 157 uri => $self->base_uri . $fileset, 140 158 }); 141 159 } continue { … … 152 170 use vars qw( @BASE_FIELDS ); 153 171 154 @BASE_FIELDS = qw( fileset datetime type );172 @BASE_FIELDS = qw( fileset datetime type uri ); 155 173 156 174 __PACKAGE__->mk_accessors(@BASE_FIELDS); -
trunk/DataStore/t/02_fileset_parse.t
r6491 r6497 3 3 # Copyright (C) 2006 Joshua Hoblitt 4 4 # 5 # $Id: 02_fileset_parse.t,v 1. 3 2006-02-25 00:13:36jhoblitt Exp $5 # $Id: 02_fileset_parse.t,v 1.4 2006-02-25 04:48:25 jhoblitt Exp $ 6 6 7 7 use strict; … … 10 10 use lib qw( ./lib ./t ); 11 11 12 use Test::More tests => 38;12 use Test::More tests => 42; 13 13 use Test::Warn; 14 14 … … 114 114 otis0123456|2006-01-01T00:03:04Z|object|11:00:10.33 68:26:59.6 2000|30.0 |r|1.23 | 115 115 END 116 my $results = DataStore::FileSet::Parser->new->parse($example1); 116 my $parser = DataStore::FileSet::Parser->new( 117 base_uri => 'http://foo.com/' 118 ); 119 my $results = $parser->parse($example1); 117 120 118 121 is(scalar @$results, 4, "correct number of item returned"); … … 122 125 is(@$results[0]->datetime, '2006-01-01T00:03:04Z', 'correct datetime'); 123 126 is(@$results[0]->type, 'object', 'correct type'); 127 is(@$results[0]->uri, 'http://foo.com/otis0123456', 'correct uri'); 124 128 125 129 isa_ok(@$results[1], 'DataStore::FileSet::Record'); … … 127 131 is(@$results[1]->datetime, '2006-01-01T00:03:04Z', 'correct datetime'); 128 132 is(@$results[1]->type, 'object', 'correct type'); 133 is(@$results[1]->uri, 'http://foo.com/otis0123456', 'correct uri'); 129 134 130 135 isa_ok(@$results[2], 'DataStore::FileSet::Record'); … … 132 137 is(@$results[2]->datetime, '2006-01-01T00:03:04Z', 'correct datetime'); 133 138 is(@$results[2]->type, 'object', 'correct type'); 139 is(@$results[2]->uri, 'http://foo.com/otis0123456', 'correct uri'); 134 140 135 141 isa_ok(@$results[3], 'DataStore::FileSet::Record'); … … 137 143 is(@$results[3]->datetime, '2006-01-01T00:03:04Z', 'correct datetime'); 138 144 is(@$results[3]->type, 'object', 'correct type'); 145 is(@$results[3]->uri, 'http://foo.com/otis0123456', 'correct uri'); 139 146 } 140 147
Note:
See TracChangeset
for help on using the changeset viewer.
