line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Gherkin::TokenScanner; |
2
|
|
|
|
|
|
|
$Gherkin::TokenScanner::VERSION = '25.0.1'; |
3
|
2
|
|
|
2
|
|
264257
|
use strict; |
|
2
|
|
|
|
|
9
|
|
|
2
|
|
|
|
|
63
|
|
4
|
2
|
|
|
2
|
|
10
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
61
|
|
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
446
|
use Class::XSAccessor accessors => [qw/fh line_number/]; |
|
2
|
|
|
|
|
2382
|
|
|
2
|
|
|
|
|
14
|
|
7
|
|
|
|
|
|
|
|
8
|
2
|
|
|
2
|
|
560
|
use Carp qw/croak/; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
88
|
|
9
|
2
|
|
|
2
|
|
13
|
use Encode; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
196
|
|
10
|
|
|
|
|
|
|
|
11
|
2
|
|
|
2
|
|
833
|
use Gherkin::Line; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
65
|
|
12
|
2
|
|
|
2
|
|
787
|
use Gherkin::Token; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
682
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub new { |
15
|
5
|
|
|
5
|
1
|
7235
|
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
|
|
|
|
|
11
|
my $fh; |
20
|
5
|
100
|
|
|
|
18
|
if ( ref $path_or_str eq 'SCALAR' ) { |
21
|
3
|
|
|
|
|
8
|
my $bytes = Encode::encode('UTF-8', ${ $path_or_str }); |
|
3
|
|
|
|
|
15
|
|
22
|
2
|
|
|
2
|
|
16
|
open $fh, '<:encoding(UTF-8)', \$bytes; |
|
2
|
|
|
2
|
|
3
|
|
|
2
|
|
|
|
|
14
|
|
|
2
|
|
|
|
|
1590
|
|
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
602
|
|
23
|
|
|
|
|
|
|
} else { |
24
|
2
|
50
|
|
|
|
87
|
open( $fh, '<', $path_or_str ) |
25
|
|
|
|
|
|
|
|| croak "Can't open [$path_or_str] for reading"; |
26
|
2
|
|
|
|
|
13
|
$fh->binmode(':utf8'); |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
5
|
|
|
|
|
1897
|
return bless { fh => $fh, line_number => 0 }, $class; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub next_line { |
33
|
42
|
|
|
42
|
0
|
58
|
my $self = shift; |
34
|
|
|
|
|
|
|
|
35
|
42
|
50
|
|
|
|
105
|
return (undef, $self->line_number) if not defined $self->fh; |
36
|
|
|
|
|
|
|
|
37
|
42
|
|
|
|
|
1005
|
my $line = $self->fh->getline; |
38
|
42
|
|
|
|
|
1222
|
$self->line_number( $self->line_number + 1 ); |
39
|
|
|
|
|
|
|
|
40
|
42
|
100
|
|
|
|
89
|
if (not defined $line) { |
41
|
4
|
|
|
|
|
27
|
$self->fh->close; |
42
|
4
|
|
|
|
|
78
|
$self->fh( undef ); |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
42
|
|
|
|
|
127
|
return ($line, $self->line_number); |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub read { |
49
|
42
|
|
|
42
|
1
|
95
|
my $self = shift; |
50
|
42
|
|
|
|
|
87
|
my ($line, $line_number) = $self->next_line; |
51
|
|
|
|
|
|
|
|
52
|
42
|
|
|
|
|
112
|
my $location = { line => $line_number }; |
53
|
42
|
|
|
|
|
64
|
my $line_token = undef; |
54
|
42
|
100
|
|
|
|
84
|
if (defined $line) { |
55
|
38
|
|
|
|
|
103
|
$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
|
|
|
|
|
256
|
return Gherkin::Token->new(line => $line_token, location => $location); |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
1; |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
__END__ |