IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 16203 for trunk/Nebulous/lib


Ignore:
Timestamp:
Jan 23, 2008, 12:27:51 PM (18 years ago)
Author:
jhoblitt
Message:

add Nebulous::Util::parse_neb_key()

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Nebulous/lib/Nebulous/Util.pm

    r13302 r16203  
    11# Copyright (c) 2004  Joshua Hoblitt
    22#
    3 # $Id: Util.pm,v 1.7 2007-05-08 02:27:42 jhoblitt Exp $
     3# $Id: Util.pm,v 1.8 2008-01-23 22:27:51 jhoblitt Exp $
    44
    55package Nebulous::Util;
     
    1212use base qw( Exporter );
    1313
     14use File::Spec::Functions;
    1415use Log::Log4perl qw( :levels );
    1516use URI::file;
     
    2223    _get_filehandle
    2324    _open_uri
     25    parse_neb_key
    2426);
    2527
     
    7880}
    7981
     82sub parse_neb_key
     83{
     84    my $text = shift;
     85
     86    # white space is not allowed
     87    if ($text =~ qr/\s+/) {
     88        die "keys and URIs may not contain whitespace";
     89    }
     90
     91    my $uri = URI->new($text);
     92    my $scheme = $uri->scheme;
     93    my $path = $uri->opaque;
     94   
     95    my $volume;
     96    # if this is a valid uri
     97    if (defined $scheme) {
     98        # if so, does it use the neb scheme?
     99        die "URI does not use the 'neb' scheme"
     100            unless $scheme eq 'neb';
     101
     102        # neb:path (not allowed)
     103        # neb://<volume name>/...
     104        # neb:/path... (leading '/' is stripped)
     105        # neb:///path... (same as neb:/path)
     106
     107        # volume specifier must be at least one character
     108        # strip off volume component if it exists
     109        $path =~ s|^//([^/]+)||;
     110        $volume = $1;
     111
     112        # require a leading slash if there is no volume name
     113        if ((not defined $volume) and (not $path =~ m|^/|)) {
     114            die "neb URI scheme requires a leading slash, eg. neb:/";
     115        }
     116    }
     117
     118    # strip leading slashes
     119    $path =~ s|^/+||;
     120
     121    # remove multiple /'s and trailing slashes
     122    $path = canonpath($path);
     123
     124    return ($path, $volume);
     125}
     126
    801271;
    81128
Note: See TracChangeset for help on using the changeset viewer.