X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FHTML%2FZoom%2FStreamBase.pm;h=1293458e8b5758d4bd59b4cc62fa10f86992e4f4;hb=bce7b3519da39ab703e46aa27e9a5b1a1791279a;hp=6c0b41620de65d56bb2c3fccb6c639af9aa6318c;hpb=12bfb3b72e83b770d0a1a8b546af34494acbf648;p=catagits%2FHTML-Zoom.git diff --git a/lib/HTML/Zoom/StreamBase.pm b/lib/HTML/Zoom/StreamBase.pm index 6c0b416..1293458 100644 --- a/lib/HTML/Zoom/StreamBase.pm +++ b/lib/HTML/Zoom/StreamBase.pm @@ -1,7 +1,6 @@ package HTML::Zoom::StreamBase; -use strict; -use warnings FATAL => 'all'; +use strictures 1; use HTML::Zoom::TransformBuilder; sub _zconfig { shift->{_zconfig} } @@ -83,9 +82,41 @@ sub apply { $self->$code; } +sub apply_if { + my ($self, $predicate, $code) = @_; + if($predicate) { + local $_ = $self; + $self->$code; + } + else { + $self; + } +} + sub to_html { my ($self) = @_; $self->_zconfig->producer->html_from_stream($self); } +sub AUTOLOAD { + my ($self, $selector, @args) = @_; + my $sel = $self->select($selector); + my $meth = our $AUTOLOAD; + $meth =~ s/.*:://; + 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) = @_; + return $self->select($selector)->$meth(@args); +} + +sub DESTROY {} + 1;