Changeset 16203 for trunk/Nebulous/lib
- Timestamp:
- Jan 23, 2008, 12:27:51 PM (18 years ago)
- File:
-
- 1 edited
-
trunk/Nebulous/lib/Nebulous/Util.pm (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Nebulous/lib/Nebulous/Util.pm
r13302 r16203 1 1 # Copyright (c) 2004 Joshua Hoblitt 2 2 # 3 # $Id: Util.pm,v 1. 7 2007-05-08 02:27:42jhoblitt Exp $3 # $Id: Util.pm,v 1.8 2008-01-23 22:27:51 jhoblitt Exp $ 4 4 5 5 package Nebulous::Util; … … 12 12 use base qw( Exporter ); 13 13 14 use File::Spec::Functions; 14 15 use Log::Log4perl qw( :levels ); 15 16 use URI::file; … … 22 23 _get_filehandle 23 24 _open_uri 25 parse_neb_key 24 26 ); 25 27 … … 78 80 } 79 81 82 sub 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 80 127 1; 81 128
Note:
See TracChangeset
for help on using the changeset viewer.
