Skip to content

Commit

Permalink
add directory method
Browse files Browse the repository at this point in the history
  • Loading branch information
dwarring committed Sep 23, 2021
1 parent 7b5f40c commit fe4031e
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
2 changes: 1 addition & 1 deletion META6.json
Expand Up @@ -3,7 +3,7 @@
"raku" : "6.*",
"name" : "URI",
"license" : "Artistic-2.0",
"version" : "0.3.2",
"version" : "0.3.3",
"description" : "A URI implementation using Raku grammars to implement RFC 3986 BNF",
"license" : "Artistic-2.0",
"depends" : [ ],
Expand Down
13 changes: 10 additions & 3 deletions lib/URI.rakumod
@@ -1,7 +1,7 @@
use URI::Path;
use URI::Query;

unit class URI:auth<github:perl6-community-modules>:ver<v0.3.2>;
unit class URI:auth<github:raku-community-modules>:ver<v0.3.3>;

use IETF::RFC_Grammar;
use IETF::RFC_Grammar::URI;
Expand Down Expand Up @@ -300,7 +300,6 @@ multi method path(URI:D: Str() $path --> Path:D ) {
source => self!gister(:$path),
);


$!path = Path.new($comp);
}
else {
Expand Down Expand Up @@ -353,7 +352,15 @@ method relative is DEPRECATED {
}

method is-absolute { so ($!scheme || $.host) }
method is-relative { ! so ($!scheme || $.host) }
method is-relative { ! $.is-absolute }

method directory(URI:D:) {
my Str $dir = $!path.Str;
$dir .= subst(/<- [/]>*$/, '');
$dir ||= self.is-absolute ?? '/' !! './';
my Path $path = self.path($dir);
self.clone: :$path;
}

method rel2abs(URI:D: URI:D $base --> URI:D) {
if $.is-absolute {
Expand Down
18 changes: 18 additions & 0 deletions t/directory.t
@@ -0,0 +1,18 @@
use v6;
use Test;
use URI;

plan 8;

sub dir(Str $u --> URI:D) {
URI.new($u).directory;
}

is dir("ccc"), "./";
is dir("/ccc"), "/";
is dir("/ccc/"), "/ccc/";
is dir("ccc/"), "ccc/";
is dir("path/doc.html"), "path/";
is dir("https://mysite.com"), "https://mysite.com/";
is dir("https://mysite.com/"), "https://mysite.com/";
is dir("https://mysite.com/path/doc.html"), "https://mysite.com/path/";

0 comments on commit fe4031e

Please sign in to comment.