Gherkin/TokenFormatterBuilder.pm untested

filter: Statementstmt 0.0% 0 / 27 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 8 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 10 Podpod 0.0% 0 / 7 totaltotal 0.0% 0 / 58 CC 3 SCAR 15.0
CC
3
Cov
0%
format_token
12.0
reset
2.0
formatted_tokens
2.0
CRAP 4.5
1 package Gherkin::TokenFormatterBuilder;
2 $Gherkin::TokenFormatterBuilder::VERSION = '42.0.1';
3 use strict;
4 use warnings;
5 use base 'Gherkin::AstBuilder';
6  
7 sub reset {
8 my $self = shift;
9 $self->SUPER::reset();
10 $self->{'formatted_tokens'} = [];
11 }
12  
13 sub formatted_tokens { return $_[0]->{'formatted_tokens'} }
14  
15 sub build {
16 my ( $self, $token ) = @_;
17 push( @{ $self->formatted_tokens }, $self->format_token($token) );
18 }
19  
20 sub start_rule { }
21 sub end_rule { }
22  
23 sub get_result {
24 my $self = shift;
25 return $self->formatted_tokens;
26 }
27  
28 my $c = 0;
29  
30 sub format_token {
31 my ( $self, $token ) = @_;
32 return "EOF" if $token->is_eof;
33 my $v = sprintf(
34 "(%s:%s)%s:%s/%s/%s",
35 $token->location->{'line'},
36 $token->location->{'column'},
37 $token->matched_type || '',
38 ( $token->matched_keyword ?
39 sprintf('(%s)%s',$token->matched_keyword_type || '',$token->matched_keyword || '') : ''),
40 $token->matched_text || '',
41 join( ',',
42 map { $_->{'column'} . ':' . $_->{'text'} }
43 @{ $token->matched_items } )
44 );
45 utf8::encode($v);
46 return $v;
47 }
48  
49 1;