| Bot-Net documentation | Contained in the Bot-Net distribution. |
Bot::Net::Util - miscellaneous utility functions
my @args = Bot::Net::Util->parse_bot_command($message);
Provides utility functions for use elsewhere.
Returns an array of words found in the given message. This tries to sensibly break up a command. The string will be split on whitespace or grouped by quotes.
Quoted strings may contain quotes by containing a double-quote to escape it. For example,
tell 'bob''s friend' """Hello World"""
would become:
('tell', "bob's friend", '"Hello World"')
Andrew Sterling Hanenkamp <hanenkamp@cpan.org>
Copyright 2007 Boomer Consulting, Inc. All Rights Reserved.
This program is free software and may be modified and distributed under the same terms as Perl itself.
| Bot-Net documentation | Contained in the Bot-Net distribution. |
use strict; use warnings; package Bot::Net::Util; use Bot::Net; use Carp; use Regexp::Common qw/ delimited /;
sub parse_bot_command { my $class = shift; local $_ = shift; unless (defined $_) { carp "No string given to parse. Returning an empty list."; return; } my @args = m/ ( $RE{delimited}{-delim=>'"'}{-esc=>'"'} | $RE{delimited}{-delim=>"'"}{-esc=>"'"} | \S+ ) /gx; # Strip the quotes and unescape the "" and '' escapes map { /^"/ && /"$/ && s/^"// && s/"$// && s/""/"/g; /^'/ && /'$/ && s/^'// && s/'$// && s/''/'/g; } @args; return @args; }
1;