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;
Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery
In reply to Re^2: Challenge: Parse XML Feed for Youtube channel -- Mojo::DOM
by LanX
in thread Challenge: Parse XML Feed for Youtube channel
by LanX
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |