Changeset 22827


Ignore:
Timestamp:
09/09/10 10:41:25 (17 months ago)
Author:
alex
Message:

Can now apply roles to templates, and uses a content implementation of ResultIterator? rather than the socket based one

File:
1 edited

Legend:

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

    r22674 r22827  
    4141use InterMine::TypeLibrary qw(Uri Model TemplateFactory SavedQueryFactory ListFactory); 
    4242 
     43use IO::String; 
     44 
    4345=head2 new( $url, [$user, $pass] ) 
    4446 
     
    125127 
    126128 
    127 =head2 template( $name ) 
     129=head2 template( $name [$roles] ) 
    128130 
    129131This checks to see if there is a template of this name in the 
     
    146148    }, 
    147149    handles => { 
    148     template => 'get_template_by_name', 
    149     }, 
    150 ); 
     150    get_template => 'get_template_by_name', 
     151    }, 
     152); 
     153 
     154sub template { 
     155    my ($self, $name, $roles) = @_; 
     156    my $t = $self->get_template($name) or return; 
     157    return apply_roles($t, $roles); 
     158} 
    151159 
    152160has _saved_queries => ( 
     
    237245    my $view_list    = shift; 
    238246    my $roles        = shift; 
    239     my $connection = Net::HTTP->new(Host => $self->host) or 
    240       confess "Could not connect to host $@"; 
    241     $connection->write_request( 
    242     GET => $url, 
    243     'User-Agent' => USER_AGENT 
     247    # my $connection = Net::HTTP->new(Host => $self->host) or 
     248    #   confess "Could not connect to host $@"; 
     249    # $connection->write_request( 
     250    #   GET => $url, 
     251    #   'User-Agent' => USER_AGENT 
     252    # ); 
     253    my $resp = $self->agent->get($url); 
     254    my $content = $resp->content; 
     255    open(my $io, '<', \$content) or confess "$!"; 
     256    my $response = InterMine::ResultIterator->new( 
     257#   connection => $connection, 
     258    view_list  => $view_list, 
     259    error_code => $resp->code, 
     260    error_message => $resp->message, 
     261    content => $io, 
    244262    ); 
    245     my $response = InterMine::ResultIterator->new( 
    246                   connection    => $connection, 
    247                   view_list     => $view_list, 
    248                  ); 
    249     confess $response->status_line if $response->is_error; 
     263    confess $response->status_line, $resp->content 
     264    if $response->is_error; 
    250265    return apply_roles($response, $roles); 
    251266} 
Note: See TracChangeset for help on using the changeset viewer.