File Coverage

blib/lib/Text/TokenStream/Token.pm
Criterion Covered Total %
statement 23 23 100.0
branch 2 2 100.0
condition 2 2 100.0
subroutine 9 9 100.0
pod 3 3 100.0
total 39 39 100.0


line stmt bran cond sub pod time code
1             package Text::TokenStream::Token;
2              
3 3     3   152192 use v5.12;
  3         23  
4 3     3   1185 use Moo;
  3         24253  
  3         20  
5              
6             our $VERSION = '0.04';
7              
8 3     3   3548 use Carp qw(confess);
  3         6  
  3         144  
9 3     3   1454 use Text::TokenStream::Types qw(Identifier Position);
  3         11  
  3         37  
10 3     3   1939 use Types::Standard qw(Bool HashRef Str);
  3         15  
  3         21  
11              
12 3     3   4429 use namespace::clean;
  3         34777  
  3         21  
13              
14             has type => (is => 'ro', isa => Identifier, required => 1);
15             has text => (is => 'ro', isa => Str, required => 1);
16             has captures => (is => 'ro', isa => HashRef[Str], default => sub { +{} });
17             has cuddled => (is => 'ro', isa => Bool, default => 0);
18             has position => (is => 'ro', isa => Position, required => 1);
19              
20 13     13 1 260 sub text_for_matching { shift->text }
21              
22             sub matches {
23 15     15 1 335 my ($self, $target) = @_;
24 15 100       45 return $self->text_for_matching eq $target if Str->check($target);
25 3         50 return !!grep $target->($_), $self;
26             }
27              
28             sub repr {
29 3     3 1 46 my ($self, $indent) = @_;
30              
31 3   100     56 return sprintf '%sToken type=%s position=%d cuddled=%d text=[%s]',
32             $indent // '', $self->type, $self->position, $self->cuddled, $self->text;
33             }
34              
35             1;
36             __END__