PPI/Token/Quote/Double.pm

filter: Statementstmt 100% 27 / 27 Branchbran 75.0% 3 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 9 / 9 Podpod 100% 3 / 3 totaltotal 97.6% 42 / 43 CC 3 SCAR 4.4
CC
3
Cov
97%
simplify
3.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.5
« PPI/Token/Data.pm ↑ Summary PPI/Token/ArrayIndex.pm »
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<PPI::Token::Quote::Double> object represents a double-quoted
19 interpolating string.
20  
21 The string is treated as a single entity, L<PPI> 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<PPI::Token::Quote::Double>, beyond
27 those provided by the parent L<PPI::Token::Quote>, L<PPI::Token> and
28 L<PPI::Element> classes.
29  
30 =cut
31  
32 62 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
33 62 ▶use Params::Util qw{_INSTANCE};
Subroutine BEGIN: called CC=1 SCAR=0.0
34 62 ▶use PPI::Token::Quote ();
Subroutine BEGIN: called CC=1 SCAR=0.0
35 62 ▶use PPI::Token::_QuoteEngine::Simple ();
Subroutine BEGIN: called CC=1 SCAR=0.0
36  
37 62 ▶use vars qw{$VERSION @ISA};
Subroutine BEGIN: called CC=1 SCAR=0.0
38 BEGIN {
39 62 ▶ $VERSION = '1.236';
Subroutine BEGIN: called CC=1 SCAR=0.0
40 62 @ISA = qw{
41 PPI::Token::_QuoteEngine::Simple
42 PPI::Token::Quote
43 };
44 }
45  
46  
47  
48  
49  
50 #####################################################################
51 # PPI::Token::Quote::Double Methods
52  
53 =pod
54  
55 =head2 interpolations
56  
57 The interpolations method checks to see if the double quote actually
58 contains any interpolated variables.
59  
60 Returns true if the string contains interpolations, or false if not.
61  
62 =cut
63  
64 # Upgrade: Return the interpolated substrings.
65 # Upgrade: Returns parsed expressions.
66 sub interpolations {
67 # Are there any unescaped $things in the string
68 6 ▶ !! ($_[0]->content =~ /(?<!\\)(?:\\\\)*[\$\@]/);
Subroutine interpolations: called CC=1 SCAR=0.0
Pod documented
69 }
70  
71 =pod
72  
73 =head2 simplify
74  
75 For various reasons, some people find themselves compelled to have
76 their code in the simplest form possible.
77  
78 The C<simplify> method will, if possible, modify a simple double-quoted
79 string token in place, turning it into the equivalent single-quoted
80 string. If the token is modified, it is reblessed into the
81 L<PPI::Token::Quote::Single> package.
82  
83 Because the length of the content is not changed, there is no need
84 to call the document's C<flush_locations> method.
85  
86 The object itself is returned as a convenience.
87  
88 =cut
89  
90 sub simplify {
91 # This only works on EXACTLY this class
92 6 ▶ my $self = _INSTANCE(shift, 'PPI::Token::Quote::Double') or return undef;
Subroutine simplify: called CC=3 SCAR=11.0
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
my $self = &_INSTANCE(shift(), "PPI::Token::Quote::Double") or return undef 0 6 6
93  
94 # Don't bother if there are characters that could complicate things
95 6 my $content = $self->content;
96 6 my $value = substr($content, 1, length($content) - 2);
97 6 ▶ return $self if $value =~ /[\\\$@\'\"]/;
Branch: 1 branch
BranchTrueFalseTotal
if $value =~ /[\\\$\@\'\"]/ 4 2 6
98  
99 # Change the token to a single string
100 2 $self->{content} = "'$value'";
101 2 bless $self, 'PPI::Token::Quote::Single';
102 }
103  
104  
105  
106  
107  
108  
109  
110 #####################################################################
111 # PPI::Token::Quote Methods
112  
113 sub string {
114 123 ▶ my $str = $_[0]->{content};
Subroutine string: called CC=1 SCAR=0.0
Pod documented
115 123 substr( $str, 1, length($str) - 2 );
116 }
117  
118 62 1;
119  
120 =pod
121  
122 =head1 SUPPORT
123  
124 See the L<support section|PPI/SUPPORT> in the main module.
125  
126 =head1 AUTHOR
127  
128 Adam Kennedy E<lt>adamk@cpan.orgE<gt>
129  
130 =head1 COPYRIGHT
131  
132 Copyright 2001 - 2011 Adam Kennedy.
133  
134 This program is free software; you can redistribute
135 it and/or modify it under the same terms as Perl itself.
136  
137 The full text of the license can be found in the
138 LICENSE file included with this module.
139  
140 =cut
« PPI/Token/Data.pm ↑ Summary PPI/Token/ArrayIndex.pm »