← Index
NYTProf Performance Profile   « line view »
For /Users/timbo/perl5/perlbrew/perls/perl-5.18.2/bin/perlcritic
  Run on Sat Mar 19 22:12:22 2016
Reported on Sat Mar 19 22:14:10 2016

Filename/Users/timbo/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/PPI/Token/Quote/Double.pm
StatementsExecuted 13 statements in 355µs
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
111234µs1.04msPPI::Token::Quote::Double::::BEGIN@37PPI::Token::Quote::Double::BEGIN@37
11114µs26µsPPI::Token::Quote::Double::::BEGIN@34PPI::Token::Quote::Double::BEGIN@34
11110µs10µsPPI::Token::Quote::Double::::BEGIN@40PPI::Token::Quote::Double::BEGIN@40
1119µs30µsPPI::Token::Quote::Double::::BEGIN@35PPI::Token::Quote::Double::BEGIN@35
1117µs35µsPPI::Token::Quote::Double::::BEGIN@39PPI::Token::Quote::Double::BEGIN@39
1113µs3µsPPI::Token::Quote::Double::::BEGIN@36PPI::Token::Quote::Double::BEGIN@36
0000s0sPPI::Token::Quote::Double::::interpolationsPPI::Token::Quote::Double::interpolations
0000s0sPPI::Token::Quote::Double::::simplifyPPI::Token::Quote::Double::simplify
0000s0sPPI::Token::Quote::Double::::stringPPI::Token::Quote::Double::string
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package PPI::Token::Quote::Double;
2
3=pod
4
5=head1 NAME
6
7PPI::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
18A C<PPI::Token::Quote::Double> object represents a double-quoted
19interpolating string.
20
21The string is treated as a single entity, L<PPI> will not try to
22understand what is in the string during the parsing process.
23
24=head1 METHODS
25
26There are several methods available for C<PPI::Token::Quote::Double>, beyond
27those provided by the parent L<PPI::Token::Quote>, L<PPI::Token> and
28L<PPI::Element> classes.
29
30Got any ideas for methods? Submit a report to rt.cpan.org!
31
32=cut
33
34225µs238µs
# spent 26µs (14+12) within PPI::Token::Quote::Double::BEGIN@34 which was called: # once (14µs+12µs) by PPI::Token::BEGIN@55 at line 34
use strict;
# spent 26µs making 1 call to PPI::Token::Quote::Double::BEGIN@34 # spent 12µs making 1 call to strict::import
35220µs251µs
# spent 30µs (9+21) within PPI::Token::Quote::Double::BEGIN@35 which was called: # once (9µs+21µs) by PPI::Token::BEGIN@55 at line 35
use Params::Util qw{_INSTANCE};
# spent 30µs making 1 call to PPI::Token::Quote::Double::BEGIN@35 # spent 21µs making 1 call to Exporter::import
36216µs13µs
# spent 3µs within PPI::Token::Quote::Double::BEGIN@36 which was called: # once (3µs+0s) by PPI::Token::BEGIN@55 at line 36
use PPI::Token::Quote ();
# spent 3µs making 1 call to PPI::Token::Quote::Double::BEGIN@36
37285µs11.04ms
# spent 1.04ms (234µs+806µs) within PPI::Token::Quote::Double::BEGIN@37 which was called: # once (234µs+806µs) by PPI::Token::BEGIN@55 at line 37
use PPI::Token::_QuoteEngine::Simple ();
# spent 1.04ms making 1 call to PPI::Token::Quote::Double::BEGIN@37
38
39230µs263µs
# spent 35µs (7+28) within PPI::Token::Quote::Double::BEGIN@39 which was called: # once (7µs+28µs) by PPI::Token::BEGIN@55 at line 39
use vars qw{$VERSION @ISA};
# spent 35µs making 1 call to PPI::Token::Quote::Double::BEGIN@39 # spent 28µs making 1 call to vars::import
40
# spent 10µs within PPI::Token::Quote::Double::BEGIN@40 which was called: # once (10µs+0s) by PPI::Token::BEGIN@55 at line 46
BEGIN {
411300ns $VERSION = '1.215';
42110µs @ISA = qw{
43 PPI::Token::_QuoteEngine::Simple
44 PPI::Token::Quote
45 };
461167µs110µs}
# spent 10µs making 1 call to PPI::Token::Quote::Double::BEGIN@40
47
- -
52#####################################################################
53# PPI::Token::Quote::Double Methods
54
55=pod
56
57=head2 interpolations
58
59The interpolations method checks to see if the double quote actually
60contains any interpolated variables.
61
62Returns true if the string contains interpolations, or false if not.
63
64=begin testing interpolations 8
65
66# Get a set of objects
67my $Document = PPI::Document->new(\<<'END_PERL');
68"no interpolations"
69"no \@interpolations"
70"has $interpolation"
71"has @interpolation"
72"has \\@interpolation"
73"" # False content to test double-negation scoping
74END_PERL
75isa_ok( $Document, 'PPI::Document' );
76my $strings = $Document->find('Token::Quote::Double');
77is( scalar @{$strings}, 6, 'Found the 6 test strings' );
78is( $strings->[0]->interpolations, '', 'String 1: No interpolations' );
79is( $strings->[1]->interpolations, '', 'String 2: No interpolations' );
80is( $strings->[2]->interpolations, 1, 'String 3: Has interpolations' );
81is( $strings->[3]->interpolations, 1, 'String 4: Has interpolations' );
82is( $strings->[4]->interpolations, 1, 'String 5: Has interpolations' );
83is( $strings->[5]->interpolations, '', 'String 6: No interpolations' );
84
85=end testing
86
87=cut
88
89# Upgrade: Return the interpolated substrings.
90# Upgrade: Returns parsed expressions.
91sub interpolations {
92 # Are there any unescaped $things in the string
93 !! ($_[0]->content =~ /(?<!\\)(?:\\\\)*[\$\@]/);
94}
95
96=pod
97
98=head2 simplify
99
100For various reasons, some people find themselves compelled to have
101their code in the simplest form possible.
102
103The C<simply> method will turn a simple double-quoted string into the
104equivalent single-quoted string.
105
106If the double can be simplified, it will be modified in place and
107returned as a convenience, or returns false if the string cannot be
108simplified.
109
110=begin testing simplify 8
111
112my $Document = PPI::Document->new(\<<'END_PERL');
113"no special characters"
114"has \"double\" quotes"
115"has 'single' quotes"
116"has $interpolation"
117"has @interpolation"
118""
119END_PERL
120isa_ok( $Document, 'PPI::Document' );
121my $strings = $Document->find('Token::Quote::Double');
122is( scalar @{$strings}, 6, 'Found the 6 test strings' );
123is( $strings->[0]->simplify, q<'no special characters'>, 'String 1: No special characters' );
124is( $strings->[1]->simplify, q<"has \"double\" quotes">, 'String 2: Double quotes' );
125is( $strings->[2]->simplify, q<"has 'single' quotes">, 'String 3: Single quotes' );
126is( $strings->[3]->simplify, q<"has $interpolation">, 'String 3: Has interpolation' );
127is( $strings->[4]->simplify, q<"has @interpolation">, 'String 4: Has interpolation' );
128is( $strings->[5]->simplify, q<''>, 'String 6: Empty string' );
129
130=end testing
131
132=cut
133
134sub simplify {
135 # This only works on EXACTLY this class
136 my $self = _INSTANCE(shift, 'PPI::Token::Quote::Double') or return undef;
137
138 # Don't bother if there are characters that could complicate things
139 my $content = $self->content;
140 my $value = substr($content, 1, length($content) - 2);
141 return $self if $value =~ /[\\\$@\'\"]/;
142
143 # Change the token to a single string
144 $self->{content} = "'$value'";
145 bless $self, 'PPI::Token::Quote::Single';
146}
147
- -
154#####################################################################
155# PPI::Token::Quote Methods
156
157=pod
158
159=begin testing string 3
160
161my $Document = PPI::Document->new( \'print "foo";' );
162isa_ok( $Document, 'PPI::Document' );
163my $Double = $Document->find_first('Token::Quote::Double');
164isa_ok( $Double, 'PPI::Token::Quote::Double' );
165is( $Double->string, 'foo', '->string returns as expected' );
166
167=end testing
168
169=cut
170
171sub string {
172 my $str = $_[0]->{content};
173 substr( $str, 1, length($str) - 2 );
174}
175
17612µs1;
177
178=pod
179
180=head1 SUPPORT
181
182See the L<support section|PPI/SUPPORT> in the main module.
183
184=head1 AUTHOR
185
186Adam Kennedy E<lt>adamk@cpan.orgE<gt>
187
188=head1 COPYRIGHT
189
190Copyright 2001 - 2011 Adam Kennedy.
191
192This program is free software; you can redistribute
193it and/or modify it under the same terms as Perl itself.
194
195The full text of the license can be found in the
196LICENSE file included with this module.
197
198=cut