Bio-Das
view release on metacpan or search on metacpan
Das/Request.pm view on Meta::CPAN
return unless $status;
}
return $parser->parse($data);
}
=item $request->finish_body()
This internal method is called by L<Bio::Das::HTTP::Fetch> when the
end of document is encountered.
=cut
# called to finish body data
sub finish_body {
my $self = shift;
$self->cleanup();
my $parser = $self->xml_parser or return;
my $result = $parser->eof;
$self->success(1);
1;
}
=item ($inflated_data,$status) = $request->inflate($data)
This internal method is called when processing compressed data. It
returns a two-element list consisting of the inflated data and a
true/false status code. A false status code means an error was
encountered during inflation, and ordinarily causes the parsing to
terminate.
=cut
# == inflation stuff ==
sub inflate {
my $self = shift;
my $compressed_data = shift;
# the complication here is that we might be called on a portion of the
# data stream that contains only a partial header. This is unlikely, but
# I'll be paranoid.
if (!$self->{p_i}) { # haven't created the inflator yet
$self->{p_gzip_header} .= $compressed_data;
my $cd = $self->{p_gzip_header};
return ('',1) if length $cd < 10;
# process header
my ($gzip_magic,$gzip_method,$comment,$time,undef,$os_magic)
= unpack("nccVcc",substr($cd,0,10));
return $self->error("506 Data decompression failure (not a gzip stream)")
unless $gzip_magic == GZIP_MAGIC;
return $self->error("506 Data decompression failure (unknown compression method)")
unless $gzip_method == Z_DEFLATED;
substr($cd,0,10) = ''; # truncate the rest
# handle embedded comments that proceed deflated stream
# note that we do not correctly buffer here, but assume
# that we've got it all. We don't bother doing this right,
# because the filename field is not usually present in
# the on-the-fly streaming done by HTTP servers.
if ($comment == 8 or $comment == 10) {
my ($fname) = unpack("Z*",$cd);
substr($cd,0,(length $fname)+1) = '';
}
$compressed_data = $cd;
delete $self->{p_gzip_header};
$self->{p_i} = inflateInit(-WindowBits => -MAX_WBITS() ) or return;
}
my ($out,$status) = $self->{p_i}->inflate($compressed_data);
return $self->error("506 Data decompression failure (inflation failed, errcode = $status)")
unless $status == Z_OK or $status == Z_STREAM_END;
return ($out,1);
}
=item $trimmed_string = $request->trim($untrimmed_string)
This internal method strips leading and trailing whitespace from a
string.
=cut
# utilities
sub trim {
my $self = shift;
my $string = shift;
$string =~ s/^\s+//;
$string =~ s/\s+$//;
$string;
}
=back
=head2 The Parsing Process
This module and its subclasses use an interesting object-oriented way
of parsing XML documents that is flexible without imposing a large
performance penalty.
When a tag start or tag stop is encountered, the tag and its
attributes are passed to the tag_starts() and tag_stops() methods
respectively. These methods both look for a defined method called
t_TAGNAME (where TAGNAME is replaced by the actual name of the tag).
If the method exists it is invoked, otherwise the tag and attribute
data are passed to the do_tag() method, which by default simply
ignores the tag.
A Bio::Das::Request subclass that wishes to process the
E<lt>FOOBARE<gt> tag, can therefore define a method called t_FOOBAR
which takes two arguments, the request object and the tag attribute
hashref. The method can distinguish between E<lt>FOOBARE<gt> and
E<lt>/FOOBARE<gt> by looking at the attribute argument, which will be
defined for the start tag and undef for the end tag. Here is a simple
example:
sub t_FOOBAR {
my $self = shift;
( run in 1.666 second using v1.01-cache-2.11-cpan-140bd7fdf52 )