Adam Kennedy > GitHub-Extract-0.02 > GitHub::Extract



Annotate this POD


New  1
Open  0
View/Report Bugs
Module Version: 0.02   Source  


GitHub::Extract - Extract an exported copy of a GitHub project


        my $project = GitHub::Extract->new(
                username => 'adamkennedy',
                project  => 'PPI',
        $project->extract( to => '/my/directory' );


GitHub::Extract is a simple light weight interface to for the sole purpose of retrieving and extracting a "zipball" of a public (and likely open source) project.

It makes use of the plain route used by the user interface "zip" button, and as a result it avoids the need to use the full GitHub API and client.

This module shares extends (and emulates where needed) the API of Archive::Extract. Any existing tooling code which uses Archive::Extract to work with release tarballs should be trivially upgradable to work with projects directly from GitHub instead.



        my $branch = GitHub::Extract->new(
                username   => 'adamkennedy',
                repository => 'PPI',

                # Fetch a branch other than master
                branch     => 'mybranch',

                # A custom HTTP client can be provided to any constructor
                http       => HTTP::Tiny->new(
                        # Custom HTTP setup goes here

The new constructor identifies a project to download (but does not take any immediate action to do the download).

It takes a number of simple parameters to control where to download from.


The GitHub username identifying the owner of the repository.


The name of the repository within the account or organisation.


An optional parameter identifying a particular branch to download. If not specificied, the 'master' branch will be fetched.


GitHub::Extract will create a HTTP::Tiny object with default settings to download the zipball from GitHub.

This parameter allows you to use your own custom HTTP::Tiny client with alternative settings.

Returns a new GitHub::Extract object, or false on error.


The username method returns the GitHub username for the request.


The repository method returns the GitHub repository name for the request.


The branch method returns the name of the branch to be fetched.


The url method returns the full download URL used to fetch the zipball.


The http method returns the HTTP client that will be used for the request.


The archive method will return the absolute path to the downloaded zip file on disk, if the download was successful.

Returns undef if the download was not completed successfully.


The archive_extract method will return the Archive::Extract object used to extract the files from the zipball, whether or not it extracted successfully.

Returns undef if the download was not completed successfully.


        $project->extract( to => '/output/path' );

Extracts the archive represented by the GitHub::Extract object to the path of your choice as specified by the to argument. Defaults to cwd().

In the case that you did not specify a to argument, the output file will be the name of the archive file, stripped from its .gz suffix, in the current working directory.

It will return true on success, and false on failure.


        my $guard = $project->pushd( to => '/output/path' );

The pushd method downloads and extracts the project from GitHub, and then temporarily changes the current working directory into the extract path of the project.

Returns a File::pushd guard object which will return the current working directory to the original location when it is deleted, or false if the archive was not extracted.


        # Prints '/output/path/myproject-0.01-af41bc'
        if ( $project->extract( to => '/output/path' ) ) {
                print $project->extract_path;

The extract_path method returns the absolute path of the logical root directory of the zipball, once it has been extracted.

Since some archives will contain a single root directory within the zip file with which the content is placed (and some will not) this compensates for the different, detecting the logical root automatically.

See "extract" in Archive::Extract for more details.


The files method returns an array ref with the paths of all the files in the archive, relative to the to argument you specified.

To get the full path to an extracted file, you would use:

    File::Spec->catfile( $to, $ae->files->[0] );

See "extract" in Archive::Extract for more details.


        my $simple  = $project->error;
        my $verbose = $project->error(1);

The error method returns the last encountered error as string.

Pass it a true value to get the detailed output instead, as produced by "longmess" in Carp.


All global variables share the names and behaviour of the equivalent variables in Archive::Extract. Their value will be propogated down to the equivalent variables in Archive::Extract whenever it is being used.


Set this variable to true to have all calls to command line tools be printed out, including all their output.

This also enables Carp::longmess errors, instead of the regular carp errors.

Good for tracking down why things don't work with your particular setup.

Defaults to false.


This variable controls whether errors encountered internally by GitHub::Extract should be carp'd or not.

Set to false to silence warnings. Inspect the output of the error() method manually to see what went wrong.

Defaults to true.


Bugs should be reported via the CPAN bug tracker at

For other issues, contact the author.


Adam Kennedy <>




Copyright 2012-2013 Adam Kennedy.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

The full text of the license can be found in the LICENSE file included with this module.

syntax highlighting: