Skip to content

Instantly share code, notes, and snippets.

@dougwilson
Created March 13, 2011 00:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dougwilson/867743 to your computer and use it in GitHub Desktop.
Save dougwilson/867743 to your computer and use it in GitHub Desktop.
Hypothetical Test-Reporter-Transport-Metabase-CPANTesters distribution
This is a HYPOTHETICAL distribution to give easy secure access to
the CPAN Testers metabase over SSL with libwww-perl 6+.
# UPDATE
This distribution, even hypothetical as it was, is no longer needed
as a solution to the problem this module was written for has been
resolved. Please see
[CPAN Testers Metabase has a certificate](http://somethingdoug.com/thoughts/2011/03/15/cpan-testers-metabase-has-a-certificate/).
for information. The short script mentioned in the article to set
your `CPAN::Reporter` configuration back is included with this
distribution as `scripts/set_official_config.pl`. See `UNINSTALL`
for full instructions on how to uninstall the distribution.
To use this module for your CPAN::Reporter transport, edit your
`~/.cpanreporter/config.ini` file's transport directive to be
transport = Metabase::CPANTesters id_file ~/your/id_file.json
Note: I used Moose in these modules since they are hypothetical
and it made it much faster to create.
use Module::Build 0.36;
eval { check_cpan_reporter_config(); };
my $class = Module::Build->subclass(
class => 'My::Module::Build::WithUninstall',
code => <<' ...',
sub ACTION_uninstall {
my $self = shift;
if (exists $self->install_map->{write} && -e $self->install_map->{write}) {
require ExtUtils::Install;
# Get the destination packlist
my $packlist = $self->install_map->{write};
# Uninstall the files listed in the packlist
ExtUtils::Install::uninstall($packlist, $self->verbose);
}
}
...
);
my $build = $class->new(
module_name => 'Test::Reporter::Transport::Metabase::CPANTesters',
# Module that are required
requires => {
'File::ShareDir' => '1.03',
'IO::Socket::SSL' => 0,
'LWP::UserAgent' => '6.00',
'Metabase::Client::Simple' => '0.008',
'Moose' => '1.24',
'MooseX::NonMoose' => '0.19',
'Test::Reporter::Transport::Metabase' => '1.999008',
},
share_dir => 'share',
);
$build->create_build_script;
sub check_cpan_reporter_config {
# Load CPAN::Reporter configuration module
require CPAN::Reporter::Config;
# Open the configuration
my $config = CPAN::Reporter::Config::_open_config_file();
if (!$config) {
# Unable to read configuration
print <<" NOTE";
*************************** NOTE ***************************
After installation, please setup your CPAN::Reporter config
and set the transport line according to the README.
************************************************************
NOTE
return;
}
# Get the file name of the configuration
my $file_name = CPAN::Reporter::Config::_get_config_file();
# Read the transport configuration
my $transport = $config->{_}->{transport};
if (defined $transport) {
# Change the transport option into readable variables
my ($class, %args) = split m{\s+}mosx, $transport;
if ($class eq 'Metabase' &&
defined $args{uri} &&
$args{uri} eq 'https://metabase.cpantesters.org/api/v1/') {
# Looks like the user should change to this distribution
delete $args{uri};
my $transport_args = join q{ }, %args;
print <<" NOTE";
*************************** NOTE ***************************
After installation, please change your CPAN::Reporter config
file to use this transport. You can do this by modifying
$file_name
and replacing the line
transport = $transport
with
transport = Metabase::CPANTesters $transport_args
************************************************************
NOTE
}
}
return;
}
package Metabase::Client::CPANTesters 0.000;
use Moose 1.24;
use MooseX::NonMoose 0.19;
use File::ShareDir 1.03;
extends 'Metabase::Client::Simple';
around _ua => sub {
my $orig = shift;
my $self = shift;
my $ua_was_generated = !$self->{_ua};
# Get the standard generated UA
my $ua = $self->$orig(@_);
if ($ua_was_generated) {
# Add our SSL options to the UA
$ua->ssl_opts(SSL_ca_file => File::ShareDir::dist_file('Test-Reporter-Transport-Metabase-CPANTesters', 'metabase.cpantesters.org.crt'));
}
return $ua;
};
no Moose;
__PACKAGE__->meta->make_immutable;
1;
__END__
=head1 NAME
Metabase::Client::CPANTesters - HYPOTHETICAL Metabase client for CPAN Testers
package Test::Reporter::Transport::Metabase::CPANTesters 0.000;
use Moose 1.24;
use Test::Reporter::Transport::Metabase 1.999008;
has id_file => (
is => 'ro',
isa => 'Str',
required => 1,
);
has metabase_transport => (
is => 'ro',
isa => 'Test::Reporter::Transport::Metabase',
init_arg => undef,
lazy_build => 1,
handles => qr{.+}mosx,
);
has uri => (
is => 'ro',
isa => 'Str',
default => 'https://metabase.cpantesters.org/api/v1/',
);
sub _build_metabase_transport {
my $self = shift;
return Test::Reporter::Transport::Metabase->new(
client => 'Metabase::Client::CPANTesters',
id_file => $self->id_file,
uri => $self->uri,
);
}
no Moose;
__PACKAGE__->meta->make_immutable;
1;
__END__
=head1 NAME
Test::Reporter::Transport::Metabase::CPANTesters - HYPOTHETICAL Metabase transport for CPAN Testers
This is a HYPOTHETICAL distribution to give easy secure access to
the CPAN Testers metabase over SSL with libwww-perl 6+.
perl Build.PL
perl Build
perl Build installdeps
perl Build install
perl Build realclean
Build.PL
INSTALL
lib/Metabase/Client/CPANTesters.pm
lib/Test/Reporter/Transport/Metabase/CPANTesters.pm
MANIFEST
META.json
META.yml
README
scripts/set_official_config.pl
share/metabase.cpantesters.org.crt
UNINSTALL
{
"abstract" : "HYPOTHETICAL Metabase transport for CPAN Testers",
"author" : [
"unknown"
],
"dynamic_config" : 1,
"generated_by" : "Module::Build version 0.38, CPAN::Meta::Converter version 2.110580",
"license" : [
"unknown"
],
"meta-spec" : {
"url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec",
"version" : "2"
},
"name" : "Test-Reporter-Transport-Metabase-CPANTesters",
"prereqs" : {
"configure" : {
"requires" : {
"Module::Build" : "0.38"
}
},
"runtime" : {
"requires" : {
"File::ShareDir" : "1.03",
"IO::Socket::SSL" : 0,
"LWP::UserAgent" : "6.00",
"Metabase::Client::Simple" : "0.008",
"Moose" : "1.24",
"MooseX::NonMoose" : "0.19",
"Test::Reporter::Transport::Metabase" : "1.999008"
}
}
},
"provides" : {
"Metabase::Client::CPANTesters" : {
"file" : "lib/Metabase/Client/CPANTesters.pm",
"version" : 0
},
"Test::Reporter::Transport::Metabase::CPANTesters" : {
"file" : "lib/Test/Reporter/Transport/Metabase/CPANTesters.pm",
"version" : 0
}
},
"release_status" : "stable",
"version" : "0.000"
}
---
abstract: 'HYPOTHETICAL Metabase transport for CPAN Testers'
author:
- unknown
build_requires: {}
configure_requires:
Module::Build: 0.38
dynamic_config: 1
generated_by: 'Module::Build version 0.38, CPAN::Meta::Converter version 2.110580'
license: unknown
meta-spec:
url: http://module-build.sourceforge.net/META-spec-v1.4.html
version: 1.4
name: Test-Reporter-Transport-Metabase-CPANTesters
provides:
Metabase::Client::CPANTesters:
file: lib/Metabase/Client/CPANTesters.pm
version: 0
Test::Reporter::Transport::Metabase::CPANTesters:
file: lib/Test/Reporter/Transport/Metabase/CPANTesters.pm
version: 0
requires:
File::ShareDir: 1.03
IO::Socket::SSL: 0
LWP::UserAgent: 6.00
Metabase::Client::Simple: 0.008
Moose: 1.24
MooseX::NonMoose: 0.19
Test::Reporter::Transport::Metabase: 1.999008
version: 0.000
-----BEGIN CERTIFICATE-----
MIIDRjCCAq+gAwIBAgIJAJ6JIAAh+7ZVMA0GCSqGSIb3DQEBBQUAMHYxCzAJBgNV
BAYTAlVTMREwDwYDVQQIEwhOZXcgWW9yazERMA8GA1UEBxMITmV3IFlvcmsxHjAc
BgNVBAoTFUNQQU4gVGVzdGVycyBNZXRhYmFzZTEhMB8GA1UEAxMYbWV0YWJhc2Uu
Y3BhbnRlc3RlcnMub3JnMB4XDTEwMDIxODE5MjkyNVoXDTEyMTExNDE5MjkyNVow
djELMAkGA1UEBhMCVVMxETAPBgNVBAgTCE5ldyBZb3JrMREwDwYDVQQHEwhOZXcg
WW9yazEeMBwGA1UEChMVQ1BBTiBUZXN0ZXJzIE1ldGFiYXNlMSEwHwYDVQQDExht
ZXRhYmFzZS5jcGFudGVzdGVycy5vcmcwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJ
AoGBANrCjEpVS4lsgDcrYrSm0U6b64LwGlGEPkG80yvBmFvP+yue4KU0Z8MVNoZj
BF+cY73xP28Tg3xuGb4pbPmBo7XrQv6H4nzxLgcp0fljeI++Z70KYHPWZ34+zIao
67JJw0R656T8xpBaKZdstWnEhvRsjX7Bf8+ysK3xfCWKCZeLAgMBAAGjgdswgdgw
HQYDVR0OBBYEFM/97yImTvtUUhzWd6lfCd+7MiSHMIGoBgNVHSMEgaAwgZ2AFM/9
7yImTvtUUhzWd6lfCd+7MiSHoXqkeDB2MQswCQYDVQQGEwJVUzERMA8GA1UECBMI
TmV3IFlvcmsxETAPBgNVBAcTCE5ldyBZb3JrMR4wHAYDVQQKExVDUEFOIFRlc3Rl
cnMgTWV0YWJhc2UxITAfBgNVBAMTGG1ldGFiYXNlLmNwYW50ZXN0ZXJzLm9yZ4IJ
AJ6JIAAh+7ZVMAwGA1UdEwQFMAMBAf8wDQYJKoZIhvcNAQEFBQADgYEAShlhs/P3
YtOVisV6QNs56fKvTsHNxwg2+iP2EI5UmhYOwJdgsIic/QEKDEY73ve58MN3yehc
i3Kgjlkh8nw65TAxHnY47Bz4rAcMh/mxTXVXI/RQYZvWOWMdcHG5VPVZXm5krbZB
45FHcmV/Qb+Zig4ry/TAp7wrad4pH60ls/c=
-----END CERTIFICATE-----
#!/usr/bin/env perl
use 5.006;
use CPAN::Reporter::Config;
my $config_file = CPAN::Reporter::Config::_get_config_file();
my $config = CPAN::Reporter::Config::_open_config_file();
my ($class, %args) = split m{\s+}mosx, $config->{_}->{transport};
if ($class eq 'Metabase::CPANTesters') {
print "Modifying configuration file transport line from\n", $config->{_}->{transport}, "\n";
# Correct the transport information
$class = 'Metabase';
$args{uri} = 'https://metabase.cpantesters.org/api/v1/';
$config->{_}->{transport} = "$class " . join q{ }, %args;
print "to\n", $config->{_}->{transport}, "\n";
# Write the configuration
$config->write($config_file);
print "Done\n";
}
elsif ($config->{_}->{transport}) {
# Modification does not look necessary
print "Leaving transport configuration set to\n", $config->{_}->{transport}, "\n";
}
else {
# Modification does not look like it should occur
print "Not modifying configuration without transport directive\n";
}
exit 0;
This is a HYPOTHETICAL distribution to give easy secure access to
the CPAN Testers metabase over SSL with libwww-perl 6+.
Now that this distribution is no longer needed, here are the
uninstall instructions:
perl Build.PL
perl script/set_official_config.pl
perl Build uninstall
perl Build realclean
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment