File Coverage

blib/lib/PPIx/QuoteLike/Token/Interpolation.pm
Criterion Covered Total %
statement 48 48 100.0
branch 12 14 85.7
condition 5 15 33.3
subroutine 11 11 100.0
pod 2 2 100.0
total 78 90 86.6


line stmt bran cond sub pod time code
1             package PPIx::QuoteLike::Token::Interpolation;
2              
3 7     7   1112 use 5.006;
  7         27  
4              
5 7     7   34 use strict;
  7         13  
  7         129  
6 7     7   28 use warnings;
  7         12  
  7         148  
7              
8 7     7   30 use Carp;
  7         8  
  7         338  
9 7     7   1259 use PPI::Document;
  7         298801  
  7         227  
10 7         664 use PPIx::QuoteLike::Constant qw{
11             LOCATION_COLUMN
12             LOCATION_LOGICAL_LINE
13             LOCATION_LOGICAL_FILE
14             @CARP_NOT
15 7     7   44 };
  7         14  
16 7         309 use PPIx::QuoteLike::Utils qw{
17             __normalize_interpolation_for_ppi
18             __variables
19 7     7   42 };
  7         10  
20              
21 7     7   37 use base qw{ PPIx::QuoteLike::Token };
  7         12  
  7         2838  
22              
23             our $VERSION = '0.023';
24              
25             sub ppi {
26 57     57 1 89 my ( $self ) = @_;
27 57 100       172 unless ( $self->{ppi} ) {
28 34         43 my $content;
29 34         58 my $location = $self->{location};
30 34 100       64 if ( $location ) {
31 13         16 my $fn;
32 13 100       27 if( defined( $fn = $location->[LOCATION_LOGICAL_FILE] ) ) {
33 1         3 $fn =~ s/ (?= [\\"] ) /\\/smxg;
34 1         4 $content = qq{#line $location->[LOCATION_LOGICAL_LINE] "$fn"\n};
35             } else {
36 12         35 $content = qq{#line $location->[LOCATION_LOGICAL_LINE]\n};
37             }
38 13         41 $content .= ' ' x ( $location->[LOCATION_COLUMN] - 1 );
39             }
40              
41 34         84 $content .= __normalize_interpolation_for_ppi( $self->content() );
42              
43 34         146 $self->{ppi} = PPI::Document->new( \$content );
44              
45 34 100       29688 if ( $location ) {
46             # Generate locations now.
47 13         68 $self->{ppi}->location();
48             # Remove the stuff we originally injected. NOTE that we can
49             # only get away with doing this if the removal does not
50             # invalidate the locations of the other tokens that we just
51             # generated.
52 13         2332 my $elem;
53             # Remove the '#line' directive if we find it
54 13 50 33     51 $elem = $self->{ppi}->child( 0 )
      33        
55             and $elem->isa( 'PPI::Token::Comment' )
56             and $elem->content() =~ m/ \A \#line\b /smx
57             and $elem->remove();
58             # Remove the white space if we find it, and if it in fact
59             # represents only the white space we injected to get the
60             # column numbers right.
61 13         707 my $wid = $location->[LOCATION_COLUMN] - 1;
62             $wid
63 13 50 33     46 and $elem = $self->{ppi}->child( 0 )
      33        
      33        
64             and $elem->isa( 'PPI::Token::Whitespace' )
65             and $wid == length $elem->content()
66             and $elem->remove();
67             }
68             }
69 57         722 return $self->{ppi};
70             }
71              
72             sub variables {
73 56     56 1 96 my ( $self ) = @_;
74 56         107 return __variables( $self->ppi() );
75             }
76              
77             sub __perl_version_introduced {
78 16     16   25 my ( $self ) = @_;
79             $self->{postderef}
80 16 100       42 and return '5.019005';
81 9         44 return;
82             }
83              
84             1;
85              
86             __END__