package IRC::Parser;
use strict;
use warnings;
# ok, the idea here..
# plugin always takes precedence, this way any protocol fixes for any ircd..
# can be easily added, defined..
# IRC does not need parsed twice, I really could give a fuck if someone thinks they
# NEED TO in some special case.. so if they define a plugin, handle the line there!! simple enough..
# and I can't see any need in defining a protocol fix twice, so I'm not iterating through a list of them
# not that it'd be anymore difficult, just it'd be pointless to do so.
sub spawn {
my $class = shift;
bless {
origin => undef,
command => undef,
target => undef,
args => undef,
text => undef,
raw => undef
}, $class;
}
# ?origin? - command - ?target? - ?arguments? - ?text?
sub break {
my $self = shift;
(local $_ = ($self->{raw} = shift || $_)) =~ s/[\r\n]$//g;
if(@{ $self }{qw(origin command target args text)} = $_ =~ /^
(?:\x3a(\S+)\x20+)?
(\d{3}|[A-Za-z]+)
(?:
\x20+
((?!\x3a)\S+)
\x20*
(
(?:\x20*(?!\x3a)\S+)*
)
)?
\x20*
\x3a?
(.*)
$/x) { # gotta love that gibberish, IRC is a ludicrous protocol
my @broken = ($1, ($self->{command} = uc($2)), $3, $4, $5);
wantarray() ? @broken : \@broken;
} else { warn "Failed to parse ($_); string does not conform to IRC protocol."; }
}
1;
__END__