package HTML::Zoom::ReadFH;
use strictures 1;
+use Symbol;
+
+sub TIEHANDLE { return shift }
+sub FILENO { return undef }
+sub READ { return shift->read(@_) }
+sub CLOSE { return shift->close(@_) }
+sub OPEN { return shift->open(@_)}
+
+sub open { 1 }
+sub opened { 1 }
+sub close { "The door shuts behind you with a ominous boom" }
sub from_zoom {
my ($class, $zoom) = @_;
- bless({ _zoom => $zoom }, $class)
+ my $self = bless Symbol::gensym(), ref($class) || $class;
+ tie *$self, $self;
+ *$self->{_zoom} = $zoom;
+ $self->open;
+ return $self;
}
sub to_zoom {
# If this turns out to merely re-aim the gun at your left nipple, please
# come complain with a documented use case and we'll discuss deleting it.
die "Already started reading - there ain't no going back now"
- if $self->{_stream};
- $self->{_zoom}
+ if *$self->{_stream};
+ *$self->{_zoom}
}
sub getline {
my $self = shift;
my $html;
- my $stream = $self->{_stream} ||= $self->{_zoom}->to_stream;
- my $producer = $self->{_producer} ||= $self->{_zoom}->zconfig->producer;
+ my $stream = *$self->{_stream} ||= *$self->{_zoom}->to_stream;
+ my $producer = *$self->{_producer} ||= *$self->{_zoom}->zconfig->producer;
while (my ($evt) = $stream->next) {
$html .= $producer->event_to_html($evt);
last if $evt->{flush};
sub read {
my ($self, $buff, $len, $off) = @_;
$off = defined $off ? $off : 0;
- $self->{_pos} = defined $self->{_pos} ? $self->{_pos} + $off : $off;
- my $html = $self->{_html} ||= join '', $self->getlines;
- return if $self->{_pos} > length $html;
- $_[1] = substr $html, $self->{_pos}, $len;
+ *$self->{_pos} = defined *$self->{_pos} ? *$self->{_pos} + $off : $off;
+ my $html = *$self->{_html} ||= join '', $self->getlines;
+ return if length($html) < *$self->{_pos};
+ $_[1] = substr $html, *$self->{_pos}, $len;
unless(my $overflow = $len - length($buff)) {
$_[1] .= "\0" x $overflow;
}
- $self->{_pos} += $len;
+ *$self->{_pos} += $len;
}
-sub close { "The door shuts behind you with a ominous boom" }
+sub stat {
+
+ warn "GOT THE CUSSTOM STAT";
+
+ my $self = shift;
+ return 1 unless wantarray;
+ my $html = *$self->{_html} ||= join '', $self->getlines;
+ my $len = length $html;
+
+ return (
+ undef, undef, # dev, ino
+ 0666, # filemode
+ 1, # links
+ $>, # user id
+ $), # group id
+ undef, # device id
+ $len, # size
+ undef, # atime
+ undef, # mtime
+ undef, # ctime
+ 512, # blksize
+ int(($len+511)/512) # blocks
+ );
+}
1;