Catmandu-Importer-getJSON

 view release on metacpan or  search on metacpan

lib/Catmandu/Importer/getJSON.pm  view on Meta::CPAN

    }

    if ( $self->wait and $self->time ) {
        my $elapsed = ( $self->time // time ) - time;
        sleep( $self->wait - $elapsed );
    }
    $self->time(time);

    my $response = $self->client->get( $url, $self->headers );
    if ( $response->is_success ) {
        my $content = $response->decoded_content;
        my $data    = $self->json->decode($content);
        $json = $self->response_hook($data);
    }
    else {
        warn "request failed: $url\n" if $self->warn;
        $self->log->warn("request failed: $url");
        if ( $response->status =~ /^4/ ) {
            $json = '';
        }
        else {

t/MockFurl.pm  view on Meta::CPAN

package MockFurl;
sub new { bless { @_ }, 'MockFurl' }
sub decoded_content {
    my $content = $_[0]->{content};
    ref $content ? $content->() : $content; 
}
sub urls { $_[0]->{urls} // [] } 
sub get { push @{$_[0]->{urls}}, $_[1]; $_[0] }
sub is_success { 1 }
1;



( run in 0.481 second using v1.01-cache-2.11-cpan-26ccb49234f )