File Coverage

blib/lib/ExtUtils/ParseXS/CountLines.pm
Criterion Covered Total %
statement 24 24 100.0
branch n/a
condition n/a
subroutine 7 7 100.0
pod 0 1 0.0
total 31 32 96.8


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