Here a new approach with Mojo::DOM and taking benefit from it's overloading to shorten ->text and ->attr methods away.
Also using an own rolled "template system" for readability
The explicit map in the callback might also be easier done with an Mojo::DOM method ... maybe?
use v5.12;
use warnings;
use Mojo::DOM;
my $data = join "", <DATA>;
my $dom = Mojo::DOM->new($data);
say &t::page(
TITLE => $dom->at('title'),
NAME => $dom->at('name'),
ENTRIES => \&entries,
);
sub entries {
map {
t::entry
(
TITLE => $_->at("title"),
HREF => $_->at("link")->{href},
DESC => $_->at('media\:group > media\:description')
);
} $dom->find('entry')->each ;
}
package t; # poor man's templates
sub page { my %p = @_; << "____" }
<h3>$p{ TITLE }</h3>
<b>$p{ NAME }</b>
<ul>
@{[ $p{ ENTRIES }->() ]}
</ul>
____
sub entry { my %p = @_; << "____" }
<li>[$p{ HREF }|$p{ TITLE }]<p>
$p{ DESC }
</li>
____
package main;
__DATA__
<feed xmlns:yt="http://www.youtube.com/xml/schemas/2015" xmlns:media="
+http://search.yahoo.com/mrss/" xmlns="http://www.w3.org/2005/Atom">
<link rel="self" href="http://www.youtube.com/feeds/videos.xml?playlis
+t_id=PLA9_Hq3zhoFyOpb-U3DMU7OT93dPUdtpE"/>
<id>yt:playlist:PLA9_Hq3zhoFyOpb-U3DMU7OT93dPUdtpE</id>
<yt:playlistId>PLA9_Hq3zhoFyOpb-U3DMU7OT93dPUdtpE</yt:playlistId>
<yt:channelId>UC7y4qaRSb5w2O8cCHOsKZDw</yt:channelId>
<title>TPC 2022 in Houston</title>
<author>
<name>Conference in the Cloud! A Perl and Raku Conf</name>
<uri>https://www.youtube.com/channel/UC7y4qaRSb5w2O8cCHOsKZDw</uri>
</author>
<published>2022-06-22T19:04:37+00:00</published>
<entry>
<id>yt:video:waHAGThlRH8</id>
<yt:videoId>waHAGThlRH8</yt:videoId>
<yt:channelId>UC7y4qaRSb5w2O8cCHOsKZDw</yt:channelId>
<title>Raku -Ofun for Everyone - Daniel Sockwell</title>
<link rel="alternate" href="https://www.youtube.com/watch?v=waHAGThlRH
+8"/>
<author>
<name>Conference in the Cloud! A Perl and Raku Conf</name>
<uri>https://www.youtube.com/channel/UC7y4qaRSb5w2O8cCHOsKZDw</uri>
</author>
<published>2022-06-24T15:57:38+00:00</published>
<updated>2022-06-25T03:36:26+00:00</updated>
<media:group>
<media:title>Raku -Ofun for Everyone - Daniel Sockwell</media:title>
<media:content url="https://www.youtube.com/v/waHAGThlRH8?version=3" t
+ype="application/x-shockwave-flash" width="640" height="390"/>
<media:thumbnail url="https://i4.ytimg.com/vi/waHAGThlRH8/hqdefault.jp
+g" width="480" height="360"/>
<media:description>Rakoons like to say that Raku is -Ofun (optimized f
+or fun). This talk ... YADDA YADDA ... </media:description>
<media:community>
<media:starRating count="14" average="5.00" min="1" max="5"/>
<media:statistics views="278"/>
</media:community>
</media:group>
</entry>
<entry>
<id>yt:video:3BYlObnzuKQ</id>
<yt:videoId>3BYlObnzuKQ</yt:videoId>
<yt:channelId>UC7y4qaRSb5w2O8cCHOsKZDw</yt:channelId>
<title>Introducing Perl Data Types - Will Braswell</title>
<link rel="alternate" href="https://www.youtube.com/watch?v=3BYlObnzuK
+Q"/>
<author>
<name>Conference in the Cloud! A Perl and Raku Conf</name>
<uri>https://www.youtube.com/channel/UC7y4qaRSb5w2O8cCHOsKZDw</uri>
</author>
<published>2022-06-24T16:00:10+00:00</published>
<updated>2022-06-24T16:00:10+00:00</updated>
<media:group>
<media:title>Introducing Perl Data Types - Will Braswell</media:title>
<media:content url="https://www.youtube.com/v/3BYlObnzuKQ?version=3" t
+ype="application/x-shockwave-flash" width="640" height="390"/>
<media:thumbnail url="https://i4.ytimg.com/vi/3BYlObnzuKQ/hqdefault.jp
+g" width="480" height="360"/>
<media:description>Data types are hints to a computer language, tellin
+g the language’s ... YADDA YADDA ...</media:description>
<media:community>
<media:starRating count="15" average="5.00" min="1" max="5"/>
<media:statistics views="198"/>
</media:community>
</media:group>
</entry>
</feed>
|