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