← 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:14 2016

Filename/Users/timbo/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/PPIx/Regexp/Token/GroupType.pm
StatementsExecuted 9 statements in 500µs
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
11116µs31µsPPIx::Regexp::Token::GroupType::::BEGIN@41PPIx::Regexp::Token::GroupType::BEGIN@41
11110µs77µsPPIx::Regexp::Token::GroupType::::BEGIN@44PPIx::Regexp::Token::GroupType::BEGIN@44
1119µs15µsPPIx::Regexp::Token::GroupType::::BEGIN@42PPIx::Regexp::Token::GroupType::BEGIN@42
0000s0sPPIx::Regexp::Token::GroupType::::__PPIX_TOKENIZER__regexpPPIx::Regexp::Token::GroupType::__PPIX_TOKENIZER__regexp
0000s0sPPIx::Regexp::Token::GroupType::::__defining_stringPPIx::Regexp::Token::GroupType::__defining_string
0000s0sPPIx::Regexp::Token::GroupType::::__make_group_type_matcherPPIx::Regexp::Token::GroupType::__make_group_type_matcher
0000s0sPPIx::Regexp::Token::GroupType::::__match_setupPPIx::Regexp::Token::GroupType::__match_setup
0000s0sPPIx::Regexp::Token::GroupType::::can_be_quantifiedPPIx::Regexp::Token::GroupType::can_be_quantified
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1=head1 NAME
2
3PPIx::Regexp::Token::GroupType - Represent a grouping parenthesis type.
4
5=head1 SYNOPSIS
6
7 use PPIx::Regexp::Dumper;
8 PPIx::Regexp::Dumper->new( 'qr{(?i:foo)}smx' )
9 ->print();
10
11=head1 INHERITANCE
12
13C<PPIx::Regexp::Token::GroupType> is a
14L<PPIx::Regexp::Token|PPIx::Regexp::Token>.
15
16C<PPIx::Regexp::Token::GroupType> is the parent of
17L<PPIx::Regexp::Token::GroupType::Assertion|PPIx::Regexp::Token::GroupType::Assertion>,
18L<PPIx::Regexp::Token::GroupType::BranchReset|PPIx::Regexp::Token::GroupType::BranchReset>,
19L<PPIx::Regexp::Token::GroupType::Code|PPIx::Regexp::Token::GroupType::Code>,
20L<PPIx::Regexp::Token::GroupType::Modifier|PPIx::Regexp::Token::GroupType::Modifier>,
21L<PPIx::Regexp::Token::GroupType::NamedCapture|PPIx::Regexp::Token::GroupType::NamedCapture>,
22L<PPIx::Regexp::Token::GroupType::Subexpression|PPIx::Regexp::Token::GroupType::Subexpression>
23and
24L<PPIx::Regexp::Token::GroupType::Switch|PPIx::Regexp::Token::GroupType::Switch>.
25
26=head1 DESCRIPTION
27
28This class represents any of the magic sequences of characters that can
29follow an open parenthesis. This particular class is intended to be
30abstract.
31
32=head1 METHODS
33
34This class provides no public methods beyond those provided by its
35superclass.
36
37=cut
38
39package PPIx::Regexp::Token::GroupType;
40
41227µs247µs
# spent 31µs (16+16) within PPIx::Regexp::Token::GroupType::BEGIN@41 which was called: # once (16µs+16µs) by base::import at line 41
use strict;
# spent 31µs making 1 call to PPIx::Regexp::Token::GroupType::BEGIN@41 # spent 16µs making 1 call to strict::import
42233µs221µs
# spent 15µs (9+6) within PPIx::Regexp::Token::GroupType::BEGIN@42 which was called: # once (9µs+6µs) by base::import at line 42
use warnings;
# spent 15µs making 1 call to PPIx::Regexp::Token::GroupType::BEGIN@42 # spent 6µs making 1 call to warnings::import
43
442436µs277µs
# spent 77µs (10+67) within PPIx::Regexp::Token::GroupType::BEGIN@44 which was called: # once (10µs+67µs) by base::import at line 44
use base qw{ PPIx::Regexp::Token };
# spent 77µs making 1 call to PPIx::Regexp::Token::GroupType::BEGIN@44 # spent 67µs making 1 call to base::import, recursion: max depth 1, sum of overlapping time 67µs
45
461800nsour $VERSION = '0.036';
47
48# Return true if the token can be quantified, and false otherwise
49sub can_be_quantified { return };
50
51=head2 __defining_string
52
53 my $string = $class->__defining_string();
54
55This method is private to the C<PPIx-Regexp> package, and is documented
56for the author's benefit only. It may be changed or revoked without
57notice.
58
59This method returns an array of strings that define the specific group
60type. These strings will normally start with C<'?'>.
61
62Optionally, the first returned item may be a hash reference. The only
63supported key is C<{suffix}>, which is a string to be suffixed to each
64of the regular expressions made by C<__make_group_type_matcher()> out of
65the defining strings, inside a C<(?= ... )>, so that it is not included
66in the match.
67
68This method B<must> be overridden, unless C<__make_group_type_matcher()>
69is.
70
71=cut
72
73sub __defining_string {
74 require Carp;
75 Carp::confess(
76 'Programming error - __defining_string() must be overridden' );
77}
78
79=head2 __make_group_type_matcher
80
81 my $hash_ref = $class->__make_group_type_matcher();
82
83This method is private to the C<PPIx-Regexp> package, and is documented
84for the author's benefit only. It may be changed or revoked without
85notice.
86
87This method returns a reference to a hash. The keys are regexp delimiter
88characters which appear in the defining strings for the group type. For
89each key, the value is a reference to an array of C<Regexp> objects,
90properly escaped for the key character. Key C<''> provides the regular
91expressions to be used if the regexp delimiter does not appear in any of
92the defining strings.
93
94If this method is overridden by the subclass, method
95C<__defining_string()> need not be, unless the overridden
96C<__make_group_type_matcher()> calls C<__defining_string()>.
97
98=cut
99
100sub __make_group_type_matcher {
101 my ( $class ) = @_;
102
103 my @defs = $class->__defining_string();
104
105 my $opt = ref $defs[0] ? shift @defs : {};
106
107 my $suffix = defined $opt->{suffix} ?
108 qr/ (?= \Q$opt->{suffix}\E ) /smx :
109 '';
110
111 my %rslt;
112 foreach my $str ( $class->__defining_string() ) {
113 my %seen;
114 my @chars = grep { ! $seen{$_}++ } split qr{}smx, $str;
115 push @{ $rslt{''} ||= [] }, qr{ \A \Q$str\E $suffix }smx;
116 foreach my $chr ( @chars ) {
117 ( my $expr = $str ) =~ s/ (?= \Q$chr\E ) /\\/smxg;
118 push @{ $rslt{$chr} ||= [] }, qr{ \A \Q$expr\E $suffix }smx;
119 }
120 }
121 return \%rslt;
122}
123
124
125=head2 __match_setup
126
127 $class->__match_setup( $tokenizer );
128
129This method is private to the C<PPIx-Regexp> package, and is documented
130for the author's benefit only. It may be changed or revoked without
131notice.
132
133This method performs whatever setup is needed once it is determined that
134the given group type has been detected. This method is called only if
135the class matched at the current position in the string being parsed. It
136must perform whatever extra setup is needed for the match. It returns
137nothing.
138
139This method need not be overridden. The default does nothing.
140
141=cut
142
143sub __match_setup {
144 return;
145}
146
1471200nsmy %matcher;
148
149sub __PPIX_TOKENIZER__regexp {
150 my ( $class, $tokenizer, $character ) = @_;
151
152 my $mtch = $matcher{$class} ||= $class->__make_group_type_matcher();
153
154 my $re_list = $mtch->{ $tokenizer->get_start_delimiter() } ||
155 $mtch->{''};
156
157 foreach my $re ( @{ $re_list } ) {
158 my $accept = $tokenizer->find_regexp( $re )
159 or next;
160 $class->__match_setup( $tokenizer );
161 return $accept;
162 }
163
164 return;
165}
166
16714µs1;
168
169__END__