Parse::IRC

A parser for the IRC protocol
Download

Parse::IRC Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Perl Artistic License
  • Price:
  • FREE
  • Publisher Name:
  • Chris Williams
  • Publisher web site:
  • http://search.cpan.org/~bingos/

Parse::IRC Tags


Parse::IRC Description

A parser for the IRC protocol Parse::IRC is a Perl module that provides a convenient way of parsing lines of text conforming to the IRC protocol ( see RFC1459 or RFC2812 ).SYNOPSISGeneral usage: use strict; use Parse::IRC; # Functional interface my $hashref = parse_irc( $irc_string ); # OO interface my $irc_parser = Parse::IRC->new(); my $hashref = $irc_parser->parse( $irc_string );Using Parse::IRC in a simple IRC bot: # A simple IRC bot using Parse::IRC use strict; use IO::Socket; use Parse::IRC; my $parser = Parse::IRC->new( public => 1 ); my %dispatch = ( 'ping' => \&irc_ping, '001' => \&irc_001, 'public' => \&irc_public ); # The server to connect to and our details. my $server = "irc.perl.moo"; my $nick = "parseirc$$"; my $login = "simple_bot"; # The channel which the bot will join. my $channel = "#IRC.pm"; # Connect to the IRC server. my $sock = new IO::Socket::INET(PeerAddr => $server, PeerPort => 6667, Proto => 'tcp') or die "Can't connect\n"; # Log on to the server. print $sock "NICK $nick\r\n"; print $sock "USER $login 8 * :Perl IRC Hacks Robot\r\n"; # Keep reading lines from the server. while (my $input = ) { $input =~ s/\r\n//g; my $hashref = $parser->parse( $input ); SWITCH: { my $type = lc $hashref->{command}; my @args; push @args, $hashref->{prefix} if $hashref->{prefix}; push @args, @{ $hashref->{params} }; if ( defined $dispatch{$type} ) { $dispatch{$type}->(@args); last SWITCH; } print STDOUT join( ' ', "irc_$type:", @args ), "\n"; } } sub irc_ping { my $server = shift; print $sock "PONG :$server\r\n"; return 1; } sub irc_001 { print STDOUT "Connected to $_\n"; print $sock "JOIN $channel\r\n"; return 1; } sub irc_public { my ($who,$where,$what) = @_; print "$who -> $where -> $what\n"; return 1; } Requirements: · Perl


Parse::IRC Related Software