Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Look ma - no November::URI. Seems to be working with the URI module b…

…ut in early stages of testing with more work to do.
  • Loading branch information...
commit 8795df43a5ea8bc6bb8ab669d2d53a9dd8ffade5 1 parent b79c3ea
Ron Schmidt authored
View
4 lib/November.pm
@@ -46,8 +46,8 @@ class November does November::Session does November::Cache {
['all'], { self.list_all_pages },
];
- my @chunks = $cgi.uri.chunks.list;
- $d.dispatch(@chunks);
+ my @segments = $cgi.uri.segments.list;
+ $d.dispatch(@segments);
}
# RAKUDO: Should `is rw` work with constant defaults? (It doesn't.)
View
6 lib/November/CGI.pm
@@ -1,11 +1,11 @@
use v6;
-use November::URI;
+use URI;
class November::CGI {
has %.params;
has %.cookie;
has @.keywords;
- has November::URI $.uri;
+ has URI $.uri;
has $!crlf = "\x[0D]\x[0A]";
@@ -38,7 +38,7 @@ class November::CGI {
$uri_str ~= ':' ~ %*ENV<SERVER_PORT> if %*ENV<SERVER_PORT>;
$uri_str ~= %*ENV<MODPERL6> ?? %*ENV<PATH_INFO> !! %*ENV<REQUEST_URI>;
- $!uri = November::URI.new( uri => $uri_str );
+ $!uri = URI.new( $uri_str );
}
# For debugging
View
120 lib/November/URI.pm
@@ -1,120 +0,0 @@
-class November::URI;
-
-# 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:
-has $.uri;
-has @.chunks;
-
-submethod BUILD(:$uri) {
-
- # clear string before parsing
- my $c_str = $uri;
- $c_str .= subst(/^ \s* ['<' | '"'] /, '');
- $c_str .= subst(/ ['>' | '"'] \s* $/, '');
-
- November::URI::Grammar.parse($c_str);
- unless $/ { die "Could not parse URI: $uri" }
-
- $!uri = $/;
- @!chunks = @($<path><chunk>) || ('');
-}
-
-method scheme {
- my $s = $.uri<scheme> || '';
- # RAKUDO: return 1 if use ~ below die because can`t do lc on Math after
- return ~$s.lc;
-}
-
-method authority {
- my $a = $.uri<authority> || '';
- # RAKUDO: return 1 if use ~ below die because can`t do lc on Math after
- return ~$a.lc;
-}
-
-method host {
- #RAKUDO: $.uri<authority>[0]<host> return full <authority> now
- my $h = ~$.uri<authority>[0]<host>;
- return $h.lc || '';
-}
-
-method port {
- # TODO: send rakudobug
- # RAKUDO: $.uri<authority><port> return full <authority> now
- # workaround:
- item $.uri<authority>[0]<port> || '';
-}
-
-method path {
- my $p = ~$.uri<path> || '';
- return $p.lc;
-}
-
-method absolute {
- # RAKUDO: The grammar uses <slash>?, so this should be either Nil or a
- # Match object. But Rakudo returns [] or [Match] instead, so we must use
- # || instead of // to test.
- return ?($.uri<path><slash> || $.scheme);
-}
-
-method relative {
- # Rakudo: Must use || instead of //, see above.
- return !($.uri<path><slash> || $.scheme);
-}
-
-method query {
- item $.uri<query> || '';
-}
-method frag {
- my $f = $.uri<fragment> || '';
- return ~$f.lc;
-}
-
-method fragment { $.frag }
-
-method Str() {
- my $str;
- $str ~= $.scheme if $.scheme;
- $str ~= '://' ~ $.authority if $.authority;
- $str ~= $.path;
- $str ~= '?' ~ $.query if $.query;
- $str ~= '#' ~ $.frag if $.frag;
- return $str;
-}
-
-
-=begin pod
-
-=head NAME
-
-November::URI — Uniform Resource Identifiers (absolute and relative)
-
-=head SYNOPSYS
-
- 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;
- my $host = $u.host;
- my $port = $u.port;
- my $path = $u.path;
- my $query = $u.query;
- my $frag = $u.frag; # or $u.fragment;
-
- my $is_absolute = $u.absolute;
- my $is_relative = $u.relative;
-
-=end pod
-
-
-# vim:ft=perl6
View
27 lib/November/URI/Grammar.pm
@@ -1,27 +0,0 @@
-use v6;
-grammar November::URI::Grammar {
- token TOP { ^ [<scheme> ':']? [ '//' <authority>]? <path> ['?' <query>]? ['#' <fragment>]? $ };
- token scheme { <-[:/&?#]>+ };
- token authority { <host> [':' <port>]? };
- token host { <-[/&?#:]>* };
- token port { (\d**1..5)
- <?{ $0 < 2 ** 16 }>
- <!before \d> };
- token path { <slash>? [ <chunk> '/'?]* }; # * mb wrong, because that allow '' URI
- token slash { '/' };
- token chunk { <-[/?#]>+ };
- token query { <-[#]>* };
- token fragment { .* };
-}
-
-# Official regexp (p5):
-# my($scheme, $authority, $path, $query, $fragment) =
-# $uri =~ m/
-# (?:([^:/?#]+):)?
-# (?://([^/?#]*))?
-# ([^?#]*)
-# (?:\?([^#]*))?
-# (?:#(.*))?
-# /x;
-
-# vim:ft=perl6
View
2  wiki 100644 → 100755
@@ -1,4 +1,4 @@
-#!perl6
+#!/usr/bin/env perl6
use v6;
use November;
Please sign in to comment.
Something went wrong with that request. Please try again.