line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Text::MatchedPosition; |
2
|
3
|
|
|
3
|
|
109760
|
use strict; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
165
|
|
3
|
3
|
|
|
3
|
|
17
|
use warnings; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
90
|
|
4
|
3
|
|
|
3
|
|
2655
|
use utf8; |
|
3
|
|
|
|
|
21
|
|
|
3
|
|
|
|
|
26
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub new { |
9
|
7
|
|
|
7
|
1
|
1419
|
my ($class, $text, $regex) = @_; |
10
|
|
|
|
|
|
|
|
11
|
7
|
|
|
|
|
11
|
my $args = +{}; |
12
|
|
|
|
|
|
|
|
13
|
7
|
100
|
|
|
|
33
|
$args->{text} = (ref $text eq 'SCALAR') ? $$text : $text; |
14
|
|
|
|
|
|
|
|
15
|
7
|
100
|
|
|
|
17
|
if (ref $regex ne 'Regexp') { |
16
|
1
|
|
|
|
|
12
|
require Carp; |
17
|
1
|
|
|
|
|
202
|
Carp::croak("The 2nd arg requires 'Regexp': $regex"); |
18
|
|
|
|
|
|
|
} |
19
|
6
|
|
|
|
|
8
|
$args->{regex} = $regex; |
20
|
|
|
|
|
|
|
|
21
|
6
|
|
|
|
|
15
|
bless $args, $class; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
11
|
|
|
11
|
1
|
38
|
sub text { $_[0]->{text} } |
25
|
|
|
|
|
|
|
|
26
|
11
|
|
|
11
|
1
|
54
|
sub regex { $_[0]->{regex} } |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub line { |
29
|
6
|
|
|
6
|
1
|
470
|
my $self = shift; |
30
|
|
|
|
|
|
|
|
31
|
6
|
50
|
|
|
|
25
|
$self->_position unless $self->{position}; |
32
|
|
|
|
|
|
|
|
33
|
6
|
|
|
|
|
6
|
return ${$self->{position}}[0]; |
|
6
|
|
|
|
|
27
|
|
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub offset { |
37
|
6
|
|
|
6
|
1
|
8
|
my $self = shift; |
38
|
|
|
|
|
|
|
|
39
|
6
|
50
|
|
|
|
17
|
$self->_position unless $self->{position}; |
40
|
|
|
|
|
|
|
|
41
|
6
|
|
|
|
|
6
|
return ${$self->{position}}[1]; |
|
6
|
|
|
|
|
31
|
|
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub _position { |
45
|
6
|
|
|
6
|
|
5
|
my $self = shift; |
46
|
|
|
|
|
|
|
|
47
|
6
|
100
|
|
|
|
11
|
unless ($self->text =~ $self->regex) { |
48
|
1
|
|
|
|
|
3
|
$self->{position} = [undef, undef]; |
49
|
1
|
|
|
|
|
2
|
return; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
5
|
|
|
|
|
14
|
my $match = (split $self->regex, $self->text)[0]; |
53
|
5
|
|
|
|
|
12
|
$match =~ s/\x0D\x0A/\n/g; |
54
|
5
|
|
|
|
|
8
|
$match =~ tr/\r/\n/; |
55
|
|
|
|
|
|
|
|
56
|
5
|
|
|
|
|
17
|
my $line_count = ($match =~ s/\n/\n/g); |
57
|
5
|
|
|
|
|
8
|
$line_count++; |
58
|
|
|
|
|
|
|
|
59
|
5
|
|
100
|
|
|
24
|
my $offset = length( (split /\n/, $match, -1)[-1] || '' ) + 1; |
60
|
|
|
|
|
|
|
|
61
|
5
|
|
|
|
|
16
|
$self->{position} = [$line_count, $offset]; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
1; |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
__END__ |