| Filename | /Users/timbo/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/PPIx/Regexp/Token/Reference.pm |
| Statements | Executed 12 statements in 519µs |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 1 | 1 | 1 | 14µs | 26µs | PPIx::Regexp::Token::Reference::BEGIN@37 |
| 1 | 1 | 1 | 11µs | 40µs | PPIx::Regexp::Token::Reference::BEGIN@43 |
| 1 | 1 | 1 | 7µs | 30µs | PPIx::Regexp::Token::Reference::BEGIN@42 |
| 1 | 1 | 1 | 7µs | 12µs | PPIx::Regexp::Token::Reference::BEGIN@38 |
| 1 | 1 | 1 | 7µs | 56µs | PPIx::Regexp::Token::Reference::BEGIN@40 |
| 0 | 0 | 0 | 0s | 0s | PPIx::Regexp::Token::Reference::__ANON__[:144] |
| 0 | 0 | 0 | 0s | 0s | PPIx::Regexp::Token::Reference::__PPIX_LEXER__record_capture_number |
| 0 | 0 | 0 | 0s | 0s | PPIx::Regexp::Token::Reference::__PPIX_TOKEN__post_make |
| 0 | 0 | 0 | 0s | 0s | PPIx::Regexp::Token::Reference::absolute |
| 0 | 0 | 0 | 0s | 0s | PPIx::Regexp::Token::Reference::is_named |
| 0 | 0 | 0 | 0s | 0s | PPIx::Regexp::Token::Reference::is_relative |
| 0 | 0 | 0 | 0s | 0s | PPIx::Regexp::Token::Reference::name |
| 0 | 0 | 0 | 0s | 0s | PPIx::Regexp::Token::Reference::number |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | =head1 NAME | ||||
| 2 | |||||
| 3 | PPIx::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 | |||||
| 13 | C<PPIx::Regexp::Token::Reference> is a | ||||
| 14 | L<PPIx::Regexp::Token|PPIx::Regexp::Token>. | ||||
| 15 | |||||
| 16 | C<PPIx::Regexp::Token::Reference> is the parent of | ||||
| 17 | L<PPIx::Regexp::Token::Backreference|PPIx::Regexp::Token::Backreference>, | ||||
| 18 | L<PPIx::Regexp::Token::Condition|PPIx::Regexp::Token::Condition> and | ||||
| 19 | L<PPIx::Regexp::Token::Recursion|PPIx::Regexp::Token::Recursion>. | ||||
| 20 | |||||
| 21 | =head1 DESCRIPTION | ||||
| 22 | |||||
| 23 | This abstract class represents a reference to a capture buffer, either | ||||
| 24 | numbered or named. It should never be instantiated, but it provides a | ||||
| 25 | number of methods to its subclasses. | ||||
| 26 | |||||
| 27 | =head1 METHODS | ||||
| 28 | |||||
| 29 | This class provides the following public methods. Methods not documented | ||||
| 30 | here are private, and unsupported in the sense that the author reserves | ||||
| 31 | the right to change or remove them without notice. | ||||
| 32 | |||||
| 33 | =cut | ||||
| 34 | |||||
| 35 | package PPIx::Regexp::Token::Reference; | ||||
| 36 | |||||
| 37 | 2 | 23µs | 2 | 38µ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 # spent 26µs making 1 call to PPIx::Regexp::Token::Reference::BEGIN@37
# spent 12µs making 1 call to strict::import |
| 38 | 2 | 20µs | 2 | 16µ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 # spent 12µs making 1 call to PPIx::Regexp::Token::Reference::BEGIN@38
# spent 4µs making 1 call to warnings::import |
| 39 | |||||
| 40 | 2 | 26µs | 2 | 56µ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 # 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 | |||||
| 42 | 2 | 21µs | 2 | 52µ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 # spent 30µs making 1 call to PPIx::Regexp::Token::Reference::BEGIN@42
# spent 23µs making 1 call to Exporter::import |
| 43 | 2 | 426µs | 2 | 47µ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 # spent 40µs making 1 call to PPIx::Regexp::Token::Reference::BEGIN@43
# spent 7µs making 1 call to List::Util::import |
| 44 | |||||
| 45 | 1 | 600ns | our $VERSION = '0.036'; | ||
| 46 | |||||
| 47 | =head2 absolute | ||||
| 48 | |||||
| 49 | print "The absolute reference is ", $ref->absolute(), "\n"; | ||||
| 50 | |||||
| 51 | This method returns the absolute number of the capture buffer referred | ||||
| 52 | to. This is the same as number() for unsigned numeric references. If the | ||||
| 53 | reference is to a named buffer, C<undef> is returned. | ||||
| 54 | |||||
| 55 | =cut | ||||
| 56 | |||||
| 57 | sub 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 | |||||
| 66 | This method returns true if the reference is named rather than numbered. | ||||
| 67 | |||||
| 68 | =cut | ||||
| 69 | |||||
| 70 | sub 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 | |||||
| 80 | This method returns true if the reference is numbered and it is a | ||||
| 81 | relative number (i.e. if it is signed). | ||||
| 82 | |||||
| 83 | =cut | ||||
| 84 | |||||
| 85 | sub 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 | |||||
| 94 | This method returns the name of the capture buffer referred to. In the | ||||
| 95 | case of a reference to a numbered capture (i.e. C<is_named> returns | ||||
| 96 | false), this method returns C<undef>. | ||||
| 97 | |||||
| 98 | =cut | ||||
| 99 | |||||
| 100 | sub name { | ||||
| 101 | my ( $self ) = @_; | ||||
| 102 | return $self->{name}; | ||||
| 103 | } | ||||
| 104 | |||||
| 105 | =head2 number | ||||
| 106 | |||||
| 107 | print "The number is ", $ref->number(), "\n"; | ||||
| 108 | |||||
| 109 | This method returns the number of the capture buffer referred to. In the | ||||
| 110 | case of a reference to a named capture (i.e. C<is_named> returns true), | ||||
| 111 | this method returns C<undef>. | ||||
| 112 | |||||
| 113 | =cut | ||||
| 114 | |||||
| 115 | sub number { | ||||
| 116 | my ( $self ) = @_; | ||||
| 117 | return $self->{number}; | ||||
| 118 | } | ||||
| 119 | |||||
| 120 | # Called by the lexer to record the capture number. | ||||
| 121 | sub __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. | ||||
| 138 | sub __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 | |||||
| 190 | 1 | 2µs | 1; | ||
| 191 | |||||
| 192 | __END__ |