#!/usr/bin/perl
# turn on perl's safety features
use strict;
use warnings;
# work out the name of the module we're looking for
my $module_name = $ARGV[0]
or die "Must specify module name on command line";
# create a new browser
use WWW::Mechanize;
my $browser = WWW::Mechanize->new();
# tell it to get the main page
$browser->get("http://search.cpan.org/");
# okay, fill in the box with the name of the
# module we want to look up
$browser->form_number(1);
$browser->field("query", $module_name);
$browser->click();
# click on the link that matches the module name
$browser->follow_link( text_regex => $module_name );
my $url = $browser->uri;
# launch a browser...
system('galeon', $url);
exit(0);
####
C:\cygwin64\home\Fred\pages2\hunt>perl cpan4.pl WWW::Mechanize
module name is WWW::Mechanize
url is http://search.cpan.org/search?query=WWW%3A%3AMechanize&mode=all
C:\cygwin64\home\Fred\pages2\hunt>type cpan4.pl
#! /usr/bin/perl
use warnings;
use strict;
use 5.010;
# work out the name of the module we're looking for
my $module_name = $ARGV[0]
or die "Must specify module name on command line";
say "module name is $module_name";
# create a new browser
use WWW::Mechanize;
my $browser = WWW::Mechanize->new();
# tell it to get the main page
$browser->get("http://search.cpan.org/");
# okay, fill in the box with the name of the
# module we want to look up
$browser->form_number(1);
$browser->field( "query", $module_name );
$browser->click();
my $url = $browser->uri;
say "url is $url";
# launch a browser...
system( 'C:\Program Files (x86)\Google\Chrome\Application\chrome.exe', $url );
exit(0);
####
C:\cygwin64\home\Fred\pages2\hunt>perl cpan1.pl WWW::Mechanize
WWW::Mechanize passed as text_regex is not a regex at cpan1.pl line 24.
url is http://st.pimg.net/tucs/style.css?3
C:\cygwin64\home\Fred\pages2\hunt>perl cpan1.pl WWW::Mechan
WWW::Mechan passed as text_regex is not a regex at cpan1.pl line 24.
url is http://st.pimg.net/tucs/style.css?3
C:\cygwin64\home\Fred\pages2\hunt>perl cpan1.pl 'WWW::Mechanize'
'WWW::Mechanize' passed as text_regex is not a regex at cpan1.pl line 24.
url is http://st.pimg.net/tucs/style.css?3
C:\cygwin64\home\Fred\pages2\hunt>perl cpan1.pl "WWW::Mechanize"
WWW::Mechanize passed as text_regex is not a regex at cpan1.pl line 24.
url is http://st.pimg.net/tucs/style.css?3
C:\cygwin64\home\Fred\pages2\hunt>
####
#! /usr/bin/perl
use warnings;
use strict;
use 5.010;
# work out the name of the module we're looking for
my $module_name = $ARGV[0]
or die "Must specify module name on command line";
# create a new browser
use WWW::Mechanize;
my $browser = WWW::Mechanize->new();
# tell it to get the main page
$browser->get("http://search.cpan.org/");
# okay, fill in the box with the name of the
# module we want to look up
$browser->form_number(1);
$browser->field( "query", $module_name );
$browser->click();
# click on the link that matches the module name
$browser->follow_link( text_regex => $module_name );
my $url = $browser->uri;
say "url is $url";
# launch a browser...
system( 'C:\Program Files (x86)\Google\Chrome\Application\chrome.exe', $url );
exit(0);