Adam

 view release on metacpan or  search on metacpan

lib/Adam.pm  view on Meta::CPAN

    );
}

sub privmsg {
    my $self = shift;
    POE::Kernel->post( $self->irc_session_id => privmsg => @_ );
}


sub START {
    my ( $self, $heap ) = @_[ OBJECT, HEAP ];
    $poe_kernel->post( $self->irc_session_id => register => 'all' );
    $poe_kernel->post( $self->irc_session_id => connect  => {} );
    $self->info( 'connecting to ' . $self->get_server . ':' . $self->get_port );
    return;
}

sub load_plugin {
    my ( $self, $name, $plugin ) = @_;
    $self->plugin_manager->load( $name => $plugin, bot => $self );
}


event irc_plugin_add => sub {
    my ( $self, $desc, $plugin ) = @_[ OBJECT, ARG0, ARG1 ];
    $self->info("loaded plugin: $desc");
    if ( $desc eq 'PlugMan' ) {
        $self->debug("loading other plugins");
        for my $name ( sort $self->plugin_names ) {
            $self->debug("loading $name");
            $plugin = $self->get_plugin($name);
            $self->load_plugin( $name => $plugin );
        }
    }
};

event irc_connected => sub {
    my ( $self, $sender ) = @_[ OBJECT, SENDER ];
    $self->info( "connected to " . $self->get_server . ':' . $self->get_port );
    return;
};

# We registered for all events, this will produce some debug info.
sub DEFAULT {
    my ( $self, $event, $args ) = @_[ OBJECT, ARG0 .. $#_ ];
    my @output = ("$event: ");

    foreach my $arg (@$args) {
        if ( ref($arg) eq ' ARRAY ' ) {
            push( @output, "[" . join( " ,", @$arg ) . "]" );
        }
        else {
            push( @output, "'$arg' " );
        }
    }
    $self->debug( join ' ', @output );
    return 0;
}

sub run {
    $_[0]->new_with_options unless blessed $_[0];
    POE::Kernel->run;
}


has _loop => (
    is        => 'rw',
    traits    => ['NoGetopt'],
    predicate => 'has_loop',
);

sub async {
    my $self = shift;
    require IO::Async::Loop::POE;
    $self = $self->new_with_options unless blessed $self;
    my $loop = IO::Async::Loop::POE->new();
    $self->_loop($loop);
    $loop->run;
}


sub stop {
    my $self = shift;
    if ($self->has_loop) {
        $self->_loop->stop;
    } else {
        POE::Kernel->stop;
    }
}


1;

__END__

=pod

=encoding UTF-8

=head1 NAME

Adam - The patriarch of IRC Bots

=head1 VERSION

version 1.003

=head1 SYNOPSIS

See the Synopsis in L<Moses>. Adam is not meant to be used directly.

=head1 DESCRIPTION

The Adam class implements an IRC bot based on L<POE::Component::IRC::State>,
L<Moose>, and L<MooseX::POE>. It supports two event loop modes: the default
L<POE> loop via C<run()>, and an L<IO::Async> mode via C<async()> that allows
integration with other L<IO::Async>-based components through
L<IO::Async::Loop::POE>.

Adam is not meant to be used directly — see L<Moses> for the declarative
sugar layer.

=head2 logger

Logger object that implements the L<Adam::Logger::API> role. Defaults to
L<Adam::Logger::Default>.

=head2 nickname

The IRC nickname for the bot. Defaults to the package name. Required.

=head2 server

The IRC server to connect to. Defaults to C<irc.perl.org>. Required.



( run in 1.737 second using v1.01-cache-2.11-cpan-39bf76dae61 )