/usr/share/perl5/Dist/Zilla/Plugin/Repository.pm is in libdist-zilla-plugin-repository-perl 0.21-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 | package Dist::Zilla::Plugin::Repository;
$Dist::Zilla::Plugin::Repository::VERSION = '0.21';
# ABSTRACT: Automatically sets repository URL from svn/svk/Git checkout for Dist::Zilla
use Moose;
with 'Dist::Zilla::Role::MetaProvider';
has git_remote => (
is => 'ro',
isa => 'Str',
default => 'origin',
);
has github_http => (
is => 'ro',
isa => 'Bool',
default => 0,
);
has _found_repo => (
is => 'ro',
isa => 'HashRef',
lazy_build => 1,
);
sub _build__found_repo {
my $self = shift;
my @info = $self->_find_repo(\&_execute);
unshift @info, 'url' if @info == 1;
my %repo = @info;
$repo{$_} ||= '' for qw(type url web);
return \%repo;
}
has 'repository' => (
is => 'ro',
isa => 'Str',
lazy_build => 1,
);
sub _build_repository {
shift->_found_repo->{url};
}
has type => (
is => 'ro',
isa => 'Str',
lazy => 1,
default => sub { shift->_found_repo->{type} },
);
has web => (
is => 'ro',
isa => 'Str',
lazy => 1,
default => sub { shift->_found_repo->{web} },
);
sub metadata {
my ($self, $arg) = @_;
my %repo;
$repo{url} = $self->repository if $self->repository;
$repo{type} = $self->type if $self->type;
$repo{web} = $self->web if $self->web;
return unless $repo{url} or $repo{web};
return {resources => {repository => \%repo}};
}
sub _execute {
my ($command) = @_;
$ENV{LC_ALL} = "C";
`$command`;
}
# Copy-Paste of Module-Install-Repository, thank MIYAGAWA
sub _find_repo {
my ($self, $execute) = @_;
my %repo;
if (-e ".git") {
$repo{type} = 'git';
if ($execute->('git remote show -n ' . $self->git_remote) =~ /URL: (.*)$/m) {
# XXX Make it public clone URL, but this only works with github
my $git_url = $1;
$git_url =~ s![\w\-]+\@([^:]+):!git://$1/!;
$repo{url} = $git_url unless $git_url eq 'origin'; # RT 55136
if ($git_url =~ /^(?:git|https?):\/\/((?:git(?:lab|hub)\.com|bitbucket.org).*?)(?:\.git)?$/) {
$repo{web} = "https://$1";
if ($self->github_http) {
# I prefer https://github.com/user/repository
# to git://github.com/user/repository.git
delete $repo{url};
$self->log("github_http is deprecated. "
. "Consider using META.json instead,\n"
. "which can store URLs for both git clone "
. "and the web front-end.");
} # end if github_http
} # end if Github repository
} elsif ($execute->('git svn info') =~ /URL: (.*)$/m) {
%repo = (qw(type svn url), $1);
}
# invalid github remote might come back with just the remote name
if ($repo{url} && $repo{url} =~ /\A\w+\z/) {
delete $repo{$_} for qw/url type web/;
$self->log("Skipping invalid git remote " . $self->git_remote);
}
} elsif (-e ".svn") {
$repo{type} = 'svn';
if ($execute->('svn info') =~ /URL: (.*)$/m) {
my $svn_url = $1;
if ($svn_url =~ /^https(\:\/\/.*?\.googlecode\.com\/svn\/.*)$/) {
$svn_url = 'http' . $1;
}
$repo{url} = $svn_url;
}
} elsif (-e "_darcs") {
# defaultrepo is better, but that is more likely to be ssh, not http
$repo{type} = 'darcs';
if (my $query_repo = $execute->('darcs query repo')) {
if ($query_repo =~ m!Default Remote: (http://.+)!) {
return %repo, url => $1;
}
}
open my $handle, '<', '_darcs/prefs/repos' or return;
while (<$handle>) {
chomp;
return %repo, url => $_ if m!^http://!;
}
} elsif (-e ".hg") {
$repo{type} = 'hg';
if ($execute->('hg paths') =~ /default = (.*)$/m) {
my $mercurial_url = $1;
$mercurial_url =~ s!^ssh://hg\@(bitbucket\.org/)!https://$1!;
$repo{url} = $mercurial_url;
}
} elsif (-e "$ENV{HOME}/.svk") {
# Is there an explicit way to check if it's an svk checkout?
my $svk_info = $execute->('svk info') or return;
SVK_INFO: {
if ($svk_info =~ /Mirrored From: (.*), Rev\./) {
return qw(type svn url) => $1;
}
if ($svk_info =~ m!Merged From: (/mirror/.*), Rev\.!) {
$svk_info = $execute->("svk info /$1") or return;
redo SVK_INFO;
}
}
}
return %repo;
}
__PACKAGE__->meta->make_immutable;
no Moose;
1;
__END__
=pod
=encoding UTF-8
=head1 NAME
Dist::Zilla::Plugin::Repository - Automatically sets repository URL from svn/svk/Git checkout for Dist::Zilla
=head1 VERSION
version 0.21
=head1 SYNOPSIS
# dist.ini
[Repository]
=head1 DESCRIPTION
The code is mostly a copy-paste of L<Module::Install::Repository>
=head2 ATTRIBUTES
=over 4
=item * git_remote
This is the name of the remote to use for the public repository (if
you use Git). By default, unsurprisingly, to F<origin>.
=item * github_http
B<This attribute is deprecated.>
If the remote is a GitHub repository, list only the https url
(https://github.com/fayland/dist-zilla-plugin-repository) and not the actual
clonable url (git://github.com/fayland/dist-zilla-plugin-repository.git).
This used to default to true, but as of 0.16 it defaults to false.
The CPAN Meta 2 spec defines separate keys for the clonable C<url> and
web front-end C<web>. The Meta 1 specs allowed only 1 URL. If you
set C<github_http> to true, the C<url> key will be removed from the v2
metadata, and the v1 metadata will then use the C<web> key.
Instead of setting C<github_http>, you should use the MetaJSON plugin
to include a v2 META.json file with both URLs.
=item * repository
You can set this attribute if you want a specific repository instead of the
plugin to auto-identify your repository.
An example would be if you're releasing a module from your fork, and you don't
want it to identify your fork, so you can specify the repository explicitly.
In the L<Meta 2 spec|CPAN::Meta::Spec>, this is the C<url> key.
=item * type
This should be the (lower-case) name of the most common program used
to work with the repository, e.g. git, svn, cvs, darcs, bzr or hg.
It's normally determined automatically, but you can override it.
=item * web
This is a URL pointing to a human-usable web front-end for the
repository. Currently, only Github repositories get this set automatically.
=back
=for Pod::Coverage metadata
=head1 AUTHORS
=over 4
=item *
Fayland Lam <fayland@gmail.com>
=item *
Ricardo SIGNES <rjbs@cpan.org>
=item *
Moritz Onken <onken@netcubed.de>
=item *
Christopher J. Madsen <perl@cjmweb.net>
=back
=head1 COPYRIGHT AND LICENSE
This software is copyright (c) 2017 by Fayland Lam, Ricardo SIGNES, Moritz Onken, Christopher J. Madsen.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
=cut
|