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   156896 use v5.12;
  3         21  
4 3     3   1206 use Moo;
  3         25734  
  3         22  
5              
6             our $VERSION = '0.03';
7              
8 3     3   3667 use Carp qw(confess);
  3         7  
  3         160  
9 3     3   1479 use Text::TokenStream::Types qw(Identifier Position);
  3         13  
  3         39  
10 3     3   1841 use Types::Standard qw(Bool HashRef Str);
  3         17  
  3         20  
11              
12 3     3   4535 use namespace::clean;
  3         37036  
  3         22  
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 256 sub text_for_matching { shift->text }
21              
22             sub matches {
23 15     15 1 339 my ($self, $target) = @_;
24 15 100       43 return $self->text_for_matching eq $target if Str->check($target);
25 3         54 return !!grep $target->($_), $self;
26             }
27              
28             sub repr {
29 3     3 1 45 my ($self, $indent) = @_;
30              
31 3   100     47 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__