IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 6497


Ignore:
Timestamp:
Feb 24, 2006, 6:48:25 PM (20 years ago)
Author:
jhoblitt
Message:

add DataStore::FileSet::Parser->new( base_uri => ... )
add DataStore::FileSet::Parser->base_uri()
add DataStore::FileSet::Record->uri()

Location:
trunk/DataStore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/DataStore/lib/DataStore/FileSet/Parser.pm

    r6489 r6497  
    11# Copyright (C) 2006  Joshua Hoblitt
    22#
    3 # $Id: Parser.pm,v 1.4 2006-02-25 00:11:19 jhoblitt Exp $
     3# $Id: Parser.pm,v 1.5 2006-02-25 04:48:25 jhoblitt Exp $
    44
    55package DataStore::FileSet::Parser;
     
    1111$VERSION = '0.01';
    1212
     13use base qw( Class::Accessor::Fast );
     14
    1315use Carp qw( carp );
    14 use Params::Validate qw( validate_pos SCALAR);
     16use Data::Validate::URI qw( is_http_uri );
     17use Params::Validate qw( validate validate_pos SCALAR);
    1518
    1619my $time_field = qr/^ (\d{4})-(\d\d)-(\d\d) T (\d\d):(\d\d):(\d\d) Z $/x;
     
    1821#my %known_types = map { $_ => 1 } qw( OBJECT DOMEFLAT SKYFLAT BIAS DARK );
    1922my %known_types = map { $_ => 1 } qw( object domeflat skyflat bias dark );
     23
     24__PACKAGE__->mk_ro_accessors(qw(base_uri));
    2025
    2126=pod
     
    5863    my $class = shift;
    5964
    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;
    6179
    6280    return $self;
    6381}
    64 
    6582
    6683=back
     
    138155            datetime    => $datetime,
    139156            type        => $type,
     157            uri         => $self->base_uri . $fileset,
    140158        });
    141159    } continue {
     
    152170use vars qw( @BASE_FIELDS );
    153171
    154 @BASE_FIELDS = qw( fileset datetime type );
     172@BASE_FIELDS = qw( fileset datetime type uri );
    155173
    156174__PACKAGE__->mk_accessors(@BASE_FIELDS);
  • trunk/DataStore/t/02_fileset_parse.t

    r6491 r6497  
    33# Copyright (C) 2006  Joshua Hoblitt
    44#
    5 # $Id: 02_fileset_parse.t,v 1.3 2006-02-25 00:13:36 jhoblitt Exp $
     5# $Id: 02_fileset_parse.t,v 1.4 2006-02-25 04:48:25 jhoblitt Exp $
    66
    77use strict;
     
    1010use lib qw( ./lib ./t );
    1111
    12 use Test::More tests => 38;
     12use Test::More tests => 42;
    1313use Test::Warn;
    1414
     
    114114otis0123456|2006-01-01T00:03:04Z|object|11:00:10.33 68:26:59.6 2000|30.0 |r|1.23   |
    115115END
    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);
    117120
    118121    is(scalar @$results, 4, "correct number of item returned");
     
    122125    is(@$results[0]->datetime, '2006-01-01T00:03:04Z', 'correct datetime');
    123126    is(@$results[0]->type, 'object', 'correct type');
     127    is(@$results[0]->uri, 'http://foo.com/otis0123456', 'correct uri');
    124128
    125129    isa_ok(@$results[1], 'DataStore::FileSet::Record');
     
    127131    is(@$results[1]->datetime, '2006-01-01T00:03:04Z', 'correct datetime');
    128132    is(@$results[1]->type, 'object', 'correct type');
     133    is(@$results[1]->uri, 'http://foo.com/otis0123456', 'correct uri');
    129134
    130135    isa_ok(@$results[2], 'DataStore::FileSet::Record');
     
    132137    is(@$results[2]->datetime, '2006-01-01T00:03:04Z', 'correct datetime');
    133138    is(@$results[2]->type, 'object', 'correct type');
     139    is(@$results[2]->uri, 'http://foo.com/otis0123456', 'correct uri');
    134140
    135141    isa_ok(@$results[3], 'DataStore::FileSet::Record');
     
    137143    is(@$results[3]->datetime, '2006-01-01T00:03:04Z', 'correct datetime');
    138144    is(@$results[3]->type, 'object', 'correct type');
     145    is(@$results[3]->uri, 'http://foo.com/otis0123456', 'correct uri');
    139146}
    140147
Note: See TracChangeset for help on using the changeset viewer.