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

Filename/Users/timbo/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/PPIx/Regexp/Structure/Switch.pm
StatementsExecuted 8 statements in 229µs
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
11112µs23µsPPIx::Regexp::Structure::Switch::::BEGIN@32PPIx::Regexp::Structure::Switch::BEGIN@32
1117µs11µsPPIx::Regexp::Structure::Switch::::BEGIN@33PPIx::Regexp::Structure::Switch::BEGIN@33
1117µs69µsPPIx::Regexp::Structure::Switch::::BEGIN@35PPIx::Regexp::Structure::Switch::BEGIN@35
0000s0sPPIx::Regexp::Structure::Switch::::__PPIX_LEXER__finalizePPIx::Regexp::Structure::Switch::__PPIX_LEXER__finalize
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::Structure::Switch - Represent a switch
4
5=head1 SYNOPSIS
6
7 use PPIx::Regexp::Dumper;
8 PPIx::Regexp::Dumper->new( 'qr{(?(1)foo|bar)}smx' )
9 ->print();
10
11=head1 INHERITANCE
12
13C<PPIx::Regexp::Structure::Switch> is a
14L<PPIx::Regexp::Structure|PPIx::Regexp::Structure>.
15
16C<PPIx::Regexp::Structure::Switch> has no descendants.
17
18=head1 DESCRIPTION
19
20This class represents a switch, or conditional expression. The condition
21will be the first child.
22
23=head1 METHODS
24
25This class provides no public methods beyond those provided by its
26superclass.
27
28=cut
29
30package PPIx::Regexp::Structure::Switch;
31
32219µs234µs
# spent 23µs (12+12) within PPIx::Regexp::Structure::Switch::BEGIN@32 which was called: # once (12µs+12µs) by PPIx::Regexp::Lexer::BEGIN@58 at line 32
use strict;
# spent 23µs making 1 call to PPIx::Regexp::Structure::Switch::BEGIN@32 # spent 12µs making 1 call to strict::import
33228µs215µs
# spent 11µs (7+4) within PPIx::Regexp::Structure::Switch::BEGIN@33 which was called: # once (7µs+4µs) by PPIx::Regexp::Lexer::BEGIN@58 at line 33
use warnings;
# spent 11µs making 1 call to PPIx::Regexp::Structure::Switch::BEGIN@33 # spent 4µs making 1 call to warnings::import
34
352179µs2131µs
# spent 69µs (7+62) within PPIx::Regexp::Structure::Switch::BEGIN@35 which was called: # once (7µs+62µs) by PPIx::Regexp::Lexer::BEGIN@58 at line 35
use base qw{ PPIx::Regexp::Structure };
# spent 69µs making 1 call to PPIx::Regexp::Structure::Switch::BEGIN@35 # spent 62µs making 1 call to base::import
36
371600nsour $VERSION = '0.036';
38
39sub __PPIX_LEXER__finalize {
40 my ( $self ) = @_;
41
42 # Assume no errors.
43 my $rslt = 0;
44
45 # Number of allowed alternations not known yet.
46 my $alternations;
47
48 # If we are a valid switch, the first child is the condition. Make
49 # sure we have a first child and that it is of the expected class.
50 # If it is, determine how many alternations are allowed.
51 if ( my $condition = $self->child( 0 ) ) {
52 foreach my $class ( qw{
53 PPIx::Regexp::Structure::Assertion
54 PPIx::Regexp::Structure::Code
55 PPIx::Regexp::Token::Condition
56 } ) {
57 $condition->isa( $class ) or next;
58 $alternations = $condition->content() eq '(DEFINE)' ? 0 : 1;
59 last;
60 }
61 }
62
63 if ( defined $alternations ) {
64 # If we figured out how many alternations were allowed, count
65 # them, changing surplus ones to the unknown token.
66 foreach my $kid ( $self->children () ) {
67 $kid->isa( 'PPIx::Regexp::Token::Operator' ) or next;
68 $kid->content() eq '|' or next;
69 --$alternations >= 0 and next;
70 $kid->__error( 'Too many alternatives for switch' );
71 $rslt++;
72 }
73 } else {
74 # If we could not figure out how many alternations were allowed,
75 # it means we did not understand our condition. Rebless
76 # ourselves to the unknown structure and count a parse failure.
77 $self->__error( 'Switch condition not understood' );
78 $rslt++;
79 }
80
81 # Delegate to the superclass to finalize our children, now that we
82 # have finished messing with them.
83 $rslt = $self->SUPER::__PPIX_LEXER__finalize();
84
85 return $rslt;
86}
87
8812µs1;
89
90__END__