few extra utility routines
[catagits/HTML-Zoom.git] / lib / HTML / Zoom.pm
index 3234576..0ae18d2 100644 (file)
@@ -5,6 +5,7 @@ use warnings FATAL => 'all';
 
 use HTML::Zoom::ZConfig;
 use HTML::Zoom::MatchWithoutFilter;
+use HTML::Zoom::ReadFH;
 
 sub new {
   my ($class, $args) = @_;
@@ -30,6 +31,12 @@ sub from_html {
   });
 }
 
+sub from_file {
+  my $self = shift->_self_or_new;
+  my $filename = shift;
+  $self->from_html(do { local (@ARGV, $/) = ($filename); <> });
+}
+
 sub to_stream {
   my $self = shift;
   die "No events to build from - forgot to call from_html?"
@@ -42,6 +49,22 @@ sub to_stream {
   $stream
 }
 
+sub to_fh {
+  HTML::Zoom::ReadFH->from_zoom(shift);
+}
+
+sub run {
+  my $self = shift;
+  $self->zconfig->stream_utils->stream_to_array($self->to_stream);
+  return
+}
+
+sub apply {
+  my ($self, $code) = @_;
+  local $_ = $self;
+  $self->$code;
+}
+
 sub to_html {
   my $self = shift;
   $self->zconfig->producer->html_from_stream($self->to_stream);