Skip to content

Instantly share code, notes, and snippets.

@kraih
Created August 31, 2011 10:12
Show Gist options
  • Save kraih/1183234 to your computer and use it in GitHub Desktop.
Save kraih/1183234 to your computer and use it in GitHub Desktop.
use Mojo::DOM;
# Parse HTML5 snippet
my $dom = Mojo::DOM->new(<<EOF);
<div>
<a href="http://search.cpan.org">
<img src="/images/search.png">
</a>
<a href="http://mojolicio.us">
<p>Mojolicious</p>
</a>
<a href="http://metacpan.org">
<p><img src="/images/metacpan.png"></p>
</a>
</div>
EOF
# Add class attribute to all image links
$dom->find('$a img')->each(sub { shift->{class} = 'logo' });
# Render HTML5 snippet
print "$dom";
@ghandmann
Copy link

Whats the reason you are using the dollar-sign instead of the exclamation mark like in the w3c proposal? Wouldn't it be saner to stay standard-compliant?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment