#!/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 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 happen with thos e it is now not so Tiny anymore, it even has support for stuff on platforms 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 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 and subsequent discussions 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('text')->first; print "Reviewer: $reviewer\n"; my $reviewdate = $review->find('p.review_attribution')->map('text')->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('text')->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')->first; print "Comment: $comment\n\n"; } }