From 95134d49a4d5e168ad17244bbcfd9927cf684cf4 Mon Sep 17 00:00:00 2001 From: Carl Masak Date: Tue, 2 Feb 2010 09:59:35 +0100 Subject: [PATCH] [URI] renamed to November::URI To avoid a name collision between the november project and the uri project. --- lib/November/CGI.pm | 6 +++--- lib/{ => November}/URI.pm | 21 ++++++++++++++------- lib/{ => November}/URI/Grammar.pm | 2 +- t/integration/01-view_page.t | 4 ++-- t/uri/01.t | 18 +++++++++--------- 5 files changed, 29 insertions(+), 22 deletions(-) rename lib/{ => November}/URI.pm (74%) rename lib/{ => November}/URI/Grammar.pm (96%) diff --git a/lib/November/CGI.pm b/lib/November/CGI.pm index 715d196..fce6bf7 100644 --- a/lib/November/CGI.pm +++ b/lib/November/CGI.pm @@ -1,11 +1,11 @@ use v6; -use URI; +use November::URI; class November::CGI { has %.params; has %.cookie; has @.keywords; - has URI $.uri; + has November::URI $.uri; has $!crlf = "\x[0D]\x[0A]"; @@ -38,7 +38,7 @@ class November::CGI { $uri_str ~= ':' ~ %*ENV if %*ENV; $uri_str ~= %*ENV ?? %*ENV !! %*ENV; - $!uri = URI.new( uri => $uri_str ); + $!uri = November::URI.new( uri => $uri_str ); } # For debugging diff --git a/lib/URI.pm b/lib/November/URI.pm similarity index 74% rename from lib/URI.pm rename to lib/November/URI.pm index 38680ee..fc75b5e 100644 --- a/lib/URI.pm +++ b/lib/November/URI.pm @@ -1,6 +1,13 @@ -class URI; +class November::URI; -use URI::Grammar; +# This class used to be called just 'URI', but there was a collision with +# the eponymous class in the 'uri' project. Arguably, that class has more +# rights to that name, so this one was renamed. Since the 'uri' project +# ought to cover the same functionality as this class, maybe long-term we +# could switch to using that instead. One more dependency, but less code +# duplication across projects. + +use November::URI::Grammar; # RAKUDO: Match object does not do assignment properly :( #my Match $.parts; dies in init with 'Type mismatch in assignment'; # workaround: @@ -14,7 +21,7 @@ submethod BUILD(:$uri) { $c_str .= subst(/^ \s* ['<' | '"'] /, ''); $c_str .= subst(/ ['>' | '"'] \s* $/, ''); - URI::Grammar.parse($c_str); + November::URI::Grammar.parse($c_str); unless $/ { die "Could not parse URI: $uri" } $!uri = $/; @@ -84,13 +91,13 @@ method Str() { =head NAME -URI — Uniform Resource Identifiers (absolute and relative) +November::URI — Uniform Resource Identifiers (absolute and relative) =head SYNOPSYS - use URI; - my $u = URI.new; - $u.init('http://her.com/foo/bar?tag=woow#bla'); + use November::URI; + my $u = November::URI.new; + $u.init('http://example.com/foo/bar?tag=woow#bla'); my $scheme = $u.scheme; my $authority = $u.authority; diff --git a/lib/URI/Grammar.pm b/lib/November/URI/Grammar.pm similarity index 96% rename from lib/URI/Grammar.pm rename to lib/November/URI/Grammar.pm index 9a6e70d..6adadc7 100644 --- a/lib/URI/Grammar.pm +++ b/lib/November/URI/Grammar.pm @@ -1,5 +1,5 @@ use v6; -grammar URI::Grammar { +grammar November::URI::Grammar { token TOP { ^ [ ':']? [ '//' ]? ['?' ]? ['#' ]? $ }; token scheme { <-[:/&?#]>+ }; token authority { [':' ]? }; diff --git a/t/integration/01-view_page.t b/t/integration/01-view_page.t index 11edfd9..da908d8 100644 --- a/t/integration/01-view_page.t +++ b/t/integration/01-view_page.t @@ -4,7 +4,7 @@ use Test; use November; use Test::CGI; use November::Config; -use URI; +use November::URI; my @markups = < Text::Markup::Wiki::MediaWiki >; my @skins = < CleanAndSoft >; @@ -26,7 +26,7 @@ for @markups X @skins -> $m, $s { my $c = November::Config.new( markup => $m, skin => $s ); my $w = November.new( config => $c ); for %gets.kv -> $page, $description { - my $uri = URI.new( 'http://testserver' ~ $page ); + my $uri = November::URI.new( 'http://testserver' ~ $page ); my $cgi = Test::CGI.new( uri => $uri ); $cgi.parse_params( $page ); lives_ok( { $w.handle_request( $cgi ) }, "$m, $s, $description" ); diff --git a/t/uri/01.t b/t/uri/01.t index 10a7a8c..302ee57 100644 --- a/t/uri/01.t +++ b/t/uri/01.t @@ -2,10 +2,10 @@ use v6; use Test; plan 28; -use URI; +use November::URI; ok(1,'We use URI and we are still alive'); -my $u = URI.new(uri => 'http://example.com:80/about/us?foo#bar'); +my $u = November::URI.new(uri => 'http://example.com:80/about/us?foo#bar'); is($u.scheme, 'http', 'scheme'); is($u.host, 'example.com', 'host'); @@ -20,20 +20,20 @@ is($u.chunks[1], 'us', 'second chunk'); is( ~$u, 'http://example.com:80/about/us?foo#bar', 'Complete path stringification'); -$u = URI.new(uri => 'https://eXAMplE.COM'); +$u = November::URI.new(uri => 'https://eXAMplE.COM'); is($u.scheme, 'https', 'scheme'); is($u.host, 'example.com', 'host'); is( "$u", 'https://example.com', 'https://eXAMplE.COM stringifies to https://example.com'); -$u = URI.new(uri => '/foo/bar/baz'); +$u = November::URI.new(uri => '/foo/bar/baz'); is($u.chunks, 'foo bar baz', 'chunks from absolute path'); ok($u.absolute, 'absolute path'); nok($u.relative, 'not relative path'); -$u = URI.new(uri => 'foo/bar/baz'); +$u = November::URI.new(uri => 'foo/bar/baz'); is($u.chunks, 'foo bar baz', 'chunks from relative path'); ok( $u.relative, 'relative path'); @@ -43,17 +43,17 @@ is($u.chunks[0], 'foo', 'first chunk'); is($u.chunks[1], 'bar', 'second chunk'); is($u.chunks[*-1], 'baz', 'last chunk'); -$u = URI.new(uri => 'http://foo.com'); +$u = November::URI.new(uri => 'http://foo.com'); ok($u.chunks.list.perl eq '[""]', ".chunks return [''] for empty path"); ok($u.absolute, 'http://foo.com has an absolute path'); nok($u.relative, 'http://foo.com does not have a relative path'); -# test URI parsing with <> or "" and spaces -$u = URI.new(uri => " "); +# test November::URI parsing with <> or "" and spaces +$u = November::URI.new(uri => " "); is("$u", 'http://foo.com', '<> removed from str'); -$u = URI.new(uri => ' "http://foo.com"'); +$u = November::URI.new(uri => ' "http://foo.com"'); is("$u", 'http://foo.com', '"" removed from str');