From 175d70e3703caa05bcde9d1dc50e3ebe842fbedb Mon Sep 17 00:00:00 2001 From: Zoffix Znet Date: Wed, 25 Nov 2015 15:47:36 -0500 Subject: Make stubbing work --- lib/IRC/Client.pm6 | 28 +++++++++++++++++----------- lib/IRC/Client/Plugin/HNY.pm6 | 6 ++++-- 2 files changed, 21 insertions(+), 13 deletions(-) (limited to 'lib') diff --git a/lib/IRC/Client.pm6 b/lib/IRC/Client.pm6 index d4a00ca..ae8f245 100644 --- a/lib/IRC/Client.pm6 +++ b/lib/IRC/Client.pm6 @@ -1,16 +1,16 @@ use v6; -class IRC::Client::Plugin { ... } +role IRC::Client::Plugin { ... } class IRC::Client:ver<1.001001> { - - has Str $.host = 'localhost'; - has Int $.port where 0 <= $_ <= 65535 = 6667; - has Str $.nick where 1 <= .chars <= 9 = 'Perl6IRC'; - has Str $.username = 'Perl6IRC'; - has Str $.userhost = 'localhost'; - has Str $.userreal = 'Perl6 IRC Client'; - has Str @.channels = ['#perl6bot']; - has IO::Socket::Async $.sock; - has IRC::Client::Plugin @.plugins = []; + has Bool $.debug = False; + has Str $.host = 'localhost'; + has Int $.port where 0 <= $_ <= 65535 = 6667; + has Str $.nick where 1 <= .chars <= 9 = 'Perl6IRC'; + has Str $.username = 'Perl6IRC'; + has Str $.userhost = 'localhost'; + has Str $.userreal = 'Perl6 IRC Client'; + has Str @.channels = ['#perl6bot']; + has @.plugins = []; + has IO::Socket::Async $.sock; method run { await IO::Socket::Async.connect( $!host, $!port ).then({ @@ -36,7 +36,13 @@ class IRC::Client:ver<1.001001> { method ssay (Str:D $msg) { $!sock.print("$msg\n"); + self; + } + method privmsg (Str $who, Str $what) { + my $msg = ":$!nick!$!username\@$!userhost PRIVMSG $who :$what\n"; + $!debug and say ".privmsg({$msg.subst("\n", "␤", :g)})"; + self.ssay: $msg; self; } } diff --git a/lib/IRC/Client/Plugin/HNY.pm6 b/lib/IRC/Client/Plugin/HNY.pm6 index 7f52302..f9f7cbe 100644 --- a/lib/IRC/Client/Plugin/HNY.pm6 +++ b/lib/IRC/Client/Plugin/HNY.pm6 @@ -2,7 +2,9 @@ use v6; use IRC::Client; use IRC::Client::Plugin; unit class IRC::Client::Plugin::HNY:ver<1.001001> does IRC::Client::Plugin; -multi method interval ( ) { 2 } +multi method interval ( ) { 6 } multi method interval (IRC::Client $irc) { - $irc.ssay("5 seconds passed. Time is now " ~ now); + $irc.privmsg( + $irc.channels[0], "5 seconds passed. Time is now " ~ now + ); } -- cgit v1.1