Ignore:
Timestamp:
Jan 16, 2008, 10:03:00 PM (14 years ago)
Author:
Nelson Elhage <nelhage@mit.edu>
Branches:
master, barnowl_perlaim, debian, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
Children:
eebef19
Parents:
f2d72128
Message:
Rewrite ::Connection to not subclass Net::IRC::Connection to avoid
stupid namespace conflicts
File:
1 edited

Legend:

Unmodified
Added
Removed
  • perl/modules/IRC/lib/BarnOwl/Module/IRC/Connection.pm

    reab7a4c rba2ca66  
    1010=head1 DESCRIPTION
    1111
    12 This module is a Net::IRC::Connection subclass for BarnOwl's IRC
     12This module is a wrapper around Net::IRC::Connection for BarnOwl's IRC
    1313support
    1414
    1515=cut
    1616
    17 use base qw(Net::IRC::Connection Class::Accessor Exporter);
    18 __PACKAGE__->mk_accessors(qw(alias channels owl_connected owl_motd));
     17use Net::IRC::Connection;
     18
     19use base qw(Class::Accessor Exporter);
     20__PACKAGE__->mk_accessors(qw(conn alias channels connected motd));
    1921our @EXPORT_OK = qw(&is_private);
    2022
    2123use BarnOwl;
     24
     25BEGIN {
     26    no strict 'refs';
     27    my @delegate = qw(nick server);
     28    for my $meth (@delegate) {
     29        *{"BarnOwl::Module::IRC::Connection::$meth"} = sub {
     30            shift->conn->$meth(@_);
     31        }
     32    }
     33};
    2234
    2335sub new {
     
    2638    my $alias = shift;
    2739    my %args = (@_);
    28     my $self = $class->SUPER::new($irc, %args);
     40    my $conn = Net::IRC::Connection->new($irc, %args);
     41    my $self = bless({}, $class);
     42    $self->conn($conn);
    2943    $self->alias($alias);
    3044    $self->channels([]);
    31     $self->owl_motd("");
    32     $self->owl_connected(0);
    33     bless($self, $class);
    34 
    35     $self->add_default_handler(sub { goto &on_event; });
    36     $self->add_handler(['msg', 'notice', 'public', 'caction'],
    37             sub { goto &on_msg });
    38     $self->add_handler(['welcome', 'yourhost', 'created',
     45    $self->motd("");
     46    $self->connected(0);
     47
     48    $self->conn->add_default_handler(sub { shift; $self->on_event(@_) });
     49    $self->conn->add_handler(['msg', 'notice', 'public', 'caction'],
     50            sub { shift; $self->on_msg(@_) });
     51    $self->conn->add_handler(['welcome', 'yourhost', 'created',
    3952            'luserclient', 'luserop', 'luserchannels', 'luserme'],
    40             sub { goto &on_admin_msg });
    41     $self->add_handler(['myinfo', 'map', 'n_local', 'n_global',
     53            sub { shift; $self->on_admin_msg(@_) });
     54    $self->conn->add_handler(['myinfo', 'map', 'n_local', 'n_global',
    4255            'luserconns'],
    4356            sub { });
    44     $self->add_handler(motdstart => sub { goto &on_motdstart });
    45     $self->add_handler(motd      => sub { goto &on_motd });
    46     $self->add_handler(endofmotd => sub { goto &on_endofmotd });
    47     $self->add_handler(join      => sub { goto &on_join });
    48     $self->add_handler(part      => sub { goto &on_part });
    49     $self->add_handler(disconnect => sub { goto &on_disconnect });
    50     $self->add_handler(nicknameinuse => sub { goto &on_nickinuse });
    51     $self->add_handler(cping     => sub { goto &on_ping });
     57    $self->conn->add_handler(motdstart => sub { shift; $self->on_motdstart(@_) });
     58    $self->conn->add_handler(motd      => sub { shift; $self->on_motd(@_) });
     59    $self->conn->add_handler(endofmotd => sub { shift; $self->on_endofmotd(@_) });
     60    $self->conn->add_handler(join      => sub { shift; $self->on_join(@_) });
     61    $self->conn->add_handler(part      => sub { shift; $self->on_part(@_) });
     62    $self->conn->add_handler(disconnect => sub { shift; $self->on_disconnect(@_) });
     63    $self->conn->add_handler(nicknameinuse => sub { shift; $self->on_nickinuse(@_) });
     64    $self->conn->add_handler(cping     => sub { shift; $self->on_ping(@_) });
    5265
    5366    return $self;
     
    97110sub on_ping {
    98111    my ($self, $evt) = @_;
    99     $self->ctcp_reply($evt->nick, join (' ', ($evt->args)));
     112    $self->conn->ctcp_reply($evt->nick, join (' ', ($evt->args)));
    100113}
    101114
     
    110123sub on_motdstart {
    111124    my ($self, $evt) = @_;
    112     $self->owl_motd(join "\n", cdr $evt->args);
     125    $self->motd(join "\n", cdr $evt->args);
    113126}
    114127
    115128sub on_motd {
    116129    my ($self, $evt) = @_;
    117     $self->owl_motd(join "\n", $self->owl_motd, cdr $evt->args);
     130    $self->motd(join "\n", $self->motd, cdr $evt->args);
    118131}
    119132
    120133sub on_endofmotd {
    121134    my ($self, $evt) = @_;
    122     $self->owl_motd(join "\n", $self->owl_motd, cdr $evt->args);
    123     if(!$self->owl_connected) {
     135    $self->motd(join "\n", $self->motd, cdr $evt->args);
     136    if(!$self->connected) {
    124137        BarnOwl::admin_message("IRC", "Connected to " .
    125138                               $self->server . " (" . $self->alias . ")");
    126         $self->owl_connected(1);
     139        $self->connected(1);
    127140       
    128141    }
    129142    BarnOwl::admin_message("IRC",
    130143            BarnOwl::Style::boldify('MOTD for ' . $self->alias) . "\n"
    131             . strip_irc_formatting($self->owl_motd));
     144            . strip_irc_formatting($self->motd));
    132145}
    133146
     
    163176                           "[" . $self->alias . "] " .
    164177                           [$evt->args]->[1] . ": Nick already in use");
    165     unless($self->owl_connected) {
    166         $self->disconnect;
     178    unless($self->connected) {
     179        $self->conn->disconnect;
    167180    }
    168181}
Note: See TracChangeset for help on using the changeset viewer.