Skip to content

Commit

Permalink
Merge branch 'refactor/gentoo_cpan' into upstream_master
Browse files Browse the repository at this point in the history
* refactor/gentoo_cpan:
  fix POD for transformCPAN() and tweak it a little
  add tests for transformCPAN()
  cleanup new() from all unnecessary stuff, now it's a tiny one
  refactor: use separate var for access to CPAN dist info
  rename test and update it to manage Gentoo::CPAN instead of Gentoo
  • Loading branch information
bor committed Nov 25, 2016
2 parents 79a9be8 + 40a9aa6 commit af82b13
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 44 deletions.
2 changes: 1 addition & 1 deletion MANIFEST
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ README.md
t/00_Gentoo.t
t/01_Gentoo_Portage_Q.t
t/05_Gentoo_Portage.t
t/10cpan_packages.t
t/06_Gentoo_CPAN.t
t/11_App_gcpan.t
t/98_changes.t
t/98_eol.t
Expand Down
49 changes: 19 additions & 30 deletions lib/Gentoo/CPAN.pm
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,8 @@ use constant DEF_BASH_PROG => '/bin/bash';
unless ( $ENV{TMPDIR} ) { $ENV{TMPDIR} = '/var/tmp/g-cpan' }

sub new {
my $proto = shift;
my %args = @_;
my $class = ref($proto) || $proto;
my $self = {};

$self->{cpan} = {};
$self->{DEBUG} = $args{debug}||"";

bless( $self, $class );
return $self;
my $class = shift;
return bless {}, $class;
}

##### - CPAN OVERRIDE - #####
Expand Down Expand Up @@ -143,12 +135,15 @@ sub getCPANInfo {
$desc =~ s/^$module_name - //g;
return $desc;
}
$self->{'cpan'}{ lc($find_module) }{'description'} =
$mod->{RO}{'description'} || manpage_title($mod, $find_module) || "No description available";
$self->{'cpan'}{ lc($find_module) }{'src_uri'} = $mod->{RO}{'CPAN_FILE'};
$self->{'cpan'}{ lc($find_module) }{'name'} = $mod->id;
$self->{'cpan'}{ lc($find_module) }{'version'} = $mod->{RO}{'CPAN_VERSION'}
|| "0";

my $dist_info = $self->{cpan}{ lc($find_module) };
$dist_info->{description} =
$mod->{RO}{description} || manpage_title( $mod, $find_module ) || 'No description available';
$dist_info->{src_uri} = $mod->{RO}{CPAN_FILE};
$dist_info->{name} = $mod->id;
$dist_info->{version} = $mod->{RO}{CPAN_VERSION} || '0';
$self->{cpan}{ lc($find_module) } = $dist_info;

return;
}

Expand Down Expand Up @@ -431,11 +426,11 @@ sub yaml_load {
return if $@;
return $yaml;
}

sub transformCPAN {
my $self = shift;
my $name = shift;
my $req = shift;
return unless ( defined($name) );
my ( $self, $name, $req ) = @_;
return unless $name;

my $re_path = '(?:.*)?';
my $re_pkg = '(?:.*)?';
my $re_ver = '(?:v?[\d\.]+[a-z]?\d*)?';
Expand Down Expand Up @@ -475,14 +470,8 @@ sub transformCPAN {
if ( substr( $filenamever, 0, 1 ) eq '.' ) {
$filenamever = 0 . $filenamever;
}
if ($req eq "v")
{
return ($filenamever);
}
else
{
return ($filename);
}

return ( $req eq 'v' ) ? $filenamever : $filename;
}

sub makeCPANstub {
Expand Down Expand Up @@ -632,9 +621,9 @@ Grabs the module from CPAN and unpacks it. It then proceeds to scan for
dependencies, filling in $obj->{'cpan'}{lc($somemodule)}{'depends'} with and
deeps that were found (hash).
=item $obj->transformCPANVersion($somemodule)
=item $obj->transformCPAN($somemodule, 'v')
=item $obj->transformCPANName($somemodule)
=item $obj->transformCPAN($somemodule, 'n')
Returns a portage friend version or module name from the name that is used on
CPAN. Useful for modules that use names or versions that would break as a
Expand Down
34 changes: 21 additions & 13 deletions t/10cpan_packages.t → t/06_Gentoo_CPAN.t
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,29 @@ elsif ( $needs_cpan_stub and not _init_cpan_config() ) {
plan skip_all => 'Tests impossible without a configured CPAN::Config';
}
else {
plan tests => 3;
plan tests => 4;
}

use_ok('Gentoo');
my $GC = new_ok('Gentoo');

my $module = 'Module::Build';
subtest "retrieve and check information for $module", sub {
$GC->getCPANInfo($module);
my $module_lc = lc($module);
ok( $GC->{cpan}{$module_lc}, 'information obtained' );
ok( $GC->{cpan}{$module_lc}{version}, 'has version' );
ok( $GC->{cpan}{$module_lc}{name}, 'has a name' );
ok( $GC->{cpan}{$module_lc}{src_uri}, 'has src_uri' );
ok( $GC->{cpan}{$module_lc}{description}, 'has a description' );
use_ok('Gentoo::CPAN');
my $cpan = new_ok('Gentoo::CPAN');

my $module = 'Module::Build';
my $module_lc = lc($module);

subtest "getCPANInfo('$module')", sub {
$cpan->getCPANInfo($module);
ok( $cpan->{cpan}{$module_lc}, 'information obtained' );
ok( $cpan->{cpan}{$module_lc}{version}, 'has version' );
ok( $cpan->{cpan}{$module_lc}{name}, 'has a name' );
ok( $cpan->{cpan}{$module_lc}{src_uri}, 'has src_uri' );
ok( $cpan->{cpan}{$module_lc}{description}, 'has a description' );
};

subtest "transformCPAN('$cpan->{cpan}{$module_lc}{src_uri}', 'n'|'v')", sub {
my $name = $cpan->transformCPAN( $cpan->{cpan}{$module_lc}{src_uri}, 'n' );
is( $name, 'Module-Build', '"name" is OK' );
my $version = $cpan->transformCPAN( $cpan->{cpan}{$module_lc}{src_uri}, 'v' );
like( $version, qr/^\d[\d\.]+\d$/, '"version" is OK' );
};

sub _init_cpan_config {
Expand Down

0 comments on commit af82b13

Please sign in to comment.