Filename | /Users/timbo/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/PPIx/Regexp/Structure/Regexp.pm |
Statements | Executed 8 statements in 207µs |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 15µs | 26µs | BEGIN@34 | PPIx::Regexp::Structure::Regexp::
1 | 1 | 1 | 8µs | 12µs | BEGIN@35 | PPIx::Regexp::Structure::Regexp::
1 | 1 | 1 | 6µs | 55µs | BEGIN@37 | PPIx::Regexp::Structure::Regexp::
0 | 0 | 0 | 0s | 0s | __PPIX_LEXER__finalize | PPIx::Regexp::Structure::Regexp::
0 | 0 | 0 | 0s | 0s | can_be_quantified | PPIx::Regexp::Structure::Regexp::
0 | 0 | 0 | 0s | 0s | capture_names | PPIx::Regexp::Structure::Regexp::
0 | 0 | 0 | 0s | 0s | max_capture_number | PPIx::Regexp::Structure::Regexp::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | =head1 NAME | ||||
2 | |||||
3 | PPIx::Regexp::Structure::Regexp - Represent the top-level regular expression | ||||
4 | |||||
5 | =head1 SYNOPSIS | ||||
6 | |||||
7 | use PPIx::Regexp::Dumper; | ||||
8 | PPIx::Regexp::Dumper->new( 'qr{foo}smx' ) | ||||
9 | ->print(); | ||||
10 | |||||
11 | =head1 INHERITANCE | ||||
12 | |||||
13 | C<PPIx::Regexp::Structure::Regexp> is a | ||||
14 | L<PPIx::Regexp::Structure::Main|PPIx::Regexp::Structure::Main>. | ||||
15 | |||||
16 | C<PPIx::Regexp::Structure::Regexp> has no descendants. | ||||
17 | |||||
18 | =head1 DESCRIPTION | ||||
19 | |||||
20 | This class represents the top-level regular expression. In the example | ||||
21 | given in the L</SYNOPSIS>, the C<{foo}> will be represented by this | ||||
22 | class. | ||||
23 | |||||
24 | =head1 METHODS | ||||
25 | |||||
26 | This class provides the following public methods. Methods not documented | ||||
27 | here are private, and unsupported in the sense that the author reserves | ||||
28 | the right to change or remove them without notice. | ||||
29 | |||||
30 | =cut | ||||
31 | |||||
32 | package PPIx::Regexp::Structure::Regexp; | ||||
33 | |||||
34 | 2 | 20µs | 2 | 38µs | # spent 26µs (15+11) within PPIx::Regexp::Structure::Regexp::BEGIN@34 which was called:
# once (15µs+11µs) by PPIx::Regexp::Lexer::BEGIN@55 at line 34 # spent 26µs making 1 call to PPIx::Regexp::Structure::Regexp::BEGIN@34
# spent 11µs making 1 call to strict::import |
35 | 2 | 23µs | 2 | 16µs | # spent 12µs (8+4) within PPIx::Regexp::Structure::Regexp::BEGIN@35 which was called:
# once (8µs+4µs) by PPIx::Regexp::Lexer::BEGIN@55 at line 35 # spent 12µs making 1 call to PPIx::Regexp::Structure::Regexp::BEGIN@35
# spent 4µs making 1 call to warnings::import |
36 | |||||
37 | 2 | 161µs | 2 | 103µs | # spent 55µs (6+48) within PPIx::Regexp::Structure::Regexp::BEGIN@37 which was called:
# once (6µs+48µs) by PPIx::Regexp::Lexer::BEGIN@55 at line 37 # spent 55µs making 1 call to PPIx::Regexp::Structure::Regexp::BEGIN@37
# spent 48µs making 1 call to base::import |
38 | |||||
39 | 1 | 500ns | our $VERSION = '0.036'; | ||
40 | |||||
41 | sub can_be_quantified { return; } | ||||
42 | |||||
43 | =head2 capture_names | ||||
44 | |||||
45 | foreach my $name ( $re->capture_names() ) { | ||||
46 | print "Capture name '$name'\n"; | ||||
47 | } | ||||
48 | |||||
49 | This method returns the capture names found in the regular expression. | ||||
50 | |||||
51 | =cut | ||||
52 | |||||
53 | sub capture_names { | ||||
54 | my ( $self ) = @_; | ||||
55 | my %name; | ||||
56 | my $captures = $self->find( | ||||
57 | 'PPIx::Regexp::Structure::NamedCapture') | ||||
58 | or return; | ||||
59 | foreach my $grab ( @{ $captures } ) { | ||||
60 | $name{$grab->name()}++; | ||||
61 | } | ||||
62 | return ( sort keys %name ); | ||||
63 | } | ||||
64 | |||||
65 | =head2 max_capture_number | ||||
66 | |||||
67 | print "Highest used capture number ", | ||||
68 | $re->max_capture_number(), "\n"; | ||||
69 | |||||
70 | This method returns the highest capture number used by the regular | ||||
71 | expression. If there are no captures, the return will be 0. | ||||
72 | |||||
73 | =cut | ||||
74 | |||||
75 | sub max_capture_number { | ||||
76 | my ( $self ) = @_; | ||||
77 | return $self->{max_capture_number}; | ||||
78 | } | ||||
79 | |||||
80 | # Called by the lexer once it has done its worst to all the tokens. | ||||
81 | # Called as a method with no arguments. The return is the number of | ||||
82 | # parse failures discovered when finalizing. | ||||
83 | sub __PPIX_LEXER__finalize { | ||||
84 | my ( $self ) = @_; | ||||
85 | my $rslt = 0; | ||||
86 | foreach my $elem ( $self->elements() ) { | ||||
87 | $rslt += $elem->__PPIX_LEXER__finalize(); | ||||
88 | } | ||||
89 | |||||
90 | # Calculate the maximum capture group, and number all the other | ||||
91 | # capture groups along the way. | ||||
92 | $self->{max_capture_number} = | ||||
93 | $self->__PPIX_LEXER__record_capture_number( 1 ) - 1; | ||||
94 | |||||
95 | return $rslt; | ||||
96 | } | ||||
97 | |||||
98 | 1 | 2µs | 1; | ||
99 | |||||
100 | __END__ |