Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Map IRC message to GET request

by puudeli (Pilgrim)
on Mar 30, 2009 at 11:48 UTC ( [id://754119]=CUFP: print w/replies, xml ) Need Help??

A friend of mine asked me to do a simple script that would consume IRC's (RFC 1459) pseudo BNF and map it directly to a GET request that is sent to an application server. This is what I came up within few hours.

It was a real pleasure since I haven't done a lot of www programming with Perl. I am open to all suggestions how this kind of stuff is usually done and all pointers to previous art are appreciated.

#! /usr/bin/perl use strict; use warnings; use HTTP::Lite; use English qw( -no_match_vars ); { usage() if @ARGV != 2; # Note, if you want to define the port the <domain:port> # has to contain trailing slash, eg. # http://foo.bar.com:80/ # http://foo.bar.com:80/my/remote/app my $url = shift; my $bnf = shift; my @items = split(/\s+/, $bnf); my @bnf = (); # Leave the possible 15th parameter untouched. for(my $i = 0; $i < 16; $i++ ) { push @bnf, shift @items; } # The last param may contain whitespaces etc. push @bnf, join(' ', @items); my $ret = http_get_request_from_bnf($url, @bnf); die "Server failed to serve our request '$url' : $ret" if $ret !~ /2\d{1,2}/; print "$ret\n"; } sub http_get_request_from_bnf { my $url = shift; my @bnf_items = @_; my $i = 1; my $prefix = shift @bnf_items; my $command = shift @bnf_items; my $http = new HTTP::Lite; $http->add_req_header('Prefix', $prefix); $http->add_req_header('Command', $command); foreach my $item ( @bnf_items ) { $http->add_req_header("Param$i", $item); $i++; } #use Data::Dumper; #print Dumper($http); my $request = $http->request($url) or die "Unable to create GET request : $OS_ERROR\n"; return $request; } sub usage { print<<EOL; usage: $PROGRAM_NAME <url> <Pseudo BNF command> URL must contain trailing slash and the port number can be included, e +g. http://foo.bar.com:80/ http://www.baz.com:80/my/remote/app EOL exit 1; }
--
seek $her, $from, $everywhere if exists $true{love};

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2024-04-25 07:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found