Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request uri_base method have to return URI object in all cases #1560

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

bor
Copy link
Contributor

@bor bor commented Sep 9, 2020

The PR makes consistency better in cases of:
- with the 'base' method, now both return URI objects
- in various cases of '/' at end

The issue was that =~ converts the value into a scalar in case of '/' at the end.

that makes consistency better in cases of:
 - with the 'base' method, now both return URI objects
 - in various cases of '/' at end
@cromedome cromedome added this to the January 2021 Release milestone Jan 12, 2021
@veryrusty
Copy link
Member

Thanks for the PR @bor.

I concur it would have been better if request->base and request->uri_base were consistent and returned URI objects, which would then match the behaviour of what Plack::Request does for its url related methods.

The refactor of _common_uri always canonicalises the url is good.

@SysPete @cromedome The existing behaviour (and code) of string return from uri_base looks to have been taken directly from Dancer1. Our docs for uri_base include examples for url construction in templates. I'm concerned that breakage may occur if we change to a URI object at this point. eg. Tempalte::Toolkit vmethods, where `[% uri_base.size %] would become a method call on the URI object.

Should we consider another method that returns request uri_base as a URI object ? Something like the following would suffice.

sub base_uri {
     my $self = shift;
     my $uri  = $self->_common_uri;

     if ( $uri->path eq '/' ) {
         $uri->path('');
     }

     return $uri;
 }
 
 sub uri_base { shift->base_uri->as_string }

@cromedome
Copy link
Contributor

I share @veryrusty's concern here. I am all for consistency... but not so much for breakage. Any suggestions for a method name? base_uri vs uri_base leaves me very confused :)

@bor
Copy link
Contributor Author

bor commented Jan 14, 2021

I've checked the documentation and didn't found any base_uri. entries (call it as method).

At the moment base_uri method may returns both object or string in a case of / at the end.
So IMHO it is in breakable stage already. (I've encountered that)

The documentation says Same thing as C<base> above.
And for base we see: Returns a L<URI> object (which stringifies to the URL, as you'd expect).
So it looks like base_uri should return object. And that's why I've called that as a "fix" ;)

@SysPete
Copy link
Member

SysPete commented Jan 17, 2021

Since current behaviour is clearly broken I'd like to propose that we mark uri_base as deprecated and remove it from all docs. The new method as proposed by @veryrusty is fine for me with the name proposed as replacement.

@veryrusty
Copy link
Member

Yeah, two similarly named methods sucketh (who suggested that?!).

The uri_base method was copied from Dancer1 and currently behaves the same there. If we were deprecate it we need to note that in the migration docs from D1. If we apply the change in this PR we need to note that the migration docs that it has changed behaviour. A bit of damned if we do and damned if we don't.

After reflection, the fix in this PR is the way to go. However we need tests and documentation, and possibly a blog post somewhere about it.

@cromedome
Copy link
Contributor

I can deal with the docs and blog post as part of the release if someone has time to cobble some tests together.

I'll create an issue for creating a real deprecation policy, but for now, maybe go with two minor versions out and throw a warning, ie. "Method marked as deprecated and will be removed in Dancer2 0.500000". Thoughts?

@cromedome cromedome modified the milestones: Next Release, April 2021 Mar 18, 2021
@cromedome cromedome modified the milestones: April 2021, May 2021 Apr 15, 2021
@cromedome cromedome modified the milestones: May 2021, June 2021 Jun 6, 2021
@cromedome
Copy link
Contributor

@xsawyerx and I spent some time reviewing this today.

Our documentation says we return an object, but as @bor points out, we don't always. We're thinking we should approve and merge this, write the appropriate docs and blog post, and deal with the fallout.

@veryrusty and @SysPete - penny for your thoughts?

@cromedome
Copy link
Contributor

@veryrusty and @SysPete - penny for your thoughts? Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants