[whishlist] Mojo::Dom: simpler find - map - text?

274 views
Skip to first unread message

Helmut Wollmersdorfer

unread,
Feb 5, 2015, 6:14:39 AM2/5/15
to mojol...@googlegroups.com
Hi,

maybe I missed some more convenient methods, but here are my solutions so far:

That's a working snippet for reading out a key-value pair from an HTML table:

  for my $details ($tables[4]->find('tr')->each) {
   
my ($key,$value)
       
= map { $_->all_text } $details->find('td')->each;

    $result
{$key} = $value;
 
}

My first attempt was something like

  my ($key,$value) = $details->find('td')->each->all_text; # WRONG

which does not work.

Then I tried map and ended in something complex like this one

  my ($key,$value) = @{
     
Mojo::DOM->new("<b>K</b><b>V</b>")
       
->find("b")
       
->map(sub {$_->text})
       
->to_array
 
};

I still would like my first attempt, which is IMHO more natural, but maybe against technically oriented design.

Comments?

Helmut Wollmersdorfer

sri

unread,
Feb 5, 2015, 6:36:10 AM2/5/15
to mojol...@googlegroups.com
This is a funny request.

    my @all = $dom->find('td')->all_text->each;

It used to work like this until we removed AUTOLOAD and stringification support from Mojo::Collection.


No, i'm afraid there is no chance we will bring any of that back, there have been way too many complaints.

--
sebastian

Helmut Wollmersdorfer

unread,
Feb 5, 2015, 8:05:39 AM2/5/15
to mojol...@googlegroups.com
Thx for the explanation of the history. Now I see that cluck() also has gone.

Ok, it is as it is.


sri

unread,
Feb 5, 2015, 8:24:53 AM2/5/15
to mojol...@googlegroups.com
Now I see that cluck() also has gone.

There never was a cluck(), so i suspect you mean pluck(), and that one is not "gone".


--
sebastian

Helmut Wollmersdorfer

unread,
Feb 6, 2015, 3:54:10 AM2/6/15
to mojol...@googlegroups.com
pluck() seems removed in the current version:

$ perl -Mojo -e 'Mojo::DOM->new("<b>")->find("b")->pluck()';mojo version | grep Mojo
Can't locate object method "pluck" via package "Mojo::Collection" at -e line 1.

  Mojolicious (5.77, Tiger Face)


See also

https://github.com/kraih/mojo/commit/759215c7897855ce6fe8a3cc28a33c2bed912871#diff-0c4b798f16fc7e5ac314e0dbf81858e3

Or do I understand something wron?

Helmut Wollmersdorfer



sri

unread,
Feb 6, 2015, 6:52:21 AM2/6/15
to mojol...@googlegroups.com

Or do I understand something wron?


The functionality has been merged into map(), which is why is always says "...deprecated in favor of..." .


--
sebastian
Reply all
Reply to author
Forward
0 new messages