File Coverage

blib/lib/PPI/Token/Quote/Double.pm
Criterion Covered Total %
statement 21 21 100.0
branch 3 4 75.0
condition n/a
subroutine 7 7 100.0
pod 3 3 100.0
total 34 35 97.1


line stmt bran cond sub pod time code
1             package PPI::Token::Quote::Double;
2              
3             =pod
4              
5             =head1 NAME
6              
7             PPI::Token::Quote::Double - A standard "double quote" token
8              
9             =head1 INHERITANCE
10              
11             PPI::Token::Quote::Double
12             isa PPI::Token::Quote
13             isa PPI::Token
14             isa PPI::Element
15              
16             =head1 DESCRIPTION
17              
18             A C object represents a double-quoted
19             interpolating string.
20              
21             The string is treated as a single entity, L will not try to
22             understand what is in the string during the parsing process.
23              
24             =head1 METHODS
25              
26             There are several methods available for C, beyond
27             those provided by the parent L, L and
28             L classes.
29              
30             =cut
31              
32 65     65   378 use strict;
  65         109  
  65         2060  
33 65     65   305 use Params::Util qw{_INSTANCE};
  65         513  
  65         2396  
34 65     65   330 use PPI::Token::Quote ();
  65         112  
  65         753  
35 65     65   246 use PPI::Token::_QuoteEngine::Simple ();
  65         103  
  65         15741  
36              
37             our $VERSION = '1.276';
38              
39             our @ISA = qw{
40             PPI::Token::_QuoteEngine::Simple
41             PPI::Token::Quote
42             };
43              
44              
45              
46              
47              
48             #####################################################################
49             # PPI::Token::Quote::Double Methods
50              
51             =pod
52              
53             =head2 interpolations
54              
55             The interpolations method checks to see if the double quote actually
56             contains any interpolated variables.
57              
58             Returns true if the string contains interpolations, or false if not.
59              
60             =cut
61              
62             # Upgrade: Return the interpolated substrings.
63             # Upgrade: Returns parsed expressions.
64             sub interpolations {
65             # Are there any unescaped $things in the string
66 6     6 1 568 !! ($_[0]->content =~ /(?
67             }
68              
69             =pod
70              
71             =head2 simplify
72              
73             For various reasons, some people find themselves compelled to have
74             their code in the simplest form possible.
75              
76             The C method will, if possible, modify a simple double-quoted
77             string token in place, turning it into the equivalent single-quoted
78             string. If the token is modified, it is reblessed into the
79             L package.
80              
81             Because the length of the content is not changed, there is no need
82             to call the document's C method.
83              
84             The object itself is returned as a convenience.
85              
86             =cut
87              
88             sub simplify {
89             # This only works on EXACTLY this class
90 6 50   6 1 484 my $self = _INSTANCE(shift, 'PPI::Token::Quote::Double') or return undef;
91              
92             # Don't bother if there are characters that could complicate things
93 6         15 my $content = $self->content;
94 6         14 my $value = substr($content, 1, length($content) - 2);
95 6 100       35 return $self if $value =~ /[\\\$@\'\"]/;
96              
97             # Change the token to a single string
98 2         5 $self->{content} = "'$value'";
99 2         10 bless $self, 'PPI::Token::Quote::Single';
100             }
101              
102              
103              
104              
105              
106              
107              
108             #####################################################################
109             # PPI::Token::Quote Methods
110              
111             sub string {
112 252     252 1 2994 my $str = $_[0]->{content};
113 252         831 substr( $str, 1, length($str) - 2 );
114             }
115              
116             1;
117              
118             =pod
119              
120             =head1 SUPPORT
121              
122             See the L in the main module.
123              
124             =head1 AUTHOR
125              
126             Adam Kennedy Eadamk@cpan.orgE
127              
128             =head1 COPYRIGHT
129              
130             Copyright 2001 - 2011 Adam Kennedy.
131              
132             This program is free software; you can redistribute
133             it and/or modify it under the same terms as Perl itself.
134              
135             The full text of the license can be found in the
136             LICENSE file included with this module.
137              
138             =cut