line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Gherkin::TokenScanner; |
2
|
|
|
|
|
|
|
$Gherkin::TokenScanner::VERSION = '27.0.0'; |
3
|
2
|
|
|
2
|
|
283804
|
use strict; |
|
2
|
|
|
|
|
15
|
|
|
2
|
|
|
|
|
66
|
|
4
|
2
|
|
|
2
|
|
10
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
73
|
|
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
537
|
use Class::XSAccessor accessors => [qw/fh line_number/]; |
|
2
|
|
|
|
|
2733
|
|
|
2
|
|
|
|
|
29
|
|
7
|
|
|
|
|
|
|
|
8
|
2
|
|
|
2
|
|
544
|
use Carp qw/croak/; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
110
|
|
9
|
2
|
|
|
2
|
|
12
|
use Encode; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
196
|
|
10
|
|
|
|
|
|
|
|
11
|
2
|
|
|
2
|
|
860
|
use Gherkin::Line; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
65
|
|
12
|
2
|
|
|
2
|
|
852
|
use Gherkin::Token; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
744
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub new { |
15
|
5
|
|
|
5
|
1
|
7857
|
my ( $class, $path_or_str ) = @_; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
# Perl convention is that a string reference is the string itself, but that |
18
|
|
|
|
|
|
|
# a straight string is a path |
19
|
5
|
|
|
|
|
9
|
my $fh; |
20
|
5
|
100
|
|
|
|
22
|
if ( ref $path_or_str eq 'SCALAR' ) { |
21
|
3
|
|
|
|
|
5
|
my $bytes = Encode::encode('UTF-8', ${ $path_or_str }); |
|
3
|
|
|
|
|
19
|
|
22
|
2
|
|
|
2
|
|
17
|
open $fh, '<:encoding(UTF-8)', \$bytes; |
|
2
|
|
|
2
|
|
5
|
|
|
2
|
|
|
|
|
14
|
|
|
2
|
|
|
|
|
1700
|
|
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
10
|
|
|
3
|
|
|
|
|
591
|
|
23
|
|
|
|
|
|
|
} else { |
24
|
2
|
50
|
|
|
|
88
|
open( $fh, '<', $path_or_str ) |
25
|
|
|
|
|
|
|
|| croak "Can't open [$path_or_str] for reading"; |
26
|
2
|
|
|
|
|
16
|
$fh->binmode(':utf8'); |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
5
|
|
|
|
|
2112
|
return bless { fh => $fh, line_number => 0 }, $class; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub next_line { |
33
|
42
|
|
|
42
|
0
|
62
|
my $self = shift; |
34
|
|
|
|
|
|
|
|
35
|
42
|
50
|
|
|
|
105
|
return (undef, $self->line_number) if not defined $self->fh; |
36
|
|
|
|
|
|
|
|
37
|
42
|
|
|
|
|
1006
|
my $line = $self->fh->getline; |
38
|
42
|
|
|
|
|
1195
|
$self->line_number( $self->line_number + 1 ); |
39
|
|
|
|
|
|
|
|
40
|
42
|
100
|
|
|
|
98
|
if (not defined $line) { |
41
|
4
|
|
|
|
|
26
|
$self->fh->close; |
42
|
4
|
|
|
|
|
83
|
$self->fh( undef ); |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
42
|
|
|
|
|
116
|
return ($line, $self->line_number); |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub read { |
49
|
42
|
|
|
42
|
1
|
93
|
my $self = shift; |
50
|
42
|
|
|
|
|
73
|
my ($line, $line_number) = $self->next_line; |
51
|
|
|
|
|
|
|
|
52
|
42
|
|
|
|
|
97
|
my $location = { line => $line_number }; |
53
|
42
|
|
|
|
|
65
|
my $line_token = undef; |
54
|
42
|
100
|
|
|
|
92
|
if (defined $line) { |
55
|
38
|
|
|
|
|
85
|
$line =~ s/\r$//; # \n as well as \r\n are considered lines separators |
56
|
38
|
|
|
|
|
155
|
$line_token = |
57
|
|
|
|
|
|
|
Gherkin::Line->new( |
58
|
|
|
|
|
|
|
{ line_text => $line, line_number => $line_number } |
59
|
|
|
|
|
|
|
); |
60
|
|
|
|
|
|
|
} |
61
|
42
|
|
|
|
|
255
|
return Gherkin::Token->new(line => $line_token, location => $location); |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
1; |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
__END__ |