http://www.perlmonks.org?node_id=1173331

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.