File Coverage

blib/lib/Perl/Tidy/LineBuffer.pm
Criterion Covered Total %
statement 29 35 82.8
branch 4 6 66.6
condition n/a
subroutine 5 7 71.4
pod 0 3 0.0
total 38 51 74.5


line stmt bran cond sub pod time code
1             #####################################################################
2             #
3             # The Perl::Tidy::LineBuffer class supplies a 'get_line()'
4             # method for returning the next line to be parsed, as well as a
5             # 'peek_ahead()' method
6             #
7             # The input parameter is an object with a 'get_line()' method
8             # which returns the next line to be parsed
9             #
10             #####################################################################
11              
12             package Perl::Tidy::LineBuffer;
13 38     38   290 use strict;
  38         106  
  38         1173  
14 38     38   238 use warnings;
  38         84  
  38         16718  
15             our $VERSION = '20230701';
16              
17             sub AUTOLOAD {
18              
19             # Catch any undefined sub calls so that we are sure to get
20             # some diagnostic information. This sub should never be called
21             # except for a programming error.
22 0     0   0 our $AUTOLOAD;
23 0 0       0 return if ( $AUTOLOAD =~ /\bDESTROY$/ );
24 0         0 my ( $pkg, $fname, $lno ) = caller();
25 0         0 my $my_package = __PACKAGE__;
26 0         0 print STDERR <<EOM;
27             ======================================================================
28             Error detected in package '$my_package', version $VERSION
29             Received unexpected AUTOLOAD call for sub '$AUTOLOAD'
30             Called from package: '$pkg'
31             Called from File '$fname' at line '$lno'
32             This error is probably due to a recent programming change
33             ======================================================================
34             EOM
35 0         0 exit 1;
36             }
37              
38       0     sub DESTROY {
39              
40             # required to avoid call to AUTOLOAD in some versions of perl
41             }
42              
43             sub new {
44              
45 556     556 0 1963 my ( $class, $line_source_object ) = @_;
46              
47 556         3736 return bless {
48             _line_source_object => $line_source_object,
49             _rlookahead_buffer => [],
50             }, $class;
51             }
52              
53             sub peek_ahead {
54 1219     1219 0 3288 my ( $self, $buffer_index ) = @_;
55 1219         2377 my $line = undef;
56 1219         2460 my $line_source_object = $self->{_line_source_object};
57 1219         2205 my $rlookahead_buffer = $self->{_rlookahead_buffer};
58 1219 100       2255 if ( $buffer_index < scalar( @{$rlookahead_buffer} ) ) {
  1219         3423  
59 110         582 $line = $rlookahead_buffer->[$buffer_index];
60             }
61             else {
62 1109         3497 $line = $line_source_object->get_line();
63 1109         3605 push( @{$rlookahead_buffer}, $line );
  1109         3079  
64             }
65 1219         5247 return $line;
66             }
67              
68             sub get_line {
69 8205     8205 0 13067 my $self = shift;
70 8205         12944 my $line = undef;
71 8205         14057 my $line_source_object = $self->{_line_source_object};
72 8205         12446 my $rlookahead_buffer = $self->{_rlookahead_buffer};
73              
74 8205 100       11840 if ( scalar( @{$rlookahead_buffer} ) ) {
  8205         17899  
75 1109         1795 $line = shift @{$rlookahead_buffer};
  1109         2554  
76             }
77             else {
78 7096         22822 $line = $line_source_object->get_line();
79             }
80 8205         19497 return $line;
81             }
82             1;
83