GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages


Manual Reference Pages  -  PARSE::IRC (3)

.ds Aq ’

NAME

Parse::IRC - A parser for the IRC protocol.

CONTENTS

VERSION

version 1.20

SYNOPSIS

General 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 "Cant 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 = <$sock>) {
    $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 $_[0]\n";
    print $sock "JOIN $channel\r\n";
    return 1;
  }

  sub irc_public {
    my ($who,$where,$what) = @_;
    print "$who -> $where -> $what\n";
    return 1;
  }



DESCRIPTION

Parse::IRC provides a convenient way of parsing lines of text conforming to the IRC protocol ( see RFC1459 or RFC2812 ).

FUNCTION INTERFACE

Using the module automagically imports ’parse_irc’ into your namespace.
parse_irc Takes a string of IRC protcol text. Returns a hashref on success or undef on failure. See below for the format of the hashref returned.

OBJECT INTERFACE

    CONSTRUCTOR

new Creates a new Parse::IRC object. One may specify debug => 1 to enable warnings about non-IRC protcol lines. Specify public => 1 to enable the automatic conversion of privmsgs targeted at channels to public instead of privmsg. Specify ctcp => 1 to enable automatic conversion of privmsgs and notices with CTCP/DCC type encoding to ctcp, ctcpreply and dcc_request.

    METHODS

parse Takes a string of IRC protcol text. Returns a hashref on success or undef on failure. The hashref contains the following fields:



  prefix
  command
  params ( this is an arrayref )
  raw_line



For example, if the filter receives the following line, the following hashref is produced:



  LINE: :moo.server.net 001 lamebot :Welcome to the IRC network lamebot

  HASHREF: {
             prefix   => :moo.server.net,
             command  => 001,
             params   => [ lamebot, Welcome to the IRC network lamebot ],
             raw_line => :moo.server.net 001 lamebot :Welcome to the IRC network lamebot,
           }



KUDOS

Based on code originally developed by Jonathan Steinert and Dennis Taylor

SEE ALSO

POE::Filter::IRCD

<http://www.faqs.org/rfcs/rfc1459.html>

<http://www.faqs.org/rfcs/rfc2812.html>

AUTHOR

Chris Williams <chris@bingosnet.co.uk>

COPYRIGHT AND LICENSE

This software is copyright (c) 2012 by Chris Williams, Jonathan Steinert and Dennis Taylor.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.

Search for    or go to Top of page |  Section 3 |  Main Index


perl v5.20.3 PARSE::IRC (3) 2012-10-20

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with manServer 1.07.