← 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/Token/Reference.pm
StatementsExecuted 12 statements in 519µs
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
11114µs26µsPPIx::Regexp::Token::Reference::::BEGIN@37PPIx::Regexp::Token::Reference::BEGIN@37
11111µs40µsPPIx::Regexp::Token::Reference::::BEGIN@43PPIx::Regexp::Token::Reference::BEGIN@43
1117µs30µsPPIx::Regexp::Token::Reference::::BEGIN@42PPIx::Regexp::Token::Reference::BEGIN@42
1117µs12µsPPIx::Regexp::Token::Reference::::BEGIN@38PPIx::Regexp::Token::Reference::BEGIN@38
1117µs56µsPPIx::Regexp::Token::Reference::::BEGIN@40PPIx::Regexp::Token::Reference::BEGIN@40
0000s0sPPIx::Regexp::Token::Reference::::__ANON__[:144]PPIx::Regexp::Token::Reference::__ANON__[:144]
0000s0sPPIx::Regexp::Token::Reference::::__PPIX_LEXER__record_capture_numberPPIx::Regexp::Token::Reference::__PPIX_LEXER__record_capture_number
0000s0sPPIx::Regexp::Token::Reference::::__PPIX_TOKEN__post_makePPIx::Regexp::Token::Reference::__PPIX_TOKEN__post_make
0000s0sPPIx::Regexp::Token::Reference::::absolutePPIx::Regexp::Token::Reference::absolute
0000s0sPPIx::Regexp::Token::Reference::::is_namedPPIx::Regexp::Token::Reference::is_named
0000s0sPPIx::Regexp::Token::Reference::::is_relativePPIx::Regexp::Token::Reference::is_relative
0000s0sPPIx::Regexp::Token::Reference::::namePPIx::Regexp::Token::Reference::name
0000s0sPPIx::Regexp::Token::Reference::::numberPPIx::Regexp::Token::Reference::number
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::Reference - Represent a reference to a capture
4
5=head1 SYNOPSIS
6
7 use PPIx::Regexp::Dumper;
8 PPIx::Regexp::Dumper->new( 'qr{\1}smx' )
9 ->print();
10
11=head1 INHERITANCE
12
13C<PPIx::Regexp::Token::Reference> is a
14L<PPIx::Regexp::Token|PPIx::Regexp::Token>.
15
16C<PPIx::Regexp::Token::Reference> is the parent of
17L<PPIx::Regexp::Token::Backreference|PPIx::Regexp::Token::Backreference>,
18L<PPIx::Regexp::Token::Condition|PPIx::Regexp::Token::Condition> and
19L<PPIx::Regexp::Token::Recursion|PPIx::Regexp::Token::Recursion>.
20
21=head1 DESCRIPTION
22
23This abstract class represents a reference to a capture buffer, either
24numbered or named. It should never be instantiated, but it provides a
25number of methods to its subclasses.
26
27=head1 METHODS
28
29This class provides the following public methods. Methods not documented
30here are private, and unsupported in the sense that the author reserves
31the right to change or remove them without notice.
32
33=cut
34
35package PPIx::Regexp::Token::Reference;
36
37223µs238µs
# spent 26µs (14+12) within PPIx::Regexp::Token::Reference::BEGIN@37 which was called: # once (14µs+12µs) by base::import at line 37
use strict;
# spent 26µs making 1 call to PPIx::Regexp::Token::Reference::BEGIN@37 # spent 12µs making 1 call to strict::import
38220µs216µs
# spent 12µs (7+4) within PPIx::Regexp::Token::Reference::BEGIN@38 which was called: # once (7µs+4µs) by base::import at line 38
use warnings;
# spent 12µs making 1 call to PPIx::Regexp::Token::Reference::BEGIN@38 # spent 4µs making 1 call to warnings::import
39
40226µs256µs
# spent 56µs (7+49) within PPIx::Regexp::Token::Reference::BEGIN@40 which was called: # once (7µs+49µs) by base::import at line 40
use base qw{ PPIx::Regexp::Token };
# spent 56µs making 1 call to PPIx::Regexp::Token::Reference::BEGIN@40 # spent 49µs making 1 call to base::import, recursion: max depth 1, sum of overlapping time 49µs
41
42221µs252µs
# spent 30µs (7+23) within PPIx::Regexp::Token::Reference::BEGIN@42 which was called: # once (7µs+23µs) by base::import at line 42
use Carp qw{ confess };
# spent 30µs making 1 call to PPIx::Regexp::Token::Reference::BEGIN@42 # spent 23µs making 1 call to Exporter::import
432426µs247µs
# spent 40µs (11+28) within PPIx::Regexp::Token::Reference::BEGIN@43 which was called: # once (11µs+28µs) by base::import at line 43
use List::Util qw{ first };
# spent 40µs making 1 call to PPIx::Regexp::Token::Reference::BEGIN@43 # spent 7µs making 1 call to List::Util::import
44
451600nsour $VERSION = '0.036';
46
47=head2 absolute
48
49 print "The absolute reference is ", $ref->absolute(), "\n";
50
51This method returns the absolute number of the capture buffer referred
52to. This is the same as number() for unsigned numeric references. If the
53reference is to a named buffer, C<undef> is returned.
54
55=cut
56
57sub absolute {
58 my ( $self ) = @_;
59 return $self->{absolute};
60}
61
62=head2 is_named
63
64 $ref->is_named and print "named reference\n";
65
66This method returns true if the reference is named rather than numbered.
67
68=cut
69
70sub is_named {
71 my ( $self ) = @_;
72 return $self->{is_named};
73}
74
75=head2 is_relative
76
77 $ref->is_relative()
78 and print "relative numbered reference\n";
79
80This method returns true if the reference is numbered and it is a
81relative number (i.e. if it is signed).
82
83=cut
84
85sub is_relative {
86 my ( $self ) = @_;
87 return $self->{is_relative};
88}
89
90=head2 name
91
92 print "The name is ", $ref->name(), "\n";
93
94This method returns the name of the capture buffer referred to. In the
95case of a reference to a numbered capture (i.e. C<is_named> returns
96false), this method returns C<undef>.
97
98=cut
99
100sub name {
101 my ( $self ) = @_;
102 return $self->{name};
103}
104
105=head2 number
106
107 print "The number is ", $ref->number(), "\n";
108
109This method returns the number of the capture buffer referred to. In the
110case of a reference to a named capture (i.e. C<is_named> returns true),
111this method returns C<undef>.
112
113=cut
114
115sub number {
116 my ( $self ) = @_;
117 return $self->{number};
118}
119
120# Called by the lexer to record the capture number.
121sub __PPIX_LEXER__record_capture_number {
122 my ( $self, $number ) = @_;
123 if ( ! exists $self->{absolute} && exists $self->{number}
124 && $self->{number} =~ m/ \A [-+] /smx ) {
125
126 my $delta = $self->{number};
127 $delta > 0 and --$delta; # no -0 or +0.
128 $self->{absolute} = $number + $delta;
129
130 }
131 return $number;
132}
133
134# Called after the token is manufactured. The calling sequence is
135# $token->__PPIX_TOKEN__post_make( $tokenizer, $arg );
136# For the sake of reblessing into this class, we are expected to deal
137# with the situation where the optional argument is missing.
138sub __PPIX_TOKEN__post_make {
139 my ( $self, $tokenizer, $arg ) = @_;
140
141 my $capture;
142 if ( defined $arg ) {
143 $tokenizer
144 and $capture = first { defined $_ } $tokenizer->capture();
145 defined $capture or $capture = $arg->{capture};
146 } else {
147 my $content = $self->content();
148 foreach ( $self->__PPIX_TOKEN__recognize() ) {
149 my ( $re, $a ) = @{ $_ };
150 $content =~ $re or next;
151 $arg = $a;
152 if ( exists $arg->{capture} ) {
153 $capture = $arg->{capture};
154 } else {
155 foreach my $inx ( 1 .. $#- ) {
156 defined $-[$inx] or next;
157 $capture = substr $content, $-[$inx], $+[$inx] - $-[$inx];
158 last;
159 }
160 }
161 last;
162 }
163 }
164
165 defined $capture
166 or confess q{Programming error - reference '},
167 $self->content(), q{' of unknown form};
168
169 foreach my $key ( keys %{ $arg } ) {
170 $key eq 'capture' and next;
171 $self->{$key} = $arg->{$key};
172 }
173
174 if ( $arg->{is_named} ) {
175 $self->{absolute} = undef;
176 $self->{is_relative} = undef;
177 $self->{name} = $capture;
178 } elsif ( $capture !~ m/ \A [-+] /smx ) {
179 $self->{absolute} = $self->{number} = $capture;
180 $self->{is_relative} = undef;
181 } else {
182 $self->{number} = $capture;
183 $self->{is_relative} = 1;
184 }
185
186 return;
187};
188
189
19012µs1;
191
192__END__