Changeset 851a0e0 for perl


Ignore:
Timestamp:
Apr 3, 2011, 3:06:01 PM (13 years ago)
Author:
Nelson Elhage <nelhage@mit.edu>
Branches:
master, release-1.10, release-1.8, release-1.9
Children:
249bbbe
Parents:
4787581
git-author:
Nelson Elhage <nelhage@mit.edu> (02/26/11 20:06:50)
git-committer:
Nelson Elhage <nelhage@mit.edu> (04/03/11 15:06:01)
Message:
IRC: Remove circular references between ::Connection and its Client.
Location:
perl/modules/IRC/lib/BarnOwl/Module
Files:
2 edited

Legend:

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

    r8ba9313 r851a0e0  
    389389        timeout   => sub {0}
    390390       });
     391    $ircnets{$alias} = $conn;
    391392    return;
    392393}
     
    395396    my $cmd = shift;
    396397    my $conn = shift;
    397     if ($conn->conn->is_connected) {
     398    if ($conn->conn->{socket}) {
    398399        $conn->conn->disconnect("Goodbye!");
    399400    } elsif ($reconnect{$conn->alias}) {
  • perl/modules/IRC/lib/BarnOwl/Module/IRC/Connection.pm

    r4787581 r851a0e0  
    3535    my $nick = $args->{nick};
    3636    my $conn = AnyEvent::IRC::Client->new();
    37     if(delete $args->{SSL}) {
    38         $conn->enable_ssl;
    39     }
    40     $conn->connect($host, $port, $args);
    4137    my $self = bless({}, $class);
    4238    $self->conn($conn);
     
    4844    $self->whois_tmp("");
    4945
     46    if(delete $args->{SSL}) {
     47        $conn->enable_ssl;
     48    }
     49    $conn->connect($host, $port, $args);
     50    $conn->{heap}{parent} = $self;
     51    weaken($conn->{heap}{parent});
     52
     53    sub on {
     54        my $meth = "on_" . shift;
     55        return sub {
     56            my $conn = shift;
     57            return unless $conn->{heap}{parent};
     58            $conn->{heap}{parent}->$meth(@_);
     59        }
     60    }
     61
    5062    # $self->conn->add_default_handler(sub { shift; $self->on_event(@_) });
    51     $self->conn->reg_cb(registered => sub { shift; $self->connected("Connected to $alias as $nick") },
    52                         connfail   => sub { shift; BarnOwl::error("Connection to $host failed!") },
    53                         disconnect => sub { shift; $self->on_disconnect(@_) },
    54                         publicmsg  => sub { shift; $self->on_msg(@_) },
    55                         privatemsg => sub { shift; $self->on_msg(@_) });
     63    $self->conn->reg_cb(registered => on("connected"),
     64                        connfail   => sub { BarnOwl::error("Connection to $host failed!") },
     65                        disconnect => on("disconnect"),
     66                        publicmsg  => on("msg"),
     67                        privatemsg => on("msg"));
    5668    for my $m (qw(welcome yourhost created
    5769                  luserclient luserop luserchannels luserme
    5870                  error)) {
    59         $self->conn->reg_cb("irc_$m" => sub { shift;  $self->on_admin_msg(@_) });
    60     }
    61     $self->conn->reg_cb(irc_375       => sub { shift; $self->on_motdstart(@_) },
    62                         irc_372       => sub { shift; $self->on_motd(@_) },
    63                         irc_376       => sub { shift; $self->on_endofmotd(@_) },
    64                         irc_join      => sub { shift; $self->on_join(@_) },
    65                         irc_part      => sub { shift; $self->on_part(@_) },
    66                         irc_quit      => sub { shift; $self->on_quit(@_) },
    67                         irc_433       => sub { shift; $self->on_nickinuse(@_) },
    68                         channel_topic => sub { shift; $self->on_topic(@_) },
    69                         irc_333       => sub { shift; $self->on_topicinfo(@_) },
    70                         irc_353       => sub { shift; $self->on_namreply(@_) },
    71                         irc_366       => sub { shift; $self->on_endofnames(@_) },
    72                         irc_311       => sub { shift; $self->on_whois(@_) },
    73                         irc_312       => sub { shift; $self->on_whois(@_) },
    74                         irc_319       => sub { shift; $self->on_whois(@_) },
    75                         irc_320       => sub { shift; $self->on_whois(@_) },
    76                         irc_318       => sub { shift; $self->on_endofwhois(@_) },
    77                         irc_mode      => sub { shift; $self->on_mode(@_) },
    78                         irc_401       => sub { shift; $self->on_nosuch(@_) },
    79                         irc_402       => sub { shift; $self->on_nosuch(@_) },
    80                         irc_403       => sub { shift; $self->on_nosuch(@_) },
    81                         nick_change  => sub { shift; $self->on_nick(@_); },
     71        $self->conn->reg_cb("irc_$m" => on("admin_msg"));
     72    }
     73    $self->conn->reg_cb(irc_375       => on("motdstart"),
     74                        irc_372       => on("motd"),
     75                        irc_376       => on("endofmotd"),
     76                        irc_join      => on("join"),
     77                        irc_part      => on("part"),
     78                        irc_quit      => on("quit"),
     79                        irc_433       => on("nickinuse"),
     80                        channel_topic => on("topic"),
     81                        irc_333       => on("topicinfo"),
     82                        irc_353       => on("namreply"),
     83                        irc_366       => on("endofnames"),
     84                        irc_311       => on("whois"),
     85                        irc_312       => on("whois"),
     86                        irc_319       => on("whois"),
     87                        irc_320       => on("whois"),
     88                        irc_318       => on("endofwhois"),
     89                        irc_mode      => on("mode"),
     90                        irc_401       => on("nosuch"),
     91                        irc_402       => on("nosuch"),
     92                        irc_403       => on("nosuch"),
     93                        nick_change   => on("nick"),
    8294                        'irc_*' => sub { BarnOwl::debug("IRC: " . $_[1]->{command}) });
    8395
     
    203215sub disconnect {
    204216    my $self = shift;
    205     delete $BarnOwl::Module::IRC::ircnets{$self->alias};
    206217    for my $k (keys %BarnOwl::Module::IRC::channels) {
    207218        my @conns = grep {$_ ne $self} @{$BarnOwl::Module::IRC::channels{$k}};
     
    344355    my $self = shift;
    345356    my $interval = shift || 5;
    346     delete $BarnOwl::Module::IRC::ircnets{$self->alias};
    347357    $BarnOwl::Module::IRC::reconnect{$self->alias} = $self;
    348358    my $weak = $self;
     
    370380}
    371381
     382sub on_connect {
     383    my $self = shift;
     384    $self->connected("Connected to $self->alias as $self->nick")
     385}
     386
    372387sub connected {
    373388    my $self = shift;
     
    375390    BarnOwl::admin_message("IRC", $msg);
    376391    $self->cancel_reconnect;
    377     $BarnOwl::Module::IRC::ircnets{$self->alias} = $self;
    378392    if ($self->autoconnect_channels) {
    379393        for my $c (@{$self->autoconnect_channels}) {
Note: See TracChangeset for help on using the changeset viewer.