| 1 |
package ExtUtils::ParseXS::CountLines; |
| 2 |
use strict; |
| 3 |
|
| 4 |
our $VERSION = '3.51'; |
| 5 |
|
| 6 |
our $SECTION_END_MARKER; |
| 7 |
|
| 8 |
sub TIEHANDLE { |
| 9 |
my ($class, $cfile, $fh) = @_; |
| 10 |
$cfile =~ s/\\/\\\\/g; |
| 11 |
$cfile =~ s/"/\\"/g; |
| 12 |
$SECTION_END_MARKER = qq{#line --- "$cfile"}; |
| 13 |
|
| 14 |
return bless { |
| 15 |
buffer => '', |
| 16 |
fh => $fh, |
| 17 |
line_no => 1, |
| 18 |
}, $class; |
| 19 |
} |
| 20 |
|
| 21 |
sub PRINT { |
| 22 |
my $self = shift; |
| 23 |
for (@_) { |
| 24 |
$self->{buffer} .= $_; |
| 25 |
while ($self->{buffer} =~ s/^([^\n]*\n)//) { |
| 26 |
my $line = $1; |
| 27 |
++$self->{line_no}; |
| 28 |
$line =~ s|^\#line\s+---(?=\s)|#line $self->{line_no}|; |
| 29 |
print {$self->{fh}} $line; |
| 30 |
} |
| 31 |
} |
| 32 |
} |
| 33 |
|
| 34 |
sub PRINTF { |
| 35 |
my $self = shift; |
| 36 |
my $fmt = shift; |
| 37 |
$self->PRINT(sprintf($fmt, @_)); |
| 38 |
} |
| 39 |
|
| 40 |
sub DESTROY { |
| 41 |
# Not necessary if we're careful to end with a "\n" |
| 42 |
my $self = shift; |
| 43 |
print {$self->{fh}} $self->{buffer}; |
| 44 |
} |
| 45 |
|
| 46 |
sub UNTIE { |
| 47 |
# This sub does nothing, but is necessary for references to be released. |
| 48 |
} |
| 49 |
|
| 50 |
sub end_marker { |
| 51 |
return $SECTION_END_MARKER; |
| 52 |
} |
| 53 |
|
| 54 |
1; |