Previously, uri_for would test to see if its first argument was isa
Catalyst::Controller but then assume any other object was a Catalyst::Action;
this change uses Safe::Isa to check the class in both cases, which is useful
both for string overloading packages such as i18n.pm and HTML::String but also
when a Path::Class::File object is passed during static URI generation.
# This file documents the revision history for Perl extension Catalyst.
+ - Fix uri_for to handle a stringifiable object
- Fix model/view/controller methods to handle stringifiable objects
- Fix RT#78377 - IIS7 ignores response body for 3xx requests, which
causes (a different) response to be broken when using keepalive.
sub uri_for {
my ( $c, $path, @args ) = @_;
- if (blessed($path) && $path->isa('Catalyst::Controller')) {
+ if ( $path->$_isa('Catalyst::Controller') ) {
$path = $path->path_prefix;
$path =~ s{/+\z}{};
$path .= '/';
$arg =~ s/([^$URI::uric])/$URI::Escape::escapes{$1}/go;
}
- if ( blessed($path) ) { # action object
+ if ( $path->$_isa('Catalyst::Action') ) { # action object
s|/|%2F|g for @args;
my $captures = [ map { s|/|%2F|g; $_; }
( scalar @args && ref $args[0] eq 'ARRAY'
);
}
-done_testing;
+{
+ package MyStringThing;
+
+ use overload '""' => sub { $_[0]->{string} }, fallback => 1;
+}
+is(
+ Catalyst::uri_for( $context, bless( { string => 'test' }, 'MyStringThing' ) ),
+ 'http://127.0.0.1/test',
+ 'overloaded object handled correctly'
+);
+
+done_testing;