POE::Component::IRC

POE::Component::IRC is a fully event-driven IRC client module.
Download

POE::Component::IRC Ranking & Summary

Advertisement

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

POE::Component::IRC Tags


POE::Component::IRC Description

POE::Component::IRC is a fully event-driven IRC client module. POE::Component::IRC is a fully event-driven IRC client module.SYNOPSIS # A simple Rot13 'encryption' bot use strict; use warnings; use POE qw(Component::IRC); my $nickname = 'Flibble' . $$; my $ircname = 'Flibble the Sailor Bot'; my $ircserver = 'irc.blahblahblah.irc'; my $port = 6667; my @channels = ( '#Blah', '#Foo', '#Bar' ); # We create a new PoCo-IRC object and component. my $irc = POE::Component::IRC->spawn( nick => $nickname, server => $ircserver, port => $port, ircname => $ircname, ) or die "Oh noooo! $!"; POE::Session->create( package_states => , ], heap => { irc => $irc }, ); $poe_kernel->run(); exit 0; sub _start { my ($kernel,$heap) = @_; # We get the session ID of the component from the object # and register and connect to the specified server. my $irc_session = $heap->{irc}->session_id(); $kernel->post( $irc_session => register => 'all' ); $kernel->post( $irc_session => connect => { } ); undef; } sub irc_001 { my ($kernel,$sender) = @_; # Get the component's object at any time by accessing the heap of # the SENDER my $poco_object = $sender->get_heap(); print "Connected to ", $poco_object->server_name(), "n"; # In any irc_* events SENDER will be the PoCo-IRC session $kernel->post( $sender => join => $_ ) for @channels; undef; } sub irc_public { my ($kernel,$sender,$who,$where,$what) = @_; my $nick = ( split /!/, $who ); my $channel = $where->; if ( my ($rot13) = $what =~ /^rot13 (.+)/ ) { $rot13 =~ tr; $kernel->post( $sender => privmsg => $channel => "$nick: $rot13" ); } undef; } # We registered for all events, this will produce some debug info. sub _default { my ($event, $args) = @_; my @output = ( "$event: " ); foreach my $arg ( @$args ) { if ( ref($arg) eq 'ARRAY' ) { push( @output, "" ); } else { push ( @output, "'$arg'" ); } } print STDOUT join ' ', @output, "n"; return 0; }POE::Component::IRC is a POE component (who'd have guessed?) which acts as an easily controllable IRC client for your other POE components and sessions. You create an IRC component and tell it what events your session cares about and where to connect to, and it sends back interesting IRC events when they happen. You make the client do things by sending it events. That's all there is to it. Cool, no?The POE::Component::IRC distribution has a docs/ folder with a collection of salient documentation including the pertinent RFCs.POE::Component::IRC consists of a POE::Session that manages the IRC connection and dispatches 'irc_' prefixed events to interested sessions and an object that can be used to access additional information using methods.Sessions register their interest in receiving 'irc_' events by sending 'register' to the component. One would usually do this in your _start handler. Your session will continue to receive events until you 'unregister'. The component will continue to stay around until you tell it not to with 'shutdown'.The SYNOPSIS demonstrates a fairly basic bot.Requirements:· Perl Requirements: · Perl


POE::Component::IRC Related Software