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
|
use strict;
use warnings;
package Debian::Upstream::Metadata::Perl;
our $VERSION = '0.129';
sub convert {
my ($class, $meta, $filename) = @_;
my %output;
$output{"Archive"} = 'CPAN';
# $output{"Name"} = $meta->{name};
# $output{"Contact"} = join( ', ', @{ $meta->{author} } );
# $output{"Homepage"} = $meta->{resources}->{homepage};
$output{"Bug-Database"} = $meta->{resources}->{bugtracker}->{web};
$output{"Bug-Submit"} = $meta->{resources}->{bugtracker}->{mailto};
$output{"Repository"} = $meta->{resources}->{repository}->{url};
$output{"Repository-Browse"} = $meta->{resources}->{repository}->{web};
# we don't care to write debian/upstream/metadata
# if we don't have a Repository
return unless defined $output{"Repository"};
my $fix_browse = ! defined $output{"Repository-Browse"};
my $url_parser = qr|(?:([^:/?\#]+):)? # protocol
(?://([^/?\#]*))? # domain name
([^?\#]*) # path
(?:\?([^\#]*))? # query
(?:\#(.*))? # fragment
|x;
my ($protocol, $domain, $path, $query, $fragment)
= $output{"Repository"} =~ $url_parser;
# fixups:
# strip user@, e.g. 'ssh://git@github.com/user/project.git'
$domain =~ s|^[^@]+@||;
# handle : after host, e.g.'git://git@github.com:user/project.git'
if ( $domain =~ m/:/ ) {
my ( $domainpart, $userpart ) = split /:/, $domain;
$domain = $domainpart;
$path = '/' . $userpart . $path;
}
my $host = {
'github.com' => 'github',
'gitlab.com' => 'gitlab',
'bitbucket.org' => 'bitbucket',
}->{$domain};
if (defined $host) {
if ($protocol ne "https") {
$output{"Repository"} = "https://$domain$path";
}
if ($fix_browse) {
$path =~ s/\.git$//;
$output{"Repository-Browse"} = "https://$domain$path";
}
# fix remaining non-HTTPS URLs
foreach ( qw(
Bug-Database
Bug-Submit
Repository
Repository-Browse
)) {
$output{$_} =~ s|^http://|https://| if $output{$_};
}
}
# GitHub fixups
if ( defined $output{"Bug-Database"}
&& $output{"Bug-Database"} =~ /github\.com.+issues\/?$/
&& !$output{"Bug-Submit"} )
{
$output{"Bug-Database"} =~ s/\/$//;
$output{"Bug-Submit"} = $output{"Bug-Database"} . '/new';
}
if ( defined $output{"Repository"}
&& $output{"Repository"} =~ /github\.com/
&& $output{"Repository"} !~ /\.git$/ )
{
$output{"Repository"} =~ s/\/$//;
$output{"Repository"} .= '.git';
}
foreach (keys %output) {
delete $output{$_} unless defined $output{$_};
}
require File::Spec;
my ($vol, $dir, $file) = File::Spec->splitpath($filename);
require File::Path;
File::Path::make_path($dir);
require YAML::XS;
YAML::XS::DumpFile($filename, \%output);
}
1;
__END__
=head1 NAME
Debian::Upstream::Metadata::Perl -- debian/upstream/metadata for Perl modules
=head1 SYNOPSIS
use Debian::Upstream::Metadata::Perl;
Debian::Upstream::Metadata::Perl->convert(
CPAN::Meta->new('META.yaml'),
'debian/upstream/metadata');
=head1 DESCRIPTION
C<Debian::Upstream::Metadata::Perl> is a helper module which can be used to
convert the data in a L<CPAN::Meta> object to a F<debian/upstream/metadata> files,
according to the UpstreamMetadata specification.
Please, note that upstream links will be switched to https URLs.
=head1 METHODS
=over
=item convert (L<CPAN::Meta> object, filename)
Not exported function, cf. L<SYNOPSIS>.
=back
=head1 SEE ALSO
=over
=item *
L<CPAN::Meta::Spec>
=item *
L<UpstreamMetadata|https://wiki.debian.org/UpstreamMetadata>
=back
=head1 COPYRIGHT AND LICENSE
=over
=item Copyright 2013-2021, gregor herrmann L<gregoa@debian.org>
=item Copyright 2016, Alex Muntada L<alexm@alexm.org>
=item Copyright 2022, Damyan Ivanov L<dmn@debian.org>
=back
This program is free software and can be distributed under the same terms as
Perl.
|