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 http://github.com/ 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).
new
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.
username
The repository method returns the GitHub repository name for the request.
repository
The branch method returns the name of the branch to be fetched.
branch
The url method returns the full download URL used to fetch the zipball.
url
The http method returns the HTTP client that will be used for the request.
http
The archive method will return the absolute path to the downloaded zip file on disk, if the download was successful.
archive
Returns undef if the download was not completed successfully.
undef
The archive_extract method will return the Archive::Extract object used to extract the files from the zipball, whether or not it extracted successfully.
archive_extract
$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().
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.
.gz
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.
pushd
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.
extract_path
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.
files
To get the full path to an extracted file, you would use:
File::Spec->catfile( $to, $ae->files->[0] );
my $simple = $project->error; my $verbose = $project->error(1);
The error method returns the last encountered error as string.
error
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.
true
This also enables Carp::longmess errors, instead of the regular carp errors.
Carp::longmess
carp
Good for tracking down why things don't work with your particular setup.
Defaults to false.
false
This variable controls whether errors encountered internally by GitHub::Extract should be carp'd or not.
GitHub::Extract
Set to false to silence warnings. Inspect the output of the error() method manually to see what went wrong.
error()
Defaults to true.
Bugs should be reported via the CPAN bug tracker at
http://rt.cpan.org/NoAuth/ReportBug.html?Queue=GitHub-Extract
For other issues, contact the author.
Adam Kennedy <adamk@cpan.org>
Archive::Extract
http://github.com/
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.
To install GitHub::Extract, copy and paste the appropriate command in to your terminal.
cpanm
cpanm GitHub::Extract
CPAN shell
perl -MCPAN -e shell install GitHub::Extract
For more information on module installation, please visit the detailed CPAN module installation guide.