From: Marco Pessotto Date: Mon, 26 Oct 2015 15:07:59 +0000 (+0100) Subject: Avoid warning when path argument for uri_for is not defined X-Git-Tag: 5.90102~8^2^2~1 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=a8020c62d2a52f96f14d288f5b81c6940be858b4 Avoid warning when path argument for uri_for is not defined --- diff --git a/lib/Catalyst.pm b/lib/Catalyst.pm index c290fff..56e0a2a 100644 --- a/lib/Catalyst.pm +++ b/lib/Catalyst.pm @@ -1560,7 +1560,7 @@ sub uri_for { my $fragment = ((scalar(@args) && ref($args[-1]) eq 'SCALAR') ? pop @args : undef ); unless(blessed $path) { - if ($path =~ s/#(.+)$//) { + if ($path and $path =~ s/#(.+)$//) { if(defined($1) and $fragment) { carp "Abiguious fragment declaration: You cannot define a fragment in '$path' and as an argument '$fragment'"; } diff --git a/t/aggregate/unit_core_uri_for.t b/t/aggregate/unit_core_uri_for.t index a541508..8886656 100644 --- a/t/aggregate/unit_core_uri_for.t +++ b/t/aggregate/unit_core_uri_for.t @@ -94,7 +94,19 @@ is( Catalyst::uri_for( $context, 'quux', { param1 => $request->base } )->as_string, 'http://127.0.0.1/foo/yada/quux?param1=http%3A%2F%2F127.0.0.1%2Ffoo', 'URI for undef action with query param as object' -); + ); + +# test with empty arg +{ + my @warnings; + local $SIG{__WARN__} = sub { push @warnings, @_ }; + is( + Catalyst::uri_for( $context )->as_string, + 'http://127.0.0.1/foo/yada', + 'URI with no action' + ); + is_deeply(\@warnings, [], "No warnings with no path argument"); +} $request->base( URI->new('http://localhost:3000/') ); $request->match( 'orderentry/contract' );