| Filename | /Users/timbo/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/PPIx/Regexp/Token/Assertion.pm |
| Statements | Executed 14 statements in 264µs |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 1 | 1 | 1 | 12µs | 23µs | PPIx::Regexp::Token::Assertion::BEGIN@34 |
| 1 | 1 | 1 | 7µs | 33µs | PPIx::Regexp::Token::Assertion::BEGIN@39 |
| 1 | 1 | 1 | 6µs | 11µs | PPIx::Regexp::Token::Assertion::BEGIN@35 |
| 1 | 1 | 1 | 6µs | 67µs | PPIx::Regexp::Token::Assertion::BEGIN@37 |
| 0 | 0 | 0 | 0s | 0s | PPIx::Regexp::Token::Assertion::__PPIX_TOKENIZER__regexp |
| 0 | 0 | 0 | 0s | 0s | PPIx::Regexp::Token::Assertion::perl_version_introduced |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | =head1 NAME | ||||
| 2 | |||||
| 3 | PPIx::Regexp::Token::Assertion - Represent a simple assertion. | ||||
| 4 | |||||
| 5 | =head1 SYNOPSIS | ||||
| 6 | |||||
| 7 | use PPIx::Regexp::Dumper; | ||||
| 8 | PPIx::Regexp::Dumper->new( 'qr{\bfoo\b}smx' ) | ||||
| 9 | ->print(); | ||||
| 10 | |||||
| 11 | =head1 INHERITANCE | ||||
| 12 | |||||
| 13 | C<PPIx::Regexp::Token::Assertion> is a | ||||
| 14 | L<PPIx::Regexp::Token|PPIx::Regexp::Token>. | ||||
| 15 | |||||
| 16 | C<PPIx::Regexp::Token::Assertion> has no descendants. | ||||
| 17 | |||||
| 18 | =head1 DESCRIPTION | ||||
| 19 | |||||
| 20 | This class represents one of the simple assertions; that is, those that | ||||
| 21 | are not defined via parentheses. This includes the zero-width assertions | ||||
| 22 | C<^>, C<$>, C<\b>, C<\B>, C<\A>, C<\Z>, C<\z> and C<\G>, as well as the | ||||
| 23 | positive look-behind assertion C<\K> added in Perl 5.009005. | ||||
| 24 | |||||
| 25 | =head1 METHODS | ||||
| 26 | |||||
| 27 | This class provides no public methods beyond those provided by its | ||||
| 28 | superclass. | ||||
| 29 | |||||
| 30 | =cut | ||||
| 31 | |||||
| 32 | package PPIx::Regexp::Token::Assertion; | ||||
| 33 | |||||
| 34 | 2 | 19µs | 2 | 35µs | # spent 23µs (12+12) within PPIx::Regexp::Token::Assertion::BEGIN@34 which was called:
# once (12µs+12µs) by PPIx::Regexp::Tokenizer::BEGIN@14 at line 34 # spent 23µs making 1 call to PPIx::Regexp::Token::Assertion::BEGIN@34
# spent 12µs making 1 call to strict::import |
| 35 | 2 | 24µs | 2 | 15µs | # spent 11µs (6+4) within PPIx::Regexp::Token::Assertion::BEGIN@35 which was called:
# once (6µs+4µs) by PPIx::Regexp::Tokenizer::BEGIN@14 at line 35 # spent 11µs making 1 call to PPIx::Regexp::Token::Assertion::BEGIN@35
# spent 4µs making 1 call to warnings::import |
| 36 | |||||
| 37 | 2 | 26µs | 2 | 128µs | # spent 67µs (6+61) within PPIx::Regexp::Token::Assertion::BEGIN@37 which was called:
# once (6µs+61µs) by PPIx::Regexp::Tokenizer::BEGIN@14 at line 37 # spent 67µs making 1 call to PPIx::Regexp::Token::Assertion::BEGIN@37
# spent 61µs making 1 call to base::import |
| 38 | |||||
| 39 | 2 | 180µs | 2 | 59µs | # spent 33µs (7+26) within PPIx::Regexp::Token::Assertion::BEGIN@39 which was called:
# once (7µs+26µs) by PPIx::Regexp::Tokenizer::BEGIN@14 at line 39 # spent 33µs making 1 call to PPIx::Regexp::Token::Assertion::BEGIN@39
# spent 26µs making 1 call to Exporter::import |
| 40 | |||||
| 41 | 1 | 600ns | our $VERSION = '0.036'; | ||
| 42 | |||||
| 43 | # Return true if the token can be quantified, and false otherwise | ||||
| 44 | # sub can_be_quantified { return }; | ||||
| 45 | |||||
| 46 | { | ||||
| 47 | |||||
| 48 | 2 | 2µs | my %perl_version_introduced = ( | ||
| 49 | '\\K' => '5.009005', | ||||
| 50 | '\\z' => '5.005', | ||||
| 51 | ); | ||||
| 52 | |||||
| 53 | sub perl_version_introduced { | ||||
| 54 | my ( $self ) = @_; | ||||
| 55 | return $perl_version_introduced{$self->content()} || MINIMUM_PERL; | ||||
| 56 | } | ||||
| 57 | |||||
| 58 | } | ||||
| 59 | |||||
| 60 | # By logic we should handle '$' here. But | ||||
| 61 | # PPIx::Regexp::Token::Interpolation needs to process it to see if it is | ||||
| 62 | # a sigil. If it is not, that module is expected to make it into an | ||||
| 63 | # assertion. This is to try to keep the order in which the tokenizers | ||||
| 64 | # are called non-critical, and try to keep all processing for a | ||||
| 65 | # character in one place. Except for the back slash, which gets in | ||||
| 66 | # everywhere. | ||||
| 67 | # | ||||
| 68 | ## my %assertion = map { $_ => 1 } qw{ ^ $ }; | ||||
| 69 | 1 | 2µs | my %assertion = map { $_ => 1 } qw{ ^ }; | ||
| 70 | 1 | 5µs | my %escaped = map { $_ => 1 } qw{ b B A Z z G K }; | ||
| 71 | |||||
| 72 | sub __PPIX_TOKENIZER__regexp { | ||||
| 73 | my ( $class, $tokenizer, $character ) = @_; | ||||
| 74 | |||||
| 75 | # Inside a character class, these are all literals. | ||||
| 76 | my $make = $tokenizer->cookie( COOKIE_CLASS ) ? | ||||
| 77 | TOKEN_LITERAL : | ||||
| 78 | __PACKAGE__; | ||||
| 79 | |||||
| 80 | # '^' and '$'. Or at least '^'. See note above for '$'. | ||||
| 81 | $assertion{$character} | ||||
| 82 | and return $tokenizer->make_token( 1, $make ); | ||||
| 83 | |||||
| 84 | $character eq '\\' or return; | ||||
| 85 | |||||
| 86 | defined ( my $next = $tokenizer->peek( 1 ) ) or return; | ||||
| 87 | |||||
| 88 | $escaped{$next} | ||||
| 89 | and return $tokenizer->make_token( 2, $make ); | ||||
| 90 | |||||
| 91 | return; | ||||
| 92 | } | ||||
| 93 | |||||
| 94 | 1 | 5µs | 1; | ||
| 95 | |||||
| 96 | __END__ |