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

Deprecate Mojo::DOM::AUTOLOAD and Mojo::Collection::AUTOLOAD #699

Merged
merged 3 commits into from
Oct 29, 2014

Conversation

kraih
Copy link
Member

@kraih kraih commented Oct 29, 2014

I expect this to be a controversial pull request. While those two AUTOLOAD methods allow for some pretty nice shortcuts, like $dom->find('not(p)')->strip and $dom->parse('<div><b>Test</b></div>')->div->b->to_string, they can also be rather confusing for less experienced Perl programmers.

Especially the fact that Mojo::DOM::AUTOLOAD can return a single Mojo::DOM object, or a Mojo::Collection object containing Mojo::DOM objects, depending on the structure of the HTML/XML document, makes it pretty much impossible to use outside of one-liners. This is documented, but we regularly see questions about how to use it in non-trivial scripts anyhow.

Other problematic cases are the infamous $dom->find('foo')->find('bar') and $dom->find('foo')->at('bar'), with unexpected return values for anyone who hasn't spent a lot of time with the documentation.

@Akron
Copy link
Contributor

Akron commented Oct 29, 2014

👍 I always liked the limited use of magic in Mojolicious and considered AUTOLOAD in Mojo::DOM nice voodoo, but voodoo - meaning I avoided it. So I would really appreciate the deprecation.

@sattellite
Copy link

Good idea. Reducing the number of objects when they are not needed - excellent!

@kraih
Copy link
Member Author

kraih commented Oct 29, 2014

Guess this is less controversial than expected. 😃

@jberger
Copy link
Member

jberger commented Oct 29, 2014

I understand why this is necessary, and will grudgingly vote for it. I wonder if any corresponding changes can be made to the get command and to ojo to ease the passing of this feature which was most useful on the command line?

kraih added a commit that referenced this pull request Oct 29, 2014
Deprecate Mojo::DOM::AUTOLOAD and Mojo::Collection::AUTOLOAD
@kraih kraih merged commit 6c8e9fa into master Oct 29, 2014
@powerman
Copy link

You right about Mojo::DOM::AUTOLOAD, it create inconsistency and even looks weird, but what is wrong with Mojo::Collection::AUTOLOAD?

@kraih kraih deleted the less_autoload branch November 27, 2014 00:37
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.

5 participants