Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Initial code ( untested ) for version checking

  • Loading branch information...
commit a4e5a3412ba46efc2db94ebee3e6ff72258a5e51 1 parent ca6ef44
@kentfredric kentfredric authored
Showing with 32 additions and 7 deletions.
  1. +32 −7 lib/App/DuckPAN/Perl.pm
View
39 lib/App/DuckPAN/Perl.pm
@@ -14,6 +14,7 @@ use File::Temp qw/ :POSIX /;
use version;
use Class::Load ':all';
+
sub dzil_root { Dist::Zilla::Util->_global_config_root }
sub dzil_config { file(shift->dzil_root,'config.ini') }
@@ -37,8 +38,32 @@ sub setup {
$self->set_dzil_config($config);
}
+=func get_local_version
+
+Returns a version object for the specified package.
+
+ my $version = App::DuckPAN::Perl::get_local_version('Moose');
+
+Returns C<undef> if the version was not defined or not installed.
+
+See L<< C<version.pm>'s documentation|version >> for more on version objects.
+
+=cut
+
sub get_local_version {
- # TODO
+ my ($module) = @_;
+ require Module::Data;
+ my $v;
+ {
+ local $@;
+ eval {
+ $v = Module::Data->new( $module )->version;
+ 1
+ } or return;
+ };
+ return if not defined $v;
+ return version->parse($v) if not ref $v;
+ return $v;
}
sub cpanminus_install_error {
@@ -61,14 +86,14 @@ sub duckpan_install {
for (@modules) {
my $module = $packages->package($_);
if ($module) {
- # TODO
- # my $localver = get_local_version($_);
- # if ($localver && version->parse($localver) == version->parse($module->version)) {
- # print "You already have latest version of ".$_." with ".$localver."\n";
- # } else {
+ local $@;
+ my $localver = get_local_version($_);
+ if ($localver && $localver == version->parse($module->version)) {
+ print "You already have latest version of ".$_." with ".$localver."\n";
+ } else {
my $latest = $self->app->duckpan.'authors/id/'.$module->distribution->pathname;
push @to_install, $latest unless grep { $_ eq $latest } @to_install;
- # }
+ }
} else {
print "[ERROR] Can't find package ".$_." on ".$self->app->duckpan."\n";
$error = 1;
Please sign in to comment.
Something went wrong with that request. Please try again.