WWW:CPAN is insteresting.. the deps are daunting.. well.. it just seems like a *lot* just to get a freaking version number from cpan..

Ok.. here's some scripting I have for myself.. Consists of 3 parts, one that checks version installed, one that checks version on cpan, and one that compares versions and optionally ass or/or installs new versions..

CAVEAT, these work and are cute.. and they are hacks.

pmver

#!/usr/bin/perl use strict; use base 'LEOCHARRE::CLI'; my $o = gopts('r'); scalar @ARGV or die('missing modules args'); my $manymods = scalar @ARGV > 1 ? 1 : 0; map { do_one($_) } @ARGV; sub usage { return qq{ $0 - what version of a perl module is installed DESCRIPTION If the moduoe version cannot be determined it returns 0, if the module is not present, returns undef. OPTION FLAGS -r round off things like 2.15, 0.345, and v5.4.4 to 2, 0, and 5 -d debug h- help USAGE EXAMPLES $0 CPAN $0 Cwd SEE ALSO LEOCHARRE::Dev }; } sub do_one { my $modname = shift; debug("modname $modname"); my $ver; no strict 'refs'; if ( eval "require $modname" ){ debug($modname); #require $modname; $ver = ${"$modname\:\:VERSION"}; defined $ver or debug("$modname is installed but can't set versi +on via module."); } #`perl -M$mod -e "print \$$mod::VERSION" else { debug("$modname not installed on this system."); $ver = ''; } if ($o->{r} and $ver){ $ver=~s/^v//; $ver=~s/\..+$//; } defined $ver or $ver =0; if ( $manymods ){ print "$modname $ver\n"; } else { print $ver } }

pmvercpan

#!/usr/bin/perl use strict; use base 'LEOCHARRE::CLI'; use WWW::CPAN; use Smart::Comments '###'; my $o = gopts('V'); @ARGV or die('missing arg'); my $cpan = WWW::CPAN->new; my @v = map { get_cpan_version($_) } @ARGV; print join("\n",@v); sub usage { return qq{$0 - get module versions from cpan OPTION FLAGS -V verbose, print meta info to stdout SEE ALSO LEOCHARRE::Dev }; } sub get_cpan_version { my $dist = shift; $dist or die('missing arg'); my $distname = _arg2distname($dist) or die; my $meta = $cpan->fetch_distmeta({ dist => $distname}) or print STDERR "cant fetch dist meta for $distname\n" and return ''; if( $o->{V} ){ ### $meta } my $version = $meta->{version} or print STDERR "cant get version number for $distname\n" and return ''; return $version; } sub _arg2distname { my $arg = shift; my $namechars = qr/[a-zA-Z0-9]/; my $distchars = qr/[a-zA-Z0-9\:\-\.]/; $arg=~/^$distchars+$/ or die("argument $arg doesn't look like a dis +tro name"); $arg=~s/\:\:/\-/g; return $arg; }

pmverstatus

#!/usr/bin/perl use strict; use base 'LEOCHARRE::CLI'; use vars qw(@MODULES); my $o = gopts('m:uaV'); @MODULES = @ARGV; (push @MODULES, $o->{m}) if $o->{m}; if ($o->{a}){ print join( "\n", @INC); } if ($o->{a}){ for my $inc (@INC){ print STDERR "looking in $inc ..\n"; my @got = find_modules_in($inc) or print STDERR "none found.\n"; printf STDERR "found %s modules.\n", scalar @got; push @MODULES, @got; } } scalar @MODULES or die("no modules arg"); printf STDERR "Testing for %s module total.. \n", scalar @MODULES; sub find_modules_in { my $dir = shift; my @modnames; for my $path ( split( /\n/, `find '$dir' -type f -name "*.pm"`) ){ $path=~s/^$dir\/+//; $path=~s/\//\:\:/g; $path=~s/\.pm$//; push @modnames, $path; } return @modnames; } for my $modname ( @MODULES ){ my($vold, $vnew); unless( ($vold, $vnew) = is_update_available($modname) ){ print STDERR "$modname, no update found.\n" if DEBUG; print STDERR "." if $o->{V}; next; } print STDERR "$modname $vold, update $vnew found.\n"; $o->{u} or next; unless( $o->{f} ){ # no force? yn("Would you like to update?") or next; } system('cpan', $modname) ==0 or warn("could not update $modname") and next; } sub is_update_available { my $modname = shift; my $v_installed = `pmver $modname 2>/dev/null`; $v_installed=~s/^\s+|\s+$//g; unless( defined $v_installed ){ print STDERR "$modname installed, missing version\n"; return; } my $v_cpan = `pmvercpan $modname 2>/dev/null`; $v_cpan=~s/^\s+|\s+$//g; unless( defined $v_cpan ){ print STDERR "$modname on cpan, missing version\n"; return; } if ( $v_installed < $v_cpan ){ return ($v_installed, $v_cpan); } return; } sub usage { return qq{ $0 - check status of perl modules installed against versions on cpan OPTION FLAGS -a all modules -u auto update modules -V verbose ARGUMENTS -m module name to check -b base dir to check modules from SEE ALSO LEOCHARRE::Dev USAGE $0 -ua }; }

Tested these out adn it's very cute. It's running through every one of my installed modules and propmting me to update if it finds a newer ver on cpan. :-)


In reply to Re: Grabbing info from cpan by leocharre
in thread Grabbing info from cpan by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.