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   125 use strict;
  18         46  
  18         7362  
3              
4             our $VERSION = '3.51';
5              
6             our $SECTION_END_MARKER;
7              
8             sub TIEHANDLE {
9 6     6   113 my ($class, $cfile, $fh) = @_;
10 6         80 $cfile =~ s/\\/\\\\/g;
11 6         71 $cfile =~ s/"/\\"/g;
12 6         80 $SECTION_END_MARKER = qq{#line --- "$cfile"};
13              
14 6         232 return bless {
15             buffer => '',
16             fh => $fh,
17             line_no => 1,
18             }, $class;
19             }
20              
21             sub PRINT {
22 904     904   1593 my $self = shift;
23 904         1754 for (@_) {
24 1138         2308 $self->{buffer} .= $_;
25 1138         4352 while ($self->{buffer} =~ s/^([^\n]*\n)//) {
26 2291         7660 my $line = $1;
27 2291         3280 ++$self->{line_no};
28 2291         3542 $line =~ s|^\#line\s+---(?=\s)|#line $self->{line_no}|;
29 2291         3086 print {$self->{fh}} $line;
  2291         9944  
30             }
31             }
32             }
33              
34             sub PRINTF {
35 1     1   4 my $self = shift;
36 1         2 my $fmt = shift;
37 1         12 $self->PRINT(sprintf($fmt, @_));
38             }
39              
40             sub DESTROY {
41             # Not necessary if we're careful to end with a "\n"
42 6     6   34 my $self = shift;
43 6         18 print {$self->{fh}} $self->{buffer};
  6         45  
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 137 return $SECTION_END_MARKER;
52             }
53              
54             1;