Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

Re: Ordering meta tags with HTML::Element

by codiac (Beadle)
on Jun 15, 2016 at 11:15 UTC ( #1165713=note: print w/replies, xml ) Need Help??

in reply to Ordering meta tags with HTML::Element

Generally sub-classing is the way to go, but sub-classing HTML::Element can be pretty ugly, so not such an easy decision in this case.

If you aren't opposed to dirty little hacks, you could modify the attribute names you make to take advantage of the "sort keys" used in the starttag sub to order the attributes.

e.g. instead of

$m_el->attr('name',$m); $m_el->attr('content',$meta{$m});
you write
$m_el->attr('aa01_name',$m); $m_el->attr('aa02_content',$meta{$m});
Then you just post process $out to substitue in the real attribute names. e.g. $out =~ s/aa01_name/name/g

I only feel a little dirty ;)

Replies are listed 'Best First'.
Re^2: Ordering meta tags with HTML::Element
by Corion (Patriarch) on Jun 15, 2016 at 11:18 UTC

    Maybe a better convention would be to use leading whitespace to enforce the ordering:

    $m_el->attr(' name',$m); $m_el->attr(' content',$meta{$m});

    This way, the output would create the attribute "names" with their leading whitespace, but in the correct order. And hopefully, the receiving side won't care about the additional whitespace.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1165713]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (2)
As of 2023-09-26 22:58 GMT
Find Nodes?
    Voting Booth?

    No recent polls found