| 1 | package ExtUtils::ParseXS::CountLines; | ||||||||||
| 2 | |||||||||||
| 3 | # Private helper module. It is used to tie a file handle, and | ||||||||||
| 4 | # whenever lines are written to it, lines which match the | ||||||||||
| 5 | # | ||||||||||
| 6 | # ExtUtils::ParseXS::CountLines->end_marker() | ||||||||||
| 7 | # | ||||||||||
| 8 | # token are replaced with: | ||||||||||
| 9 | # | ||||||||||
| 10 | # #line NNN file.c | ||||||||||
| 11 | # | ||||||||||
| 12 | # where NNN is the count of lines written so far. | ||||||||||
| 13 | |||||||||||
| 14 | 28 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 15 | 28 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 16 | |||||||||||
| 17 | 28 | our $VERSION = '3.64'; | |||||||||
| 18 | |||||||||||
| 19 | 28 | our $SECTION_END_MARKER; | |||||||||
| 20 | |||||||||||
| 21 | 432 | ▶ | sub TIEHANDLE { | ||||||||
|
Subroutine
TIEHANDLE: called CC=1 SCAR=0.0
| |||||||||||
| 22 | 432 | my ($class, $cfile, $fh) = @_; | |||||||||
| 23 | 432 | $cfile =~ s/\\/\\\\/g; | |||||||||
| 24 | 432 | $cfile =~ s/"/\\"/g; | |||||||||
| 25 | 432 | $SECTION_END_MARKER = qq{#line --- "$cfile"}; | |||||||||
| 26 | |||||||||||
| 27 | 432 | return bless { | |||||||||
| 28 | buffer => '', | ||||||||||
| 29 | fh => $fh, | ||||||||||
| 30 | line_no => 1, | ||||||||||
| 31 | }, $class; | ||||||||||
| 32 | } | ||||||||||
| 33 | |||||||||||
| 34 | 10705 | ▶ | sub PRINT { | ||||||||
|
Subroutine
PRINT: called CC=3 SCAR=11.0
| |||||||||||
| 35 | 10705 | my $self = shift; | |||||||||
| 36 | 10705 | for (@_) { | |||||||||
| 37 | 13838 | $self->{buffer} .= $_; | |||||||||
| 38 | 13838 | ▶ | while ($self->{buffer} =~ s/^([^\n]*\n)//) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 39 | 85191 | my $line = $1; | |||||||||
| 40 | 85191 | ++$self->{line_no}; | |||||||||
| 41 | 85191 | $line =~ s|^\#line\s+---(?=\s)|#line $self->{line_no}|; | |||||||||
| 42 | 85191 | print {$self->{fh}} $line; | |||||||||
| 43 | } | ||||||||||
| 44 | } | ||||||||||
| 45 | } | ||||||||||
| 46 | |||||||||||
| 47 | 345 | ▶ | sub PRINTF { | ||||||||
|
Subroutine
PRINTF: called CC=1 SCAR=0.0
| |||||||||||
| 48 | 345 | my $self = shift; | |||||||||
| 49 | 345 | my $fmt = shift; | |||||||||
| 50 | 345 | $self->PRINT(sprintf($fmt, @_)); | |||||||||
| 51 | } | ||||||||||
| 52 | |||||||||||
| 53 | 430 | ▶ | sub DESTROY { | ||||||||
|
Subroutine
DESTROY: called CC=2 SCAR=8.1
| |||||||||||
| 54 | # Not necessary if we're careful to end with a "\n" | ||||||||||
| 55 | 430 | my $self = shift; | |||||||||
| 56 | 0 | ▶ | print {$self->{fh}} $self->{buffer} if length $self->{buffer}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 57 | } | ||||||||||
| 58 | |||||||||||
| 59 | 370 | ▶ | sub UNTIE { | ||||||||
|
Subroutine
UNTIE: called CC=1 SCAR=0.0
| |||||||||||
| 60 | # This sub does nothing, but is necessary for references to be released. | ||||||||||
| 61 | } | ||||||||||
| 62 | |||||||||||
| 63 | 868 | ▶ | sub end_marker { | ||||||||
|
Subroutine
end_marker: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 64 | 868 | return $SECTION_END_MARKER; | |||||||||
| 65 | } | ||||||||||
| 66 | |||||||||||
| 67 | 28 | 1; | |||||||||