Filename | /Users/timbo/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/PPIx/Regexp/Token/Control.pm |
Statements | Executed 14 statements in 563µs |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 12µs | 24µs | BEGIN@39 | PPIx::Regexp::Token::Control::
1 | 1 | 1 | 7µs | 35µs | BEGIN@44 | PPIx::Regexp::Token::Control::
1 | 1 | 1 | 7µs | 12µs | BEGIN@40 | PPIx::Regexp::Token::Control::
1 | 1 | 1 | 7µs | 58µs | BEGIN@42 | PPIx::Regexp::Token::Control::
0 | 0 | 0 | 0s | 0s | __ANON__[:69] | PPIx::Regexp::Token::Control::
0 | 0 | 0 | 0s | 0s | __ANON__[:84] | PPIx::Regexp::Token::Control::
0 | 0 | 0 | 0s | 0s | __ANON__[:86] | PPIx::Regexp::Token::Control::
0 | 0 | 0 | 0s | 0s | __PPIX_TOKENIZER__regexp | PPIx::Regexp::Token::Control::
0 | 0 | 0 | 0s | 0s | __PPIX_TOKENIZER__repl | PPIx::Regexp::Token::Control::
0 | 0 | 0 | 0s | 0s | perl_version_introduced | PPIx::Regexp::Token::Control::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | =head1 NAME | ||||
2 | |||||
3 | PPIx::Regexp::Token::Control - Case and quote control. | ||||
4 | |||||
5 | =head1 SYNOPSIS | ||||
6 | |||||
7 | use PPIx::Regexp::Dumper; | ||||
8 | PPIx::Regexp::Dumper->new( 'qr{\Ufoo\E}smx' ) | ||||
9 | ->print(); | ||||
10 | |||||
11 | =head1 INHERITANCE | ||||
12 | |||||
13 | C<PPIx::Regexp::Token::Control> is a | ||||
14 | L<PPIx::Regexp::Token|PPIx::Regexp::Token>. | ||||
15 | |||||
16 | C<PPIx::Regexp::Token::Control> has no descendants. | ||||
17 | |||||
18 | =head1 DESCRIPTION | ||||
19 | |||||
20 | This class represents the case and quote controls. These apply when the | ||||
21 | regular expression is compiled, changing the actual expression | ||||
22 | generated. For example | ||||
23 | |||||
24 | print qr{\Ufoo\E}, "\n" | ||||
25 | |||||
26 | prints | ||||
27 | |||||
28 | (?-xism:FOO) | ||||
29 | |||||
30 | =head1 METHODS | ||||
31 | |||||
32 | This class provides no public methods beyond those provided by its | ||||
33 | superclass. | ||||
34 | |||||
35 | =cut | ||||
36 | |||||
37 | package PPIx::Regexp::Token::Control; | ||||
38 | |||||
39 | 2 | 22µs | 2 | 36µs | # spent 24µs (12+12) within PPIx::Regexp::Token::Control::BEGIN@39 which was called:
# once (12µs+12µs) by PPIx::Regexp::Tokenizer::BEGIN@23 at line 39 # spent 24µs making 1 call to PPIx::Regexp::Token::Control::BEGIN@39
# spent 12µs making 1 call to strict::import |
40 | 2 | 21µs | 2 | 16µs | # spent 12µs (7+5) within PPIx::Regexp::Token::Control::BEGIN@40 which was called:
# once (7µs+5µs) by PPIx::Regexp::Tokenizer::BEGIN@23 at line 40 # spent 12µs making 1 call to PPIx::Regexp::Token::Control::BEGIN@40
# spent 5µs making 1 call to warnings::import |
41 | |||||
42 | 2 | 27µs | 2 | 110µs | # spent 58µs (7+52) within PPIx::Regexp::Token::Control::BEGIN@42 which was called:
# once (7µs+52µs) by PPIx::Regexp::Tokenizer::BEGIN@23 at line 42 # spent 58µs making 1 call to PPIx::Regexp::Token::Control::BEGIN@42
# spent 52µs making 1 call to base::import |
43 | |||||
44 | 1 | 200ns | # spent 35µs (7+28) within PPIx::Regexp::Token::Control::BEGIN@44 which was called:
# once (7µs+28µs) by PPIx::Regexp::Tokenizer::BEGIN@23 at line 46 | ||
45 | COOKIE_QUOTE MINIMUM_PERL TOKEN_LITERAL TOKEN_UNKNOWN | ||||
46 | 1 | 468µs | 2 | 63µs | }; # spent 35µs making 1 call to PPIx::Regexp::Token::Control::BEGIN@44
# spent 28µs making 1 call to Exporter::import |
47 | |||||
48 | 1 | 1µs | our $VERSION = '0.036'; | ||
49 | |||||
50 | # Return true if the token can be quantified, and false otherwise | ||||
51 | # sub can_be_quantified { return }; | ||||
52 | |||||
53 | { | ||||
54 | 2 | 3µs | my %version_introduced = ( | ||
55 | '\\F' => '5.015008', | ||||
56 | ); | ||||
57 | |||||
58 | sub perl_version_introduced { | ||||
59 | my ( $self ) = @_; | ||||
60 | my $content = $self->content(); | ||||
61 | defined $version_introduced{$content} | ||||
62 | and return $version_introduced{$content}; | ||||
63 | return MINIMUM_PERL; | ||||
64 | } | ||||
65 | } | ||||
66 | |||||
67 | 1 | 9µs | my %is_control = map { $_ => 1 } qw{ l u L U Q E F }; | ||
68 | my %cookie = ( | ||||
69 | Q => sub { return 1; }, | ||||
70 | 1 | 4µs | E => undef, | ||
71 | ); | ||||
72 | |||||
73 | sub __PPIX_TOKENIZER__regexp { | ||||
74 | my ( $class, $tokenizer, $character ) = @_; | ||||
75 | |||||
76 | # If we are inside a quote sequence, we want to make literals out of | ||||
77 | # all the characters we reject; otherwise we just want to return | ||||
78 | # nothing. | ||||
79 | my $in_quote = $tokenizer->cookie( COOKIE_QUOTE ); | ||||
80 | my $reject = $in_quote ? | ||||
81 | sub { | ||||
82 | my ( $size, $class ) = @_; | ||||
83 | return $tokenizer->make_token( $size, $class || TOKEN_LITERAL ); | ||||
84 | } : sub { | ||||
85 | return; | ||||
86 | }; | ||||
87 | |||||
88 | # We are not interested in anything that is not escaped. | ||||
89 | $character eq '\\' or return $reject->( 1 ); | ||||
90 | |||||
91 | # We need to see what the next character is to figure out what to | ||||
92 | # do. If there is no next character, we do not know what to call the | ||||
93 | # back slash. | ||||
94 | my $control = $tokenizer->peek( 1 ) | ||||
95 | or return $reject->( 1, TOKEN_UNKNOWN, { | ||||
96 | error => 'Trailing back slash' | ||||
97 | }, | ||||
98 | ); | ||||
99 | |||||
100 | # We reject any escapes that do not represent controls. | ||||
101 | $is_control{$control} or return $reject->( 2 ); | ||||
102 | |||||
103 | # If we are quoting, we reject anything but an end quote. | ||||
104 | $in_quote and $control ne 'E' and return $reject->( 2 ); | ||||
105 | |||||
106 | # Anything left gets made into a token now, to avoid its processing | ||||
107 | # by the cookie we may make. | ||||
108 | my $token = $tokenizer->make_token( 2 ); | ||||
109 | |||||
110 | # \Q and \E make and destroy cookies respectively; do those things. | ||||
111 | exists $cookie{$control} | ||||
112 | and $tokenizer->cookie( COOKIE_QUOTE, $cookie{$control} ); | ||||
113 | |||||
114 | # Return our token. | ||||
115 | return $token; | ||||
116 | } | ||||
117 | |||||
118 | sub __PPIX_TOKENIZER__repl { | ||||
119 | my ( $class, $tokenizer, $character ) = @_; | ||||
120 | |||||
121 | $tokenizer->interpolates() and goto &__PPIX_TOKENIZER__regexp; | ||||
122 | |||||
123 | return; | ||||
124 | } | ||||
125 | |||||
126 | 1 | 8µs | 1; | ||
127 | |||||
128 | __END__ |