PPI/Token/Quote/Double.pm

filter: Statementstmt 100% 24 / 24 Branchbran 75.0% 3 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 7 / 7 Podpod 100% 3 / 3 totaltotal 97.3% 37 / 38 CC 3 SCAR 5.1
CC
3
Cov
96%
simplify
3.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.7
« 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 63 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
33 63 ▶use Params::Util qw{_INSTANCE};
Subroutine BEGIN: called CC=1 SCAR=0.0
34 63 ▶use PPI::Token::Quote ();
Subroutine BEGIN: called CC=1 SCAR=0.0
35 63 ▶use PPI::Token::_QuoteEngine::Simple ();
Subroutine BEGIN: called CC=1 SCAR=0.0
36  
37 63 our $VERSION = '1.260'; # VERSION
38  
39 63 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 ▶ !! ($_[0]->content =~ /(?<!\\)(?:\\\\)*[\$\@]/);
Subroutine interpolations: called CC=1 SCAR=0.0
Pod documented
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<simplify> 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<PPI::Token::Quote::Single> package.
80  
81 Because the length of the content is not changed, there is no need
82 to call the document's C<flush_locations> 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 ▶ 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
91  
92 # Don't bother if there are characters that could complicate things
93 6 my $content = $self->content;
94 6 my $value = substr($content, 1, length($content) - 2);
95 6 ▶ return $self if $value =~ /[\\\$@\'\"]/;
Branch: 1 branch
BranchTrueFalseTotal
if $value =~ /[\\\$\@\'\"]/ 4 2 6
96  
97 # Change the token to a single string
98 2 $self->{content} = "'$value'";
99 2 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 250 ▶ my $str = $_[0]->{content};
Subroutine string: called CC=1 SCAR=0.0
Pod documented
113 250 substr( $str, 1, length($str) - 2 );
114 }
115  
116 63 1;
117  
118 =pod
119  
120 =head1 SUPPORT
121  
122 See the L<support section|PPI/SUPPORT> in the main module.
123  
124 =head1 AUTHOR
125  
126 Adam Kennedy E<lt>adamk@cpan.orgE<gt>
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
« PPI/Token/Data.pm ↑ Summary PPI/Token/ArrayIndex.pm »