Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

cpanr - view cpan ratings from the command line

by marto (Archbishop)
on Oct 05, 2016 at 10:41 UTC ( #1173331=CUFP: print w/replies, xml ) Need Help??

A while ago I threw together a short proof of concept script to display reviews from cpanratings on the command line, based upon Re^8: Switch and some subsequent discussions.

Install WWW::Mechanize & Mojo::DOM, save the code below and run it as follows:

$ cpanr Path::Tiny Reviews for Path::Tiny Reviewer: Michiel Beijen Review date: 2014-12-17 @ 03:13:06 Module version: 0.061 Rating: 5/5 Comment: I really, REALLY like this module. It makes managing files so + much easi er. Just opening them, reading them into a scalar or array, printing t +hem out. O f course it STARTED out as a true ::Tiny module but as seems to happen + with thos e it is now not so Tiny anymore, it even has support for stuff on plat +forms as A IX and such. I wrote a platform for managing Video on Demand files and + had to lo ad and process a whole lot of XML metadata files, images, and videos. +I used thi s module extensively to crawl directories, read files and so on. It ha +s helped m e a lot writing code faster while also making my code much easier to r +ead and ma intain. Thanks a LOT for this module! Reviewer: Keedi Kim Review date: 2013-11-21 @ 18:34:22 Module version: 0.044 Rating: 5/5 Comment: Awesome module. I can't believe this is tiny module. It has a +lmost ever ything related in file and directory. It doesn't have another dependen +cy except core modules just as you expected. And documentation is very detailed +and has ma ny examples. There is no reason not to use this module at all.

cpanr

#!/usr/bin/perl use strict; use warnings; use Mojo::DOM; use WWW::Mechanize; =head1 NAME cpanr - View cpan ratings from the command line. =head1 SYNOPSIS This script displays content from cpan ratings L<http://cpanratings.pe +rl.org> on the command line. Simply call it with the module name: $ cpanr Path::Tiny Reviewer: Michiel Beijen Review date: 2014-12-17 @ 03:13:06 Module version: 0.061 Rating: 5/5 Comment: I really, REALLY like this module. It makes managing files +so much easi er. Just opening them, reading them into a scalar or array, printing + them out. O f course it STARTED out as a true ::Tiny module but as seems to happ +en with thos e it is now not so Tiny anymore, it even has support for stuff on pl +atforms as A IX and such. I wrote a platform for managing Video on Demand files a +nd had to lo ad and process a whole lot of XML metadata files, images, and videos +. I used thi s module extensively to crawl directories, read files and so on. It +has helped m e a lot writing code faster while also making my code much easier to + read and ma intain. Thanks a LOT for this module! .... This short script was written in a few minutes based upon L<http://perlmonks.org/index.pl?node_id=1169281> and subsequent discus +sions just for fun. =cut my ($module) = @ARGV; unless ($module){ print "Usage: $0 Module::Name\n"; }else{ my $ratingsURL = 'http://cpanratings.perl.org/dist/'; print "Reviews for $module\n\n"; $module =~ s/::/-/g; $ratingsURL .= $module; my $mech = WWW::Mechanize->new(); $mech->get($ratingsURL); my $dom = Mojo::DOM->new($mech->content()); unless ( $dom->find('.review')->each ){ print "Can't find any reviews for $module\n"; } for my $review ($dom->find('.review')->each){ my $reviewer = $review->find('p.review_attribution a')->map('t +ext')->first; print "Reviewer: $reviewer\n"; my $reviewdate = $review->find('p.review_attribution')->map('t +ext')->first; $reviewdate =~ s/- //; $reviewdate =~ s/T/ @ /; $reviewdate =~ s/\( \)//g; $reviewdate =~ s/\R//g; $reviewdate =~ s/\(\)//g; print "Review date: $reviewdate\n"; my $moduleversion = $review->find('h3.review_header')->map('te +xt')->first; $moduleversion =~ s/(\)|\()//g; $moduleversion =~ s/\R//g; print "Module version: $moduleversion\n"; my $stars = $review->find('img')->map(attr => 'alt')->first; print 'Rating: ' . length( $stars ) . "/5\n"; my $comment = $review->find('.review_text')->map('text')->firs +t; print "Comment: $comment\n\n"; } }

Update 24/03/2017: updated to copy with changes in the HTML. More permanent solution in due course.

Update: 03/07/2017: Now available on github, I plan on creating a better solution in due course.

Replies are listed 'Best First'.
Re: cpanr - view cpan ratings from the command line ( ojo::g )
by beech (Parson) on Oct 05, 2016 at 23:45 UTC

      Fantastic feedback, thanks. I was unaware of ojo. I'll definitely look at using this going forward.

        You probably realized already but itís to facilitate one-liners. And it actually led me to find what I believe to be a bug in the text handing of Mojo. In my view, all_text and text should find the alt info in images. In this case it would have shown the star ratings which would have been a nice DWIW. :P

        perl -Mojo -E 'say $_->all_text, $/ for g("http://cpanratings.perl.org +/dist/" . +shift=~s/::/-/r)->dom->find(".review")->each' CGI perl -Mojo -E 'say $_->all_text, $/ for g("http://cpanratings.perl.org +/dist/" . +shift=~s/::/-/r)->dom->find(".review")->each' Mojolicious
Re: cpanr - view cpan ratings from the command line
by Anonymous Monk on Oct 05, 2016 at 12:16 UTC
    Now all we need is someone to make CPAN Ratings not suck worth reading.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: CUFP [id://1173331]
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (9)
As of 2019-10-14 17:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?