| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Module::Install::Repository; | 
| 2 |  |  |  |  |  |  |  | 
| 3 | 2 |  |  | 2 |  | 662 | use strict; | 
|  | 2 |  |  |  |  | 2 |  | 
|  | 2 |  |  |  |  | 64 |  | 
| 4 | 2 |  |  | 2 |  | 54 | use 5.005; | 
|  | 2 |  |  |  |  | 5 |  | 
|  | 2 |  |  |  |  | 63 |  | 
| 5 | 2 |  |  | 2 |  | 15 | use vars qw($VERSION); | 
|  | 2 |  |  |  |  | 2 |  | 
|  | 2 |  |  |  |  | 111 |  | 
| 6 |  |  |  |  |  |  | $VERSION = '0.06'; | 
| 7 |  |  |  |  |  |  |  | 
| 8 | 2 |  |  | 2 |  | 9 | use base qw(Module::Install::Base); | 
|  | 2 |  |  |  |  | 2 |  | 
|  | 2 |  |  |  |  | 1192 |  | 
| 9 |  |  |  |  |  |  |  | 
| 10 |  |  |  |  |  |  | sub _execute { | 
| 11 | 0 |  |  | 0 |  | 0 | my ($command) = @_; | 
| 12 | 0 |  |  |  |  | 0 | `$command`; | 
| 13 |  |  |  |  |  |  | } | 
| 14 |  |  |  |  |  |  |  | 
| 15 |  |  |  |  |  |  | sub auto_set_repository { | 
| 16 | 0 |  |  | 0 | 0 | 0 | my $self = shift; | 
| 17 |  |  |  |  |  |  |  | 
| 18 | 0 | 0 |  |  |  | 0 | return unless $Module::Install::AUTHOR; | 
| 19 |  |  |  |  |  |  |  | 
| 20 | 0 |  |  |  |  | 0 | my $repo = _find_repo(\&_execute); | 
| 21 | 0 | 0 |  |  |  | 0 | if ($repo) { | 
| 22 | 0 |  |  |  |  | 0 | $self->repository($repo); | 
| 23 |  |  |  |  |  |  | } else { | 
| 24 | 0 |  |  |  |  | 0 | warn "Cannot determine repository URL\n"; | 
| 25 |  |  |  |  |  |  | } | 
| 26 |  |  |  |  |  |  | } | 
| 27 |  |  |  |  |  |  |  | 
| 28 |  |  |  |  |  |  | sub _find_repo { | 
| 29 | 2 |  |  | 2 |  | 5 | my ($execute) = @_; | 
| 30 |  |  |  |  |  |  |  | 
| 31 | 2 | 100 |  |  |  | 64 | if (-e ".git") { | 
|  |  | 50 |  |  |  |  |  | 
|  |  | 50 |  |  |  |  |  | 
|  |  | 50 |  |  |  |  |  | 
|  |  | 0 |  |  |  |  |  | 
| 32 |  |  |  |  |  |  | # TODO support remote besides 'origin'? | 
| 33 | 1 | 50 |  |  |  | 6 | if ($execute->('git remote show -n origin') =~ /URL: (.*)$/m) { | 
|  |  | 0 |  |  |  |  |  | 
| 34 |  |  |  |  |  |  | # XXX Make it public clone URL, but this only works with github | 
| 35 | 1 |  |  |  |  | 17 | my $git_url = $1; | 
| 36 | 1 |  |  |  |  | 11 | $git_url =~ s![\w\-]+\@([^:]+):!git://$1/!; | 
| 37 | 1 |  |  |  |  | 9 | return $git_url; | 
| 38 |  |  |  |  |  |  | } elsif ($execute->('git svn info') =~ /URL: (.*)$/m) { | 
| 39 | 0 |  |  |  |  | 0 | return $1; | 
| 40 |  |  |  |  |  |  | } | 
| 41 |  |  |  |  |  |  | } elsif (-e ".svn") { | 
| 42 | 0 | 0 |  |  |  | 0 | if (`svn info` =~ /URL: (.*)$/m) { | 
| 43 | 0 |  |  |  |  | 0 | return $1; | 
| 44 |  |  |  |  |  |  | } | 
| 45 |  |  |  |  |  |  | } elsif (-e "_darcs") { | 
| 46 |  |  |  |  |  |  | # defaultrepo is better, but that is more likely to be ssh, not http | 
| 47 | 0 | 0 |  |  |  | 0 | if (my $query_repo = `darcs query repo`) { | 
| 48 | 0 | 0 |  |  |  | 0 | if ($query_repo =~ m!Default Remote: (http://.+)!) { | 
| 49 | 0 |  |  |  |  | 0 | return $1; | 
| 50 |  |  |  |  |  |  | } | 
| 51 |  |  |  |  |  |  | } | 
| 52 |  |  |  |  |  |  |  | 
| 53 | 0 | 0 |  |  |  | 0 | open my $handle, '<', '_darcs/prefs/repos' or return; | 
| 54 | 0 |  |  |  |  | 0 | while (<$handle>) { | 
| 55 | 0 |  |  |  |  | 0 | chomp; | 
| 56 | 0 | 0 |  |  |  | 0 | return $_ if m!^http://!; | 
| 57 |  |  |  |  |  |  | } | 
| 58 |  |  |  |  |  |  | } elsif (-e ".hg") { | 
| 59 | 1 | 50 |  |  |  | 5 | if ($execute->('hg paths') =~ /default = (.*)$/m) { | 
| 60 | 1 |  |  |  |  | 17 | my $mercurial_url = $1; | 
| 61 | 1 |  |  |  |  | 2 | $mercurial_url =~ s!^ssh://hg\@(bitbucket\.org/)!https://$1!; | 
| 62 | 1 |  |  |  |  | 7 | return $mercurial_url; | 
| 63 |  |  |  |  |  |  | } | 
| 64 |  |  |  |  |  |  | } elsif (-e "$ENV{HOME}/.svk") { | 
| 65 |  |  |  |  |  |  | # Is there an explicit way to check if it's an svk checkout? | 
| 66 | 0 | 0 |  |  |  |  | my $svk_info = `svk info` or return; | 
| 67 |  |  |  |  |  |  | SVK_INFO: { | 
| 68 | 0 | 0 |  |  |  |  | if ($svk_info =~ /Mirrored From: (.*), Rev\./) { | 
|  | 0 |  |  |  |  |  |  | 
| 69 | 0 |  |  |  |  |  | return $1; | 
| 70 |  |  |  |  |  |  | } | 
| 71 |  |  |  |  |  |  |  | 
| 72 | 0 | 0 |  |  |  |  | if ($svk_info =~ m!Merged From: (/mirror/.*), Rev\.!) { | 
| 73 | 0 | 0 |  |  |  |  | $svk_info = `svk info /$1` or return; | 
| 74 | 0 |  |  |  |  |  | redo SVK_INFO; | 
| 75 |  |  |  |  |  |  | } | 
| 76 |  |  |  |  |  |  | } | 
| 77 |  |  |  |  |  |  |  | 
| 78 | 0 |  |  |  |  |  | return; | 
| 79 |  |  |  |  |  |  | } | 
| 80 |  |  |  |  |  |  | } | 
| 81 |  |  |  |  |  |  |  | 
| 82 |  |  |  |  |  |  | 1; | 
| 83 |  |  |  |  |  |  | __END__ |