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

Lazy loading of attributes #1

Merged
merged 8 commits into from
Mar 18, 2018
Merged

Lazy loading of attributes #1

merged 8 commits into from
Mar 18, 2018

Conversation

mdom
Copy link
Contributor

@mdom mdom commented Mar 16, 2018

Hi! This is just a rough draft to see if you like the direction I'm working on? I had to rewrite a lot, but all test but t/03-feed-find.t are passing. No idea, what i broke there, still trying to find that error.

Cheers, Mario

@mdom
Copy link
Contributor Author

mdom commented Mar 17, 2018

Ah, okay, i cached the dom and text attributes of Mojo::Feed and didn't notice that you use one Mojo::Feed object to parse multiple feeds. I reverted that change back and prevent caching of all feed related attributes in Mojo::Feed. What do you think about returning new Mojo::Feed instances from parse?

@dotandimet
Copy link
Owner

Hey Mario,
I really like the idea of lazy attributes for everything. I think that Mojo::Feed is a bit too complex right now, with the multiple entry points to parsing and possible states. Probably this is a compromise because I just kept the old tests from Mojolicious::Plugin::FeedReader.
It might make sense to return new objects from parse(), or maybe to remove parse() altogether, and just use new?

@mdom
Copy link
Contributor Author

mdom commented Mar 18, 2018

I agree that it's maybe a little bit too complex, but i'm not really sure how to address that. Maybe it would be easier to seperate it into two packages: one to fetch and discover feeds and one that is actually the feed? Although i don't know how to make that work with the new name (we could name the base class for feeds Mojo::Feed::Feed... :smiley:)

Maybe it's easier to have:

$feedr = Mojo::FeedReader->new(ua => $ua);
$url = $feedr->discover('http://example.org');
$feed = $feedr->parse($url);
say $feed->title

Or maybe it's easier if parsing and creating are really seperate operations?

$feedr = Mojo::Feed->new(ua => $ua);
$url = $feedr->discover('http://example.org');
$feed = $feedr->parse($url);
say $feed->title

I'm not really sure. Without seperating this functionality I imagine it would be weird to call discover and you would have to use ua a lot in new to prevent creating many user agents. Does that make sense? It's really early here... 😪

@dotandimet
Copy link
Owner

If we move the fetching and parsing part into its own module, we could just call it Mojo::Feed::Reader 😃
I'm inclined to go with that (extracting the fetching part). Most of the complexity I think is borrowed from XML::Atom::Feed, which tries to give a very friendly interface and hides considerable complexity inside.


my $p;
for my $field ($k, @alternatives) {
$p = $self->dom->at_with_namespace($field);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What was this trying to solve? Is there a test failure that made you add this, and if not, could you add one?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, i'm not sure what do you mean with this? This is a pretty big diff over a lot of commits...

@dotandimet
Copy link
Owner

Sorry, I meant the _at(_with_namespaces) method, seen in the commit with the message Handle multiple matches with namespaces - I presume that's fixing something you ran into which is unrelated to the lazy loading feature. Is this something you ran into with a podcast feed? I'd really like to have a test for it that fails in my branch so I can see what it changes.

BTW, I found podite, which looks very cool! I felt a sense of Deja Vu seeing the URLQueue class - I've had messier and more primitive versions of something similar in my own project. My last attempt is Mojo::UserAgent::Role::Queued, which tries to stick the queue inside the UserAgent. I'd love to know what you think (I'd be happy even with someone telling me it's a dumb idea).

@dotandimet
Copy link
Owner

Anyway, is it OK if I merge this pull request?
Let's split the part that uses a Mojo::UserAgent into a Mojo::Feed::Reader class; then Mojo::Feed and Mojo::Feed::Item can be pure parsing classes with lazy attributes.

@mdom
Copy link
Contributor Author

mdom commented Mar 18, 2018 via email

In the old version the method name was always the first selector we
searched.  But maybe that's not always the case, maybe we want to prefer
dc:creator to author? This commit also shortens (and hopefully
simplifies) the default handler for attributes.
@mdom
Copy link
Contributor Author

mdom commented Mar 18, 2018 via email

@dotandimet dotandimet merged commit 2ca1186 into dotandimet:master Mar 18, 2018
@mdom mdom deleted the lazy branch March 19, 2018 07:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants