line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Gherkin::TokenScanner; |
2
|
|
|
|
|
|
|
$Gherkin::TokenScanner::VERSION = '25.0.2'; |
3
|
2
|
|
|
2
|
|
260055
|
use strict; |
|
2
|
|
|
|
|
11
|
|
|
2
|
|
|
|
|
62
|
|
4
|
2
|
|
|
2
|
|
10
|
use warnings; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
63
|
|
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
454
|
use Class::XSAccessor accessors => [qw/fh line_number/]; |
|
2
|
|
|
|
|
2259
|
|
|
2
|
|
|
|
|
12
|
|
7
|
|
|
|
|
|
|
|
8
|
2
|
|
|
2
|
|
510
|
use Carp qw/croak/; |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
88
|
|
9
|
2
|
|
|
2
|
|
12
|
use Encode; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
180
|
|
10
|
|
|
|
|
|
|
|
11
|
2
|
|
|
2
|
|
826
|
use Gherkin::Line; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
64
|
|
12
|
2
|
|
|
2
|
|
785
|
use Gherkin::Token; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
660
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub new { |
15
|
5
|
|
|
5
|
1
|
7173
|
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
|
|
|
|
21
|
if ( ref $path_or_str eq 'SCALAR' ) { |
21
|
3
|
|
|
|
|
8
|
my $bytes = Encode::encode('UTF-8', ${ $path_or_str }); |
|
3
|
|
|
|
|
15
|
|
22
|
2
|
|
|
2
|
|
14
|
open $fh, '<:encoding(UTF-8)', \$bytes; |
|
2
|
|
|
2
|
|
4
|
|
|
2
|
|
|
|
|
15
|
|
|
2
|
|
|
|
|
1565
|
|
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
11
|
|
|
3
|
|
|
|
|
564
|
|
23
|
|
|
|
|
|
|
} else { |
24
|
2
|
50
|
|
|
|
83
|
open( $fh, '<', $path_or_str ) |
25
|
|
|
|
|
|
|
|| croak "Can't open [$path_or_str] for reading"; |
26
|
2
|
|
|
|
|
14
|
$fh->binmode(':utf8'); |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
5
|
|
|
|
|
1871
|
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
|
|
|
|
111
|
return (undef, $self->line_number) if not defined $self->fh; |
36
|
|
|
|
|
|
|
|
37
|
42
|
|
|
|
|
1001
|
my $line = $self->fh->getline; |
38
|
42
|
|
|
|
|
1257
|
$self->line_number( $self->line_number + 1 ); |
39
|
|
|
|
|
|
|
|
40
|
42
|
100
|
|
|
|
100
|
if (not defined $line) { |
41
|
4
|
|
|
|
|
31
|
$self->fh->close; |
42
|
4
|
|
|
|
|
86
|
$self->fh( undef ); |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
42
|
|
|
|
|
127
|
return ($line, $self->line_number); |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub read { |
49
|
42
|
|
|
42
|
1
|
96
|
my $self = shift; |
50
|
42
|
|
|
|
|
83
|
my ($line, $line_number) = $self->next_line; |
51
|
|
|
|
|
|
|
|
52
|
42
|
|
|
|
|
111
|
my $location = { line => $line_number }; |
53
|
42
|
|
|
|
|
66
|
my $line_token = undef; |
54
|
42
|
100
|
|
|
|
86
|
if (defined $line) { |
55
|
38
|
|
|
|
|
87
|
$line =~ s/\r$//; # \n as well as \r\n are considered lines separators |
56
|
38
|
|
|
|
|
154
|
$line_token = |
57
|
|
|
|
|
|
|
Gherkin::Line->new( |
58
|
|
|
|
|
|
|
{ line_text => $line, line_number => $line_number } |
59
|
|
|
|
|
|
|
); |
60
|
|
|
|
|
|
|
} |
61
|
42
|
|
|
|
|
246
|
return Gherkin::Token->new(line => $line_token, location => $location); |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
1; |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
__END__ |