Changeset 22825


Ignore:
Timestamp:
09/09/10 10:39:11 (17 months ago)
Author:
alex
Message:

Removed dependence on IO::String, made sure the error phrase is parsed correctly from the header (set a limit on split) and added a content attribute, as the Socket implementation isn't working happily with tomcat.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/mnw21/pathquery_refactor/intermine/perl/lib/InterMine/ResultIterator.pm

    r22674 r22825  
    33use Moose; 
    44use InterMine::TypeLibrary qw(HTTPCode NetHTTP PathList TextCSVXS); 
    5 use MooseX::Types::Moose qw(Str HashRef Bool Num); 
     5use MooseX::Types::Moose qw(Str HashRef Bool Num GlobRef); 
    66use HTTP::Status qw(status_message); 
    77use Text::CSV_XS; 
    8 use IO::String; 
    98use List::MoreUtils qw(zip); 
    109use Encode; 
     
    1211my $CRLF = "\015\012"; 
    1312 
    14 has connection => 
    15     ( 
    16      is => 'ro', 
    17      isa => NetHTTP, 
    18      required => 1, 
    19      trigger => \&set_headers, 
    20     ); 
     13sub BUILD { 
     14    my $self = shift; 
     15    confess "We need a connection or some content" 
     16    unless ($self->has_connection or $self->has_content); 
     17} 
     18 
     19has connection => ( 
     20    is => 'ro', 
     21    isa => NetHTTP, 
     22    trigger => \&set_headers, 
     23    predicate => 'has_connection', 
     24); 
     25 
     26has content => ( 
     27    is => 'ro', 
     28    isa => GlobRef, 
     29    predicate => 'has_content', 
     30); 
    2131 
    2232has error_code => 
     
    2535     isa => HTTPCode, 
    2636     writer => '_set_error_code', 
     37     predicate => 'has_code', 
    2738    ); 
    2839 
     
    3445     writer => '_set_error_message', 
    3546    ); 
     47 
     48before qr/^error_/ => sub { 
     49    my $self = shift; 
     50    unless ($self->has_code) { 
     51    $self->set_headers; 
     52    } 
     53}; 
    3654 
    3755has csv => 
     
    108126    my ($version, $code, $phrase, $key, $value); 
    109127    if ($line =~ /^HTTP/) { 
    110         chomp(($version, $code, $phrase) = split(/\s/, $line)); 
     128        chomp(($version, $code, $phrase) = split(/\s/, $line, 3)); 
    111129    } else { 
    112130        chomp(($key, $value) = split(/:\s*/, $line, 2)); 
     
    141159} 
    142160 
     161####### FOR USE WITH SOCKETS 
     162 
    143163sub read_line { 
    144164    my $self= shift; 
     165    if ($self->has_content) { 
     166    return $self->content->getline; 
     167    } 
    145168    return undef if $self->is_finished; 
    146169    if ($self->is_chunked and $self->chunk_bytes_left < 1) { 
     
    189212sub arrayref { 
    190213    my $self = shift; 
    191     my $io   = IO::String->new($self->string); 
     214    my $line = $self->string or return; 
     215    open(my $io, '<', \$line) or die $!; 
    192216    return $self->csv->getline($io); 
    193217} 
    194218sub hashref { 
    195219    my $self = shift; 
    196     my $io   = IO::String->new($self->string); 
     220    my $line = $self->string or return; 
     221    open(my $io, '<', \$line) or die $!; 
    197222    return $self->csv->getline_hr($io); 
    198223} 
Note: See TracChangeset for help on using the changeset viewer.