Skip to content

Commit 4c81a88

Browse files
committed
Make config easier to get for now
1 parent 29aef23 commit 4c81a88

File tree

2 files changed

+37
-26
lines changed

2 files changed

+37
-26
lines changed

lib/MetaCPAN/Config.pm

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package MetaCPAN::Config;
2+
3+
use warnings;
4+
use strict;
5+
6+
use FindBin ();
7+
use Config::ZOMG ();
8+
use Module::Runtime qw( require_module );
9+
10+
sub config {
11+
my $config = _zomg("$FindBin::RealBin/..");
12+
return $config if $config;
13+
14+
require_module('Git::Helpers');
15+
$config = _zomg( Git::Helpers::checkout_root() );
16+
17+
return $config if $config;
18+
19+
die "Couldn't find config file in $FindBin::RealBin/.. or "
20+
. Git::Helpers::checkout_root();
21+
}
22+
23+
sub _zomg {
24+
my $path = shift;
25+
26+
my $config = Config::ZOMG->new(
27+
local_suffix => $ENV{HARNESS_ACTIVE} ? 'testing' : 'local',
28+
name => 'metacpan_server',
29+
path => $path,
30+
);
31+
32+
return $config->open;
33+
}
34+
35+
1;

lib/MetaCPAN/Role/HasConfig.pm

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

33
use Moose::Role;
44

5-
use FindBin ();
6-
use Config::ZOMG ();
5+
use MetaCPAN::Config ();
76
use MetaCPAN::Types::TypeTiny qw( HashRef );
8-
use Module::Runtime qw( require_module );
97

108
# Done like this so can be required by a role
119
sub config {
@@ -20,30 +18,8 @@ has _config => (
2018
);
2119

2220
sub _build_config {
23-
my $self = shift;
24-
my $config = $self->_zomg("$FindBin::RealBin/..");
25-
return $config if $config;
26-
27-
require_module('Git::Helpers');
28-
$config = $self->_zomg( Git::Helpers::checkout_root() );
29-
30-
return $config if $config;
31-
32-
die "Couldn't find config file in $FindBin::RealBin/.. or "
33-
. Git::Helpers::checkout_root();
34-
}
35-
36-
sub _zomg {
3721
my $self = shift;
38-
my $path = shift;
39-
40-
my $config = Config::ZOMG->new(
41-
local_suffix => $ENV{HARNESS_ACTIVE} ? 'testing' : 'local',
42-
name => 'metacpan_server',
43-
path => $path,
44-
);
45-
46-
return $config->open;
22+
return MetaCPAN::Config::config();
4723
}
4824

4925
1;

0 commit comments

Comments
 (0)