Skip to content

Instantly share code, notes, and snippets.

@sartak
Forked from miyagawa/Repository.pm
Created March 19, 2009 20:53
Show Gist options
  • Save sartak/82056 to your computer and use it in GitHub Desktop.
Save sartak/82056 to your computer and use it in GitHub Desktop.
package Module::Install::Repository;
use strict;
use 5.008_001;
our $VERSION = '0.01';
use base qw(Module::Install::Base);
sub auto_set_repository {
my $self = shift;
return unless $Module::Install::AUTHOR;
my $repo = _find_repo();
if ($repo) {
$self->repository($repo);
} else {
warn "Cannot determine repository URL\n";
}
}
sub _find_repo {
if (-e ".git") {
# TODO support remote besides 'origin'?
if (`git remote show origin` =~ /URL: (.*)$/m) {
# XXX Make it public clone URL, but this only works with github
my $git_url = $1;
$git_url =~ s![\w\-]+\@([^:]+):!git://$1/!;
return $git_url;
}
} elsif (-e ".svn") {
if (`svn info` =~ /URL: (.*)$/m) {
return $1;
}
} elsif (-e "$ENV{HOME}/.svk") {
# Is there an explicit way to check if it's an svk checkout?
my $svk_info = `svk info` or return;
SVK_INFO: {
if ($svk_info =~ /Mirrored From: (.*), Rev\./) {
return $1;
}
if ($svk_info =~ m!Merged From: (/mirror/.*), Rev\.!) {
$svk_info = `svk info /$1` or return;
redo SVK_INFO;
}
}
return;
} elsif (-e "_darcs") {
# defaultrepo is better, but that is more likely to be ssh, not http
if (my $query_repo = `darcs query repo`) {
if ($query_repo =~ m!Default Remote: (http://.+)!) {
return $1;
}
}
open my $handle, '<', '_darcs/prefs/repos' or return;
while (<$handle>) {
chomp;
return $_ if m!^http://!;
}
}
}
1;
__END__
=encoding utf-8
=for stopwords
=head1 NAME
Module::Install::Repository -
=head1 SYNOPSIS
# in Makefile.PL
use Module::Install;
auto_set_repository;
=head1 DESCRIPTION
Module::Install::Repository is
=head1 AUTHOR
Tatsuhiko Miyagawa E<lt>miyagawa@bulknews.netE<gt>
=head1 LICENSE
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=head1 SEE ALSO
=cut
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment