1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
|
# You may distribute under the terms of the GNU General Public License
#
# (C) Paul Evans, 2008-2010 -- leonerd@leonerd.org.uk
package Circle::CommandInvocation;
use strict;
use warnings;
our $VERSION = '0.173320';
use Scalar::Util qw( weaken );
sub new
{
my $class = shift;
my ( $text, $connection, $invocant ) = @_;
$text =~ s/^\s+//;
# Weaken the connection to ensure that this object doesn't hold on to the
# connection longer than required
my $self = bless [ $text, $connection, $invocant ], $class;
weaken( $self->[1] );
return $self;
}
sub nest
{
my $self = shift;
my ( $text ) = @_;
return (ref $self)->new( $text, $self->connection, $self->invocant );
}
sub connection
{
my $self = shift;
return $self->[1];
}
sub invocant
{
my $self = shift;
return $self->[2];
}
sub peek_token
{
my $self = shift;
if( $self->[0] =~ m/^"/ ) {
$self->[0] =~ m/^"(.*)"/ and return $1;
}
else {
$self->[0] =~ m/^(\S+)/ and return $1;
}
return undef;
}
sub pull_token
{
my $self = shift;
if( $self->[0] =~ m/^"/ ) {
$self->[0] =~ s/^"(.*)"\s*// and return $1;
}
else {
$self->[0] =~ s/^(\S+)\s*// and return $1;
}
return undef;
}
sub peek_remaining
{
my $self = shift;
return $self->[0];
}
# delegate these to invocant
foreach my $method (qw(
respond
respondwarn
responderr
respond_table
)) {
no strict 'refs';
*$method = sub { shift->invocant->$method( @_ ) };
}
0x55AA;
|