Discussion:
[Mojolicious] Using Mojo::DOM to update
Stefan Adams
2018-08-25 01:24:42 UTC
Permalink
Can Mojo::DOM be used to update information in a tree, or is it just used
to select information?

For example, how could I remove the https?://host from all links (e.g. src,
href)?
--
You received this message because you are subscribed to the Google Groups "Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.
Stefan Adams
2018-08-25 01:48:13 UTC
Permalink
Sorry, I knew I should know better.

I was using the ojo#x <https://mojolicious.org/perldoc/ojo#x> example and I
just added on to it:

$ perl -Mojo -E 'say x(f("test.html")->slurp)->at("title")->content("NEW TEXT")'

I've lost access to the dom! I needed to store the dom object in a
variable so I could get back to the dom after looping thru find:

$ perl -Mojo -E 'my $dom = x(f("test.html")->slurp);
$dom->at("title")->content("NEW TEXT"); say $dom'

There was a discussion recently about tap. Is this a good use for tap?

$ perl -Mojo -E 'say
x(f("index.html")->slurp)->tap(sub{$_->at("title")->content("NEW
TEXT")})'

Now I have the full dom with my updated information!
Can Mojo::DOM be used to update information in a tree? For example, if I
want to strip the host from all links, I might ->find('a[href]') and then
loop through the collection to do some updates. But unless I'm missing
something, I can't then update the original dom with these changes.
--
You received this message because you are subscribed to the Google Groups "Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.
Dan Book
2018-08-25 02:32:46 UTC
Permalink
Absolutely, that's what tap is for.

-Dan
Post by Stefan Adams
Sorry, I knew I should know better.
I was using the ojo#x <https://mojolicious.org/perldoc/ojo#x> example and
$ perl -Mojo -E 'say x(f("test.html")->slurp)->at("title")->content("NEW TEXT")'
I've lost access to the dom! I needed to store the dom object in a
$ perl -Mojo -E 'my $dom = x(f("test.html")->slurp); $dom->at("title")->content("NEW TEXT"); say $dom'
There was a discussion recently about tap. Is this a good use for tap?
$ perl -Mojo -E 'say x(f("index.html")->slurp)->tap(sub{$_->at("title")->content("NEW TEXT")})'
Now I have the full dom with my updated information!
Can Mojo::DOM be used to update information in a tree? For example, if I
want to strip the host from all links, I might ->find('a[href]') and then
loop through the collection to do some updates. But unless I'm missing
something, I can't then update the original dom with these changes.
--
You received this message because you are subscribed to the Google Groups
"Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.
Loading...