[Bps-public-commit] r11933 - in HTML-RewriteResources: . t
sartak at bestpractical.com
sartak at bestpractical.com
Mon Apr 28 20:36:29 EDT 2008
Author: sartak
Date: Mon Apr 28 20:36:28 2008
New Revision: 11933
Modified:
HTML-RewriteResources/ (props changed)
HTML-RewriteResources/lib/HTML/RewriteAttributes.pm
HTML-RewriteResources/t/001-basic.t
Log:
r54612 at onn: sartak | 2008-04-28 20:36:20 -0400
Pass the tag into the callback, tiny refactor
Modified: HTML-RewriteResources/lib/HTML/RewriteAttributes.pm
==============================================================================
--- HTML-RewriteResources/lib/HTML/RewriteAttributes.pm (original)
+++ HTML-RewriteResources/lib/HTML/RewriteAttributes.pm Mon Apr 28 20:36:28 2008
@@ -56,15 +56,15 @@
sub _start_tag {
my ($self, $tag, $attrs, $attrseq, $text) = @_;
- for my $attr (@$attrseq) {
- next unless $self->_should_rewrite($tag, $attr);
- $attrs->{$attr} = $self->{rewrite_callback}->($attrs->{$attr});
- }
-
$self->{rewrite_html} .= "<$tag";
for my $attr (@$attrseq) {
next if $attr eq '/';
+
+ if ($self->_should_rewrite($tag, $attr)) {
+ $attrs->{$attr} = $self->{rewrite_callback}->($attrs->{$attr}, $tag);
+ }
+
$self->{rewrite_html} .= sprintf ' %s="%s"',
$attr,
#_escape($attrs->{$attr}),
Modified: HTML-RewriteResources/t/001-basic.t
==============================================================================
--- HTML-RewriteResources/t/001-basic.t (original)
+++ HTML-RewriteResources/t/001-basic.t Mon Apr 28 20:36:28 2008
@@ -2,7 +2,7 @@
use strict;
use warnings;
use HTML::RewriteResources;
-use Test::More tests => 4;
+use Test::More tests => 6;
my $html = << "END";
<html>
@@ -16,17 +16,25 @@
</html>
END
-my %seen;
+my %seen_uri;
+my %seen_tag;
my $rewrote = HTML::RewriteResources->rewrite($html, sub {
my $uri = shift;
- $seen{$uri}++;
+ my $tag = shift;
+
+ $seen_uri{$uri}++;
+ $seen_tag{$tag}++;
+
return uc $uri;
});
-is(keys %seen, 2, "saw two resources");
-is($seen{"moose.jpg"}, 1, "saw moose.jpg once");
-is($seen{"http://example.com/nethack.png"}, 1, "saw http://example.com/nethack.png once");
+is(keys %seen_uri, 2, "saw two resources");
+is($seen_uri{"moose.jpg"}, 1, "saw moose.jpg once");
+is($seen_uri{"http://example.com/nethack.png"}, 1, "saw http://example.com/nethack.png once");
+
+is(keys %seen_tag, 1, "saw two tag");
+is($seen_tag{"img"}, 2, "saw img twice");
is($rewrote, << "END", "rewrote the html correctly");
<html>
More information about the Bps-public-commit
mailing list