From: Simon Elliott Date: Thu, 19 May 2011 16:23:44 +0000 (+0100) Subject: Support for hashref in AUTOLOADed methods i.e X-Git-Tag: 0.009009~1^2~18 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FHTML-Zoom.git;a=commitdiff_plain;h=6dc05a36124ed607d23e19f2969ca5ab308bce5f Support for hashref in AUTOLOADed methods i.e $z->repeat_content({ div => ['foo'], span => ['bar'], }) --- diff --git a/lib/HTML/Zoom.pm b/lib/HTML/Zoom.pm index 053f458..8de1952 100644 --- a/lib/HTML/Zoom.pm +++ b/lib/HTML/Zoom.pm @@ -155,7 +155,19 @@ sub AUTOLOAD { my $sel = $self->select($selector); my $meth = our $AUTOLOAD; $meth =~ s/.*:://; - if(my $cr = $sel->_zconfig->filter_builder->can($meth)) { + if (ref($selector) eq 'HASH') { + my $ret = $self; + $ret = $ret->_do($_, $meth, @{$selector->{$_}}) for keys %$selector; + $ret; + } else { + $self->_do($selector, $meth, @args); + } +} + +sub _do { + my ($self, $selector, $meth, @args) = @_; + my $sel = $self->select($selector); + if( my $cr = $sel->_zconfig->filter_builder->can($meth)) { return $sel->$meth(@args); } else { die "We can't do $meth on ->select('$selector')"; @@ -770,7 +782,7 @@ Oliver Charles Jakub Nareski -Simon Elliot +Simon Elliott Joe Highton diff --git a/t/dwim-autoload.t b/t/dwim-autoload.t index caf7716..cd63df6 100644 --- a/t/dwim-autoload.t +++ b/t/dwim-autoload.t @@ -304,4 +304,15 @@ sub code_stream (&) { 'Got correct from repeat_content'; } +{ + ok my $dwim = HTML::Zoom + ->from_html(q[]) + ->replace_content({ + 'li.foo' => ['foo'], + 'li.bar' => ['bar'], + })->to_html; + is $dwim, '', + 'Multiple selectors from hashref'; +} + done_testing;