This module implements asynchronous file fetcher for Irssi.
Irssi provides a set of nice io and timer handlers, but using them may be painful sometimes. This code provides a working downloader solution.
Save it in your ~/.irssi/scripts directory as downloader.pl for instance. Make sure module is loaded before any script that may use it.
~/.irssi/scripts
downloader.pl
This script will load downloader module automatically, if it has been named downloader.pl.
use strict; use warnings; use Irssi; use IO::File; use URI::Escape; Irssi::command( '/script load downloader.pl' ); sub got_body { my ( $window, $easy, $result ) = @_; if ( $result ) { warn "Could not download $easy->{uri}: $result\n"; return; } my @found; while ( $easy->{body} =~ s#<h2\s+class=sr><a\s+href="(.*?)"> <b>(.*?)</b></a></h2>##x ) { my $uri = $1; $_ = $2; s/&#(\d+);/chr $1/eg; chomp; push @found, $_; } @found = "no results" unless @found; my $msg = "CPAN search %9$easy->{args}%n: " . (join "%9;%n ", @found); if ( $window ) { $window->print( $msg ); } else { Irssi::print( $msg ); } } sub cpan_search { my ( $args, $server, $window ) = @_; my $query = uri_escape( $args ); my $uri = "http://search.cpan.org/search?query=${query}&mode=all"; my $easy = Irssi::downloader(); $easy->{args} = $args; $easy->get( $uri, sub { got_body( $window, @_ ) } ); } Irssi::command_bind( 'cpan', \&cpan_search );
To install Net::Curl, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Net::Curl
CPAN shell
perl -MCPAN -e shell install Net::Curl
For more information on module installation, please visit the detailed CPAN module installation guide.