Skip to content
Browse files

Allow uri as optional named parameter or optional first positional

parameter.
  • Loading branch information...
1 parent 4a721fe commit cdc2cb28229bc6019e47a23b6e1d401c0adbb225 Ron Schmidt committed Jul 31, 2011
Showing with 8 additions and 5 deletions.
  1. +3 −3 lib/URI.pm
  2. +5 −2 t/01.t
View
6 lib/URI.pm
@@ -115,15 +115,15 @@ submethod BUILD($!is_validating?) {
$!grammar = IETF::RFC_Grammar.new('rfc3896');
}
-method new(Str $str?, :$is_validating) {
+method new(Str $uri_pos1?, Str :$uri, :$is_validating) {
my $obj = self.bless(*);
if $is_validating.defined {
$obj.is_validating = $is_validating;
}
- if $str.defined {
- $obj.parse($str);
+ if $uri.defined or $uri_pos1.defined {
+ $obj.parse($uri.defined ?? $uri !! $uri_pos1);
}
return $obj;
View
7 t/01.t
@@ -21,7 +21,8 @@ is($u.segments[1], 'us', 'second chunk');
is( ~$u, 'http://example.com:80/about/us?foo#bar',
'Complete path stringification');
-$u.parse('https://eXAMplE.COM');
+# allow uri as named argument too
+$u = URI.new(uri => 'https://eXAMplE.COM');
is($u.scheme, 'https', 'scheme');
is($u.host, 'example.com', 'host');
@@ -42,8 +43,10 @@ nok($u.absolute, 'not absolute path');
is($u.segments[0], 'foo', 'first segment');
is($u.segments[1], 'bar', 'second segment');
-is($u.segments[*-1], 'baz', 'last seement');
+is($u.segments[*-1], 'baz', 'last segment');
+# actual uri parameter not required
+$u = URI.new;
$u.parse('http://foo.com');
ok($u.segments.list.perl eq '[""]', ".segments return [''] for empty path");

0 comments on commit cdc2cb2

Please sign in to comment.
Something went wrong with that request. Please try again.