FetchPath

=title class Zef::Service::FetchPath
=subtitle A file system based implementation of the Fetcher and Extractor interfaces

Synopsis

    use Zef;
    use Zef::Service::FetchPath;
    my $fetch-path = Zef::Service::FetchPath.new;
    # Copy the content of the current directory to ./backup_dir/$random/*
    my $source   = $*CWD;
    my $save-to  = $*CWD.child("backup_dir");
    my $saved-to = $fetch-path.fetch($source, $save-to);
    die "Failed to copy paths" unless $saved-to;
    say "The following top level paths now exist:";
    say "\t{$_.Str}" for $saved-to.dir;
    my $extract-to   = $*CWD.child("extracted_backup_dir");
    my $extracted-to = $fetch-path.extract($saved-to, $extract-to);
    die "Failed to extract paths" unless $extracted-to;
    say "The following top level paths now exist:";
    say "\t{$_.Str}" for $extracted-to.dir;

Description

Fetcher and Extractor class for handling local file paths.

You probably never want to use this unless its indirectly through Zef::Fetch or Zef::Extractor; handling files will generally be easier using core language functionality. This class exists to provide the means for fetching local paths using the Fetcher and Extractor interfaces that the e.g. git/http/tar fetching/extracting adapters use.

Methods

method probe

method probe(--> Bool:D)

Returns True if this module believes all run time prerequisites are met. Since the only prerequisite is a file system this always returns True

method fetch-matcher

method fetch-matcher(Str() $uri --> Bool:D) 

Returns True if this module knows how to fetch $uri, which it decides based on if $uri looks like a file path (i.e. $uri starts with a . or /) and if that file path exists.

method extract-matcher

method extract-matcher(Str() $uri --> Bool:D) 

Returns True if this module knows how to extract $uri, which it decides based on if $uri looks like a file path (i.e. $uri starts with a . or /) and if that file path exists as a directory.

method fetch

method fetch(IO() $source-path, IO() $save-to, Supplier :$stdout, Supplier :$stderr --> IO::Path)

Fetches the given $source-path from the file system and copies it to $save-to (+ timestamp if $source-path is a directory) directory. A Supplier can be supplied as :$stdout and :$stderr to receive any output.

On success it returns the IO::Path where the data was actually saved to (usually a subdirectory under the passed-in $save-to). On failure it returns Nil.

method extract

method extract(IO() $source-path, IO() $save-to, Supplier :$stdout, Supplier :$stderr --> IO::Path)

Extracts the given $source-path from the file system and copies it to $save-to. A Supplier can be supplied as :$stdout and :$stderr to receive any output.

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

method ls-files

method ls-files(IO() $path --> Array[Str])

On success it returns an Array of relative paths that are available to be extracted from $path.

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