Net-Async-IRC
view release on metacpan or search on metacpan
lib/Net/Async/IRC.pm view on Meta::CPAN
print "$hints->{prefix_name} says: $hints->{text}\n";
},
);
$loop->add( $irc );
await $irc->login(
nick => "MyName",
host => "irc.example.org",
);
await $irc->do_PRIVMSG( target => "YourName", text => "Hello world!" );
$loop->run;
=head1 DESCRIPTION
This object class implements an asynchronous IRC client, for use in programs
based on L<IO::Async>.
Most of the actual IRC message handling behaviour is implemented by the parent
class L<Net::Async::IRC::Protocol>.
Most of the behaviour related to being an IRC client is implemented by the
parent class L<Protocol::IRC::Client>.
The following documentation may make mention of these above two parent
classes; the reader should make reference to them when required.
=cut
sub new
{
my $class = shift;
my %args = @_;
my $on_closed = delete $args{on_closed};
return $class->SUPER::new(
%args,
on_closed => sub {
my $self = shift;
if( $self->{on_login_f} ) {
$_->fail( "Closed" ) for @{ $self->{on_login_f} };
undef $self->{on_login_f};
}
$on_closed->( $self ) if $on_closed;
},
);
}
sub _init
{
my $self = shift;
$self->SUPER::_init( @_ );
$self->{user} = $ENV{LOGNAME} ||
( HAVE_MSWIN32 ? Win32::LoginName() : getpwuid($>) );
our $VERSION;
$self->{realname} = "Net::Async::IRC client $VERSION";
}
=head1 PARAMETERS
The following named parameters may be passed to C<new> or C<configure>:
=over 8
=item nick => STRING
=item user => STRING
=item realname => STRING
Connection details. See also C<connect>, C<login>.
If C<user> is not supplied, it will default to either C<$ENV{LOGNAME}> or the
current user's name as supplied by C<getpwuid()> or C<Win32::LoginName()>.
If unconnected, changing these properties will set the default values to use
when logging in.
If logged in, changing the C<nick> property is equivalent to calling
C<change_nick>. Changing the other properties will not take effect until the
next login.
=item use_caps => ARRAY of STRING
Attempts to negotiate IRC v3.1 CAP at connect time. The array gives the names
of capabilities which will be requested, if the server supports them.
If the C<sasl> capability is requested and supported by the server, the
C<login> method will use that.
=back
=cut
sub configure
{
my $self = shift;
my %args = @_;
for (qw( user realname use_caps )) {
$self->{$_} = delete $args{$_} if exists $args{$_};
}
if( exists $args{nick} ) {
$self->_set_nick( delete $args{nick} );
}
$self->SUPER::configure( %args );
}
=head1 METHODS
The following methods documented in an C<await> expression return L<Future>
instances.
=cut
=head2 connect
$irc = await $irc->connect( %args );
Connects to the IRC server. This method does not perform the complete IRC
login sequence; for that see instead the C<login> method. The returned
L<Future> will yield the C<$irc> instance itself, to make chaining easier.
=over 8
=item host => STRING
Hostname of the IRC server.
=item service => STRING or NUMBER
Optional. Port number or service name of the IRC server. Defaults to 6667.
( run in 2.131 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )