Skip to content

Commit dc055b9

Browse files
committed
Consolidate config creation into MetaCPAN::Server::Config
1 parent ed70092 commit dc055b9

File tree

17 files changed

+88
-169
lines changed

17 files changed

+88
-169
lines changed

etc/metacpan_testing.pl

Lines changed: 0 additions & 12 deletions
This file was deleted.

lib/Catalyst/Plugin/Session/Store/ElasticSearch.pm

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@ use Moose;
66
extends 'Catalyst::Plugin::Session::Store';
77
use MooseX::Types::ElasticSearch qw( ES );
88

9-
use MetaCPAN::Config ();
9+
use MetaCPAN::Server::Config ();
1010

1111
has _session_es => (
1212
required => 1,
1313
is => 'ro',
1414
coerce => 1,
1515
isa => ES,
16-
default => sub { MetaCPAN::Config::config()->{elasticsearch_servers} },
16+
default =>
17+
sub { MetaCPAN::Server::Config::config()->{elasticsearch_servers} },
1718
);
1819
has _session_es_index => (
1920
required => 1,

lib/MetaCPAN/Role/HasConfig.pm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package MetaCPAN::Role::HasConfig;
22

33
use Moose::Role;
44

5-
use MetaCPAN::Config ();
5+
use MetaCPAN::Server::Config ();
66
use MetaCPAN::Types::TypeTiny qw( HashRef );
77
use MetaCPAN::Util qw( checkout_root );
88

@@ -20,7 +20,7 @@ has _config => (
2020

2121
sub _build_config {
2222
my $self = shift;
23-
return MetaCPAN::Config::config();
23+
return MetaCPAN::Server::Config::config();
2424
}
2525

2626
1;

lib/MetaCPAN/Role/Logger.pm

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ package MetaCPAN::Role::Logger;
22

33
use v5.10;
44
use Moose::Role;
5-
use Log::Contextual qw( set_logger );
5+
6+
use Log::Contextual qw( set_logger );
67
use Log::Log4perl ':easy';
78
use MetaCPAN::Types::TypeTiny qw( Logger Str );
8-
use Path::Tiny qw( path );
9+
use Path::Tiny qw( path );
910

1011
has level => (
1112
is => 'ro',
@@ -45,8 +46,6 @@ sub set_logger_once {
4546
return;
4647
}
4748

48-
# XXX NOT A MOOSE BUILDER
49-
# XXX This doesn't belong here.
5049
sub _build_logger {
5150
my ($config) = @_;
5251
my $log = Log::Log4perl->get_logger( $ARGV[0]

lib/MetaCPAN/Role/Script.pm

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,14 @@ use Moose::Role;
55
use Carp ();
66
use ElasticSearchX::Model::Document::Types qw( ES );
77
use File::Path ();
8-
use IO::Prompt ();
8+
use IO::Prompt::Tiny qw( prompt );
99
use Log::Contextual qw( :log :dlog );
1010
use MetaCPAN::Model ();
1111
use MetaCPAN::Types::TypeTiny qw( Bool HashRef Int Path Str );
1212
use MetaCPAN::Util qw( checkout_root );
1313
use Mojo::Server ();
1414
use Term::ANSIColor qw( colored );
1515

16-
use IO::Prompt::Tiny qw( prompt );
17-
1816
with( 'MetaCPAN::Role::HasConfig', 'MetaCPAN::Role::Fastly',
1917
'MetaCPAN::Role::Logger' );
2018

lib/MetaCPAN/Script/Mapping.pm

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,6 @@ sub delete_all {
254254
|| $runtime_environment eq 'testing';
255255

256256
if ($is_development) {
257-
$self->are_you_sure("ALL Indices will be deleted !!!");
258-
259257
foreach my $name ( keys %{ $self->indices_info } ) {
260258
$self->_delete_index($name);
261259
}

lib/MetaCPAN/Script/Runner.pm

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ package MetaCPAN::Script::Runner;
33
use strict;
44
use warnings;
55

6-
use Config::ZOMG ();
7-
use File::Path ();
8-
use Hash::Merge::Simple qw( merge );
6+
use File::Path ();
7+
use MetaCPAN::Server::Config ();
8+
use Module::Pluggable qw( plugins );
9+
use Module::Pluggable qw( plugins );
910
use Module::Pluggable search_path => ['MetaCPAN::Script'];
1011
use Module::Runtime ();
1112
use Term::ANSIColor qw( colored );
@@ -21,7 +22,8 @@ sub run {
2122
die "Usage: metacpan [command] [args]" unless ($class);
2223
Module::Runtime::require_module( $plugins{$class} );
2324

24-
my $config = build_config();
25+
my $config = MetaCPAN::Server::Config::config();
26+
$config->{es} = $config->{elasticsearch_servers};
2527

2628
foreach my $logger ( @{ $config->{logger} || [] } ) {
2729
my $path = $logger->{filename} or next;
@@ -75,21 +77,6 @@ sub run {
7577
return ( $EXIT_CODE == 0 );
7678
}
7779

78-
sub build_config {
79-
my $config = Config::ZOMG->new(
80-
name => 'metacpan',
81-
path => 'etc'
82-
)->load;
83-
if ( $ENV{HARNESS_ACTIVE} ) {
84-
my $tconf = Config::ZOMG->new(
85-
name => 'metacpan',
86-
file => 'etc/metacpan_testing.pl'
87-
)->load;
88-
$config = merge $config, $tconf;
89-
}
90-
return $config;
91-
}
92-
9380
# AnyEvent::Run calls the main method
9481
*main = \&run;
9582

lib/MetaCPAN/Script/Snapshot.pm

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use DateTime ();
88
use DateTime::Format::ISO8601 ();
99
use HTTP::Tiny ();
1010
use Log::Contextual qw( :log );
11-
use MetaCPAN::Config ();
11+
use MetaCPAN::Server::Config ();
1212
use MetaCPAN::Types::TypeTiny qw( ArrayRef Bool Str );
1313
use Moose;
1414
use Sys::Hostname qw( hostname );
@@ -82,7 +82,8 @@ has snap_name => (
8282
has host => (
8383
is => 'ro',
8484
isa => Str,
85-
default => sub { MetaCPAN::Config::config()->{elasticsearch_servers} },
85+
default =>
86+
sub { MetaCPAN::Server::Config::config()->{elasticsearch_servers} },
8687
documentation => 'ES host, defaults to: http://localhost:9200',
8788
);
8889

lib/MetaCPAN/Config.pm renamed to lib/MetaCPAN/Server/Config.pm

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
package MetaCPAN::Config;
1+
package MetaCPAN::Server::Config;
22

33
use warnings;
44
use strict;
55

6-
use FindBin ();
76
use Config::ZOMG ();
7+
use FindBin ();
88
use Module::Runtime qw( require_module );
99

1010
sub config {
@@ -14,10 +14,16 @@ sub config {
1414
require_module('Git::Helpers');
1515
$config = _zomg( Git::Helpers::checkout_root() );
1616

17-
return $config if $config;
17+
if ( !$config ) {
18+
die "Couldn't find config file in $FindBin::RealBin/.. or "
19+
. Git::Helpers::checkout_root();
20+
}
21+
22+
if ( defined $config->{logger} && ref $config->{logger} ne 'ARRAY' ) {
23+
$config->{logger} = [ $config->{logger} ];
24+
}
1825

19-
die "Couldn't find config file in $FindBin::RealBin/.. or "
20-
. Git::Helpers::checkout_root();
26+
return $config;
2127
}
2228

2329
sub _zomg {

lib/MetaCPAN/Server/Model/CPAN.pm

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ package MetaCPAN::Server::Model::CPAN;
22

33
use Moose;
44

5-
use MetaCPAN::Config ();
6-
use MetaCPAN::Model ();
5+
use MetaCPAN::Model ();
6+
use MetaCPAN::Server::Config ();
77

88
extends 'Catalyst::Model';
99

@@ -22,7 +22,7 @@ has index => (
2222
has servers => (
2323
is => 'ro',
2424
default => sub {
25-
return MetaCPAN::Config::config()->{elasticsearch_servers};
25+
return MetaCPAN::Server::Config::config()->{elasticsearch_servers};
2626
},
2727
);
2828

metacpan_server.conf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
git /usr/bin/git
22

3+
level info
34
elasticsearch_servers = :9200
45
minion_dsn = postgresql:///minion_queue
56

7+
<logger>
8+
class Log::Log4perl::Appender::File
9+
filename ../var/log/metacpan.log
10+
syswrite 1
11+
</logger>
12+
613
<controller User::Turing>
714
# required for server startup -- override this in metacpan_server_local.conf
815
private_key 59125ffc09413eed3f2a2c07a37c7a44b95633e2

metacpan_server_testing.conf

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
cpan var/t/tmp/fakecpan
2+
die_on_error 1
3+
level warn
24
source_base var/t/tmp/source
35

4-
elasticsearch_servers = http://elasticsearch_test:9200
6+
elasticsearch_servers = elasticsearch_test:9200
7+
8+
<logger>
9+
class Log::Log4perl::Appender::Screen
10+
name testing
11+
</logger>
512

613
<model CPAN>
714
servers __ENV(ES)__

t/config.t

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
use strict;
44
use warnings;
55

6-
use MetaCPAN::Config ();
6+
use MetaCPAN::Server::Config ();
77
use Test::More import => [qw( done_testing ok )];
88

9-
my $config = MetaCPAN::Config::config();
9+
my $config = MetaCPAN::Server::Config::config();
1010
ok($config);
1111

1212
done_testing();

t/lib/MetaCPAN/Server/Test.pm

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ package MetaCPAN::Server::Test;
33
use strict;
44
use warnings;
55

6-
use HTTP::Request::Common qw( DELETE GET POST ); ## no perlimports
7-
use MetaCPAN::Config ();
8-
use MetaCPAN::Server ();
9-
use Plack::Test qw( test_psgi ); ## no perlimports
6+
use HTTP::Request::Common qw( DELETE GET POST ); ## no perlimports
7+
use MetaCPAN::Server ();
8+
use MetaCPAN::Server::Config ();
9+
use Plack::Test qw( test_psgi ); ## no perlimports
1010
use Test::More;
1111

1212
use base 'Exporter';
@@ -43,7 +43,9 @@ use MetaCPAN::Model ();
4343
sub model {
4444
MetaCPAN::Model->new(
4545
es => (
46-
nodes => [ MetaCPAN::Config::config()->{elasticsearch_servers} ]
46+
nodes => [
47+
MetaCPAN::Server::Config::config()->{elasticsearch_servers}
48+
]
4749
)
4850
);
4951
}

t/lib/MetaCPAN/TestHelpers.pm

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
package MetaCPAN::TestHelpers;
2+
13
use strict;
24
use warnings;
35

@@ -7,10 +9,10 @@ package # no_index
79
use Cpanel::JSON::XS qw( decode_json encode_json );
810
use File::Copy qw( copy );
911
use File::pushd qw( pushd );
10-
use FindBin ();
11-
use MetaCPAN::Script::Runner ();
12+
use MetaCPAN::Server::Config ();
1213
use MetaCPAN::Util qw( checkout_root );
1314
use Path::Tiny qw( path );
15+
use Test::More import => [qw( diag is ok )];
1416
use Test::More;
1517
use Test::Routine::Util qw( run_tests );
1618
use Try::Tiny qw( catch finally try );
@@ -98,13 +100,7 @@ sub test_release {
98100
}
99101

100102
sub get_config {
101-
my $config = do {
102-
103-
# build_config expects test to be t/*.t
104-
local $FindBin::RealBin = path( checkout_root(), 't' );
105-
MetaCPAN::Script::Runner->build_config;
106-
};
107-
return $config;
103+
return MetaCPAN::Server::Config::config();
108104
}
109105

110106
sub tmp_dir {

0 commit comments

Comments
 (0)