From: Simon Elliott Date: Mon, 10 Mar 2014 17:50:37 +0000 (+0000) Subject: merge X-Git-Tag: 0.009009~1 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FHTML-Zoom.git;a=commitdiff_plain;h=0c58a1e1705f0eafd1c6457ed5f26104e2bb4ad4;hp=0767fbba4ed63925df8e5aeed172407a39b37ae5 merge --- diff --git a/Makefile.PL b/Makefile.PL deleted file mode 100644 index 0dc20df..0000000 --- a/Makefile.PL +++ /dev/null @@ -1,13 +0,0 @@ -use strict; -use warnings FATAL => 'all'; -use 5.008001; -use ExtUtils::MakeMaker; - -(do 'maint/Makefile.PL.include' or die $@) unless -f 'META.yml'; - -WriteMakefile( - NAME => 'HTML-Zoom', - VERSION_FROM => 'lib/HTML/Zoom.pm', - PREREQ_PM => { strictures => 1, 'Test::More' => '0.88' }, - test => { TESTS => 't/*.t t/*/*.t' }, -); diff --git a/dist.ini b/dist.ini new file mode 100644 index 0000000..5bdb988 --- /dev/null +++ b/dist.ini @@ -0,0 +1,11 @@ +name = HTML-Zoom +version = 0.009008_01 +author = Matt S. Trout +license = Perl_5 +copyright_holder = Matt S. Trout + +[@Basic] + +[Prereqs] +strictures = 0 +Test::More = 0 diff --git a/lib/HTML/Zoom/FilterBuilder.pm b/lib/HTML/Zoom/FilterBuilder.pm index 6713841..ed7fef1 100644 --- a/lib/HTML/Zoom/FilterBuilder.pm +++ b/lib/HTML/Zoom/FilterBuilder.pm @@ -28,15 +28,13 @@ sub set_attr { shift->set_attribute(@_); } sub set_attribute { my $self = shift; - my ($name, $value) = $self->_parse_attribute_args(@_); + my $attr = $self->_parse_attribute_args(@_); sub { my $a = (my $evt = $_[0])->{attrs}; - my $e = exists $a->{$name}; + my @kadd = grep {!exists $a->{$_}} keys %$attr; +{ %$evt, raw => undef, raw_attrs => undef, - attrs => { %$a, $name => $value }, - ($e # add to name list if not present - ? () - : (attr_names => [ @{$evt->{attr_names}}, $name ])) + attrs => { %$a, %$attr }, + @kadd ? (attr_names => [ @{$evt->{attr_names}}, @kadd ]) : () } }; } @@ -46,8 +44,10 @@ sub _parse_attribute_args { die "Long form arg (name => 'class', value => 'x') is no longer supported" if(@_ == 1 && $_[0]->{'name'} && $_[0]->{'value'}); - my ($name, $value) = @_ > 1 ? @_ : @{$_[0]}{qw(name value)}; - return ($name, $self->_zconfig->parser->html_escape($value)); + + my $opts = ref($_[0]) eq 'HASH' ? $_[0] : {$_[0] => $_[1]}; + for (values %{$opts}) { $self->_zconfig->parser->html_escape($_); } + return $opts; } sub add_attribute { @@ -64,18 +64,17 @@ sub set_id { shift->set_attribute('id',@_) } sub add_to_attribute { my $self = shift; - my ($name, $value) = $self->_parse_attribute_args(@_); + my $attr = $self->_parse_attribute_args(@_); sub { my $a = (my $evt = $_[0])->{attrs}; - my $e = exists $a->{$name}; + my @kadd = grep {!exists $a->{$_}} keys %$attr; +{ %$evt, raw => undef, raw_attrs => undef, attrs => { %$a, - $name => join(' ', ($e ? $a->{$name} : ()), $value) + map {$_ => join(' ', (exists $a->{$_} ? $a->{$_} : ()), $attr->{$_}) } + keys %$attr }, - ($e # add to name list if not present - ? () - : (attr_names => [ @{$evt->{attr_names}}, $name ])) + @kadd ? (attr_names => [ @{$evt->{attr_names}}, @kadd ]) : () } }; } @@ -89,7 +88,7 @@ sub remove_from_attribute { attrs => { %$a, #TODO needs to support multiple removes - map { my $tar = $_; $_ => join ' ', + map { my $tar = $_; $_ => join ' ', map {$attr->{$tar} ne $_} split ' ', $a->{$_} } grep {exists $a->{$_}} keys %$attr }, @@ -678,9 +677,9 @@ Similar to add_before, but adds the content to the match. ->select('p') ->prepend_content("Hello ") ->to_html - + ##

Hello World

- + Acceptable values are strings, scalar refs and L objects =head2 append_content @@ -692,7 +691,7 @@ Similar to add_after, but adds the content to the match. ->select('p') ->prepend_content("World") ->to_html - + ##

Hello World

Acceptable values are strings, scalar refs and L objects @@ -729,7 +728,7 @@ pre-generated) } } @list ]); - + Subroutines would be run with $_ localized to result of L (of collected elements), and with said result passed as parameter to subroutine. diff --git a/t/actions.t b/t/actions.t index 7f23cd4..d1dcc54 100644 --- a/t/actions.t +++ b/t/actions.t @@ -9,7 +9,7 @@ use HTML::Zoom::FilterStream; my $tmpl = < -
+
Bob Builder
@@ -55,12 +55,12 @@ is( 'set attribute on existing attribute' ); -($expect = $tmpl) =~ s/class="main"/class="foo"/; +($expect = $tmpl) =~ s/name="cow" class="main"/name="bar" class="foo"/; is( - run_for { $_->set_attr({ name => 'class', value => 'foo' }) }, + run_for { $_->set_attr({ 'class' => 'foo', 'name' => 'bar'}) }, $expect, - 'set attribute on existing attribute (shorthand)' + 'set attributes using hashref form (shorthand)' ); ($expect = $tmpl) =~ s/class="main"/class="main" foo="bar"/; @@ -253,7 +253,7 @@ is( is( HTML::Zoom::Producer::BuiltIn->html_from_events(\@ev), - '
+ '
Bob Builder
@@ -266,7 +266,7 @@ is( is( run_for { $_->collect({ into => \@ev, content => 1 }) }, ' -
+
', 'collect w/content removes correctly' @@ -285,7 +285,7 @@ is( is( run_for { $_->replace($ohai, { content => 1 }) }, ' -
O HAI
+
O HAI
', 'replace w/content' @@ -319,11 +319,11 @@ is( ) }, q{ -
+
mst Chainsaw Wielder
-
+
mdk Adminion
@@ -351,7 +351,7 @@ is( ) }, q{ -
+
mst Chainsaw Wielder
@@ -391,7 +391,7 @@ is( ) }, q{ -
+
mst Chainsaw Wielder
@@ -424,7 +424,7 @@ is( ) }, q{ -
+
mst Chainsaw Wielder