From c0d52b7c34ce2889944cce5a92e949488ff47234 Mon Sep 17 00:00:00 2001
From: Patrick Spek
Date: Tue, 9 Apr 2019 20:27:30 +0200
Subject: Add methods to add query and path parts
---
lib/URL.pm6 | 32 ++++++++++++++++++++++++++++++--
lib/URL/Grammar.pm6 | 2 +-
lib/URL/Grammar/Actions.pm6 | 2 +-
3 files changed, 32 insertions(+), 4 deletions(-)
(limited to 'lib')
diff --git a/lib/URL.pm6 b/lib/URL.pm6
index 57235b4..fa9ebc8 100644
--- a/lib/URL.pm6
+++ b/lib/URL.pm6
@@ -25,7 +25,7 @@ multi method new (
samewith(
|%match,
- path => %match.list
+ path => %match.list,
);
}
@@ -51,6 +51,34 @@ multi method new (
);
}
+#| Append one or more parts to the path of the URL.
+method add-path (
+ *@parts,
+
+ --> URL
+) {
+ return self.new(|self.Hash) unless @parts;
+
+ self.new(
+ |self.Hash,
+ path => [|@!path, |@parts],
+ );
+}
+
+#| Append one or more query parameters to the URL.
+method add-query (
+ *%parts,
+
+ --> URL
+) {
+ return self.new(|self.Hash) unless %parts;
+
+ self.new(
+ |self.Hash,
+ query => %(|%!query, |%parts),
+ );
+}
+
method Hash (
--> Hash
) {
@@ -111,7 +139,7 @@ multi method Str (
=NAME URL
=AUTHOR Patrick Spek
-=VERSION 0.1.0
+=VERSION 0.2.0
=head1 Synopsis
diff --git a/lib/URL/Grammar.pm6 b/lib/URL/Grammar.pm6
index cc9f13c..2f5cd45 100644
--- a/lib/URL/Grammar.pm6
+++ b/lib/URL/Grammar.pm6
@@ -33,7 +33,7 @@ token fragment { <-[ \s ]>+ }
=NAME URL::Grammar
=AUTHOR Patrick Spek
-=VERSION 0.1.0
+=VERSION 0.2.0
=head1 Synopsis
diff --git a/lib/URL/Grammar/Actions.pm6 b/lib/URL/Grammar/Actions.pm6
index 2015073..2ef70bb 100644
--- a/lib/URL/Grammar/Actions.pm6
+++ b/lib/URL/Grammar/Actions.pm6
@@ -32,7 +32,7 @@ method fragment ($/) { make ~$/ }
=NAME URL::Grammar::Actions
=AUTHOR Patrick Spek
-=VERSION 0.1.0
+=VERSION 0.2.0
=head1 Synopsis
--
cgit v1.1