From 791d7981cff0cd3a85fdd504f410a7c9833272dc Mon Sep 17 00:00:00 2001 From: Zoffix Znet Date: Sat, 4 Jun 2016 15:16:43 -0400 Subject: More stuff --- lib/IRC/Client/Grammar/Actions.pm6 | 33 +++++++++++++++++---------------- lib/IRC/Client/Message.pm6 | 14 +++++++------- lib/IRC/Client/Message/Numeric.pm6 | 2 ++ 3 files changed, 26 insertions(+), 23 deletions(-) (limited to 'lib/IRC/Client') diff --git a/lib/IRC/Client/Grammar/Actions.pm6 b/lib/IRC/Client/Grammar/Actions.pm6 index 3e190cd..54943bd 100644 --- a/lib/IRC/Client/Grammar/Actions.pm6 +++ b/lib/IRC/Client/Grammar/Actions.pm6 @@ -5,23 +5,23 @@ use IRC::Client::Message::Numeric; has $.irc; has $.server; -method TOP ($/) { $/.make: ($».made, $) } - -method left-overs ($/) { - $/.made: $/.defined ?? !$/ !! ''; +method TOP ($/) { + $/.make: ( + $».made, + ~( $ // '' ), + ); } -method message ($/) { +method message ($match) { my %args; - my $pref = $/; + my $pref = $match; for qw/nick user host/ { $pref{$_}.defined or next; %args{$_} = ~$pref{$_}; } %args = ~$pref if $pref.defined; - my $p = $; - + my $p = $match; loop { if ( $p.defined ) { %args.append: ~$p; @@ -30,26 +30,27 @@ method message ($/) { %args.append: ~$p; last; } + last unless $p.defined; $p = $p; } my %msg-args = irc => $!irc, - nick => %args, - username => %args, - host => %args, - usermask => "%args!%args@%args", + nick => %args//'', + username => %args//'', + host => %args//'', server => $!server; + . = . ~ '!' ~ . ~ '@' ~ . given %msg-args; my $msg; - given ~$ { - when /^ ([0..9]**3) $/ { + given ~$match { + when /^ $=(<[0..9]>**3) $/ { $msg = IRC::Client::Message::Numeric.new: - :command( $ ), + :command( ~$ ), :args( %args ), |%msg-args; } } - $/.make: $msg; + $match.make: $msg; } diff --git a/lib/IRC/Client/Message.pm6 b/lib/IRC/Client/Message.pm6 index 6670baa..69e7c82 100644 --- a/lib/IRC/Client/Message.pm6 +++ b/lib/IRC/Client/Message.pm6 @@ -1,9 +1,9 @@ unit role IRC::Client::Message; -has $.irc; -has $.nick; -has $.username; -has $.host; -has $.usermask; -has $.server; -has $.command; +has $.irc is required; +has Str:D $.nick is required; +has Str:D $.username is required; +has Str:D $.host is required; +has Str:D $.usermask is required; +has Str:D $.command is required; +has Str:D $.server is required; diff --git a/lib/IRC/Client/Message/Numeric.pm6 b/lib/IRC/Client/Message/Numeric.pm6 index c57c3c2..38e9a26 100644 --- a/lib/IRC/Client/Message/Numeric.pm6 +++ b/lib/IRC/Client/Message/Numeric.pm6 @@ -2,3 +2,5 @@ use IRC::Client::Message; unit role IRC::Client::Message::Numeric does IRC::Client::Message; has @.args; + +method Str { "$.command @.args[]" } -- cgit v1.1