Fetch

=title class Zef::Fetch
=subtitle A configurable implementation of the Fetcher interface

Synopsis

    use Zef;
    use Zef::Fetch;
    # Setup with a single fetcher backend
    my $fetcher = Zef::Fetch.new(
        backends => [
            { module => "Zef::Service::Shell::curl" },
            { module => "Zef::Service::Shell::wget" },
        ],
    );
    # Save the content of $uri to $save-to
    my $uri      = "https://httpbin.org/ip";
    my $save-to  = $*CWD.child("output.txt");
    my $saved-to = $fetcher.fetch(Candidate.new(:$uri), $save-to);
    say $saved-to ?? $saved-to.slurp !! "Failed to download and save";

Description

A Fetcher class that uses 1 or more other Fetcher instances as backends. It abstracts the logic to do 'grab this uri with the first backend that supports the given uri'.

Methods

method fetch-matcher

method fetch-matcher($path --> Bool:D)

Returns True if any of the probeable self.plugins know how to fetch $path.

method fetch

method fetch(Candidate $candi, IO() $save-to, Supplier :$logger, Int :$timeout --> IO::Path)

Fetches the files for $candi (usually as $candi.uri) to $save-to. If a backend fails to fetch for some reason (such as going over its :$timeout) the next matching backend will be used. Failure occurs when no backend was able to fetch the $candi.

An optional :$logger can be supplied to receive events about what is occurring.

An optional :$timeout can be passed to denote the number of seconds after which we'll assume failure.

On success it returns the IO::Path where the data was actually fetched to. On failure it returns Nil.

Note this differs from other 'Fetcher' adapters method fetch (i.e. the fetchers this uses as backends) which take a Str $uri as the first parameter, not a Candidate $candi.

The Camelia image is copyright 2009 by Larry Wall. "Raku" is trademark of the Yet Another Society. All rights reserved.