Re: [Mojolicious] Re: Using Mojo::DOM to update

2018-08-24 Thread Dan Book
Absolutely, that's what tap is for.

-Dan

On Fri, Aug 24, 2018 at 9:48 PM Stefan Adams  wrote:

> Sorry, I knew I should know better.
>
> I was using the 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!
>
> On Fri, Aug 24, 2018 at 8:24 PM Stefan Adams  wrote:
>
>> 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+unsubscr...@googlegroups.com.
> To post to this group, send email to mojolicious@googlegroups.com.
> 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+unsubscr...@googlegroups.com.
To post to this group, send email to mojolicious@googlegroups.com.
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.


[Mojolicious] Re: Using Mojo::DOM to update

2018-08-24 Thread Stefan Adams
Sorry, I knew I should know better.

I was using the 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!

On Fri, Aug 24, 2018 at 8:24 PM Stefan Adams  wrote:

> 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+unsubscr...@googlegroups.com.
To post to this group, send email to mojolicious@googlegroups.com.
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.


[Mojolicious] Using Mojo::DOM to update

2018-08-24 Thread Stefan Adams
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+unsubscr...@googlegroups.com.
To post to this group, send email to mojolicious@googlegroups.com.
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.