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         7169  
3              
4             our $VERSION = '3.43_02';
5              
6             our $SECTION_END_MARKER;
7              
8             sub TIEHANDLE {
9 6     6   119 my ($class, $cfile, $fh) = @_;
10 6         95 $cfile =~ s/\\/\\\\/g;
11 6         122 $cfile =~ s/"/\\"/g;
12 6         82 $SECTION_END_MARKER = qq{#line --- "$cfile"};
13              
14 6         286 return bless {
15             buffer => '',
16             fh => $fh,
17             line_no => 1,
18             }, $class;
19             }
20              
21             sub PRINT {
22 805     805   1387 my $self = shift;
23 805         1580 for (@_) {
24 1037         2110 $self->{buffer} .= $_;
25 1037         3970 while ($self->{buffer} =~ s/^([^\n]*\n)//) {
26 2169         7389 my $line = $1;
27 2169         3159 ++$self->{line_no};
28 2169         3298 $line =~ s|^\#line\s+---(?=\s)|#line $self->{line_no}|;
29 2169         2828 print {$self->{fh}} $line;
  2169         9054  
30             }
31             }
32             }
33              
34             sub PRINTF {
35 1     1   2 my $self = shift;
36 1         3 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   17 my $self = shift;
43 6         10 print {$self->{fh}} $self->{buffer};
  6         43  
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 180 return $SECTION_END_MARKER;
52             }
53              
54             1;