This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Update ExtUtils-ParseXS to CPAN version 3.07
[perl5.git] / dist / ExtUtils-ParseXS / lib / ExtUtils / ParseXS / CountLines.pm
CommitLineData
9e831c8e
JK
1package ExtUtils::ParseXS::CountLines;
2use strict;
71a65ad3 3
ac616993 4our $VERSION = '3.07';
71a65ad3 5
9e831c8e
JK
6our $SECTION_END_MARKER;
7
8sub TIEHANDLE {
9 my ($class, $cfile, $fh) = @_;
10 $cfile =~ s/\\/\\\\/g;
11 $SECTION_END_MARKER = qq{#line --- "$cfile"};
12
13 return bless {
14 buffer => '',
15 fh => $fh,
16 line_no => 1,
17 }, $class;
18}
19
20sub PRINT {
21 my $self = shift;
22 for (@_) {
23 $self->{buffer} .= $_;
24 while ($self->{buffer} =~ s/^([^\n]*\n)//) {
25 my $line = $1;
26 ++$self->{line_no};
27 $line =~ s|^\#line\s+---(?=\s)|#line $self->{line_no}|;
28 print {$self->{fh}} $line;
29 }
30 }
31}
32
33sub PRINTF {
34 my $self = shift;
35 my $fmt = shift;
36 $self->PRINT(sprintf($fmt, @_));
37}
38
39sub DESTROY {
40 # Not necessary if we're careful to end with a "\n"
41 my $self = shift;
42 print {$self->{fh}} $self->{buffer};
43}
44
45sub UNTIE {
629b8367 46 # This sub does nothing, but is necessary for references to be released.
9e831c8e
JK
47}
48
49sub end_marker {
50 return $SECTION_END_MARKER;
51}
52
531;