| Filename | /Users/timbo/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/PPIx/Regexp/Token/Code.pm |
| Statements | Executed 16 statements in 396µs |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 1 | 1 | 1 | 14µs | 26µs | PPIx::Regexp::Token::Code::BEGIN@44 |
| 1 | 1 | 1 | 8µs | 12µs | PPIx::Regexp::Token::Code::BEGIN@45 |
| 1 | 1 | 1 | 7µs | 56µs | PPIx::Regexp::Token::Code::BEGIN@47 |
| 1 | 1 | 1 | 6µs | 25µs | PPIx::Regexp::Token::Code::BEGIN@51 |
| 1 | 1 | 1 | 6µs | 26µs | PPIx::Regexp::Token::Code::BEGIN@50 |
| 1 | 1 | 1 | 4µs | 4µs | PPIx::Regexp::Token::Code::BEGIN@49 |
| 0 | 0 | 0 | 0s | 0s | PPIx::Regexp::Token::Code::__PPIX_TOKENIZER__regexp |
| 0 | 0 | 0 | 0s | 0s | PPIx::Regexp::Token::Code::__PPIX_TOKEN__post_make |
| 0 | 0 | 0 | 0s | 0s | PPIx::Regexp::Token::Code::_new |
| 0 | 0 | 0 | 0s | 0s | PPIx::Regexp::Token::Code::content |
| 0 | 0 | 0 | 0s | 0s | PPIx::Regexp::Token::Code::perl_version_introduced |
| 0 | 0 | 0 | 0s | 0s | PPIx::Regexp::Token::Code::ppi |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | =head1 NAME | ||||
| 2 | |||||
| 3 | PPIx::Regexp::Token::Code - Represent a chunk of Perl embedded in a regular expression. | ||||
| 4 | |||||
| 5 | =head1 SYNOPSIS | ||||
| 6 | |||||
| 7 | use PPIx::Regexp::Dumper; | ||||
| 8 | PPIx::Regexp::Dumper->new( | ||||
| 9 | 'qr{(?{print "hello sailor\n"})}smx')->print; | ||||
| 10 | |||||
| 11 | =head1 INHERITANCE | ||||
| 12 | |||||
| 13 | C<PPIx::Regexp::Token::Code> is a | ||||
| 14 | L<PPIx::Regexp::Token|PPIx::Regexp::Token>. | ||||
| 15 | |||||
| 16 | C<PPIx::Regexp::Token::Code> is the parent of | ||||
| 17 | L<PPIx::Regexp::Token::Interpolation|PPIx::Regexp::Token::Interpolation>. | ||||
| 18 | |||||
| 19 | =head1 DESCRIPTION | ||||
| 20 | |||||
| 21 | This class represents a chunk of Perl code embedded in a regular | ||||
| 22 | expression. Specifically, it results from parsing things like | ||||
| 23 | |||||
| 24 | (?{ code }) | ||||
| 25 | (??{ code }) | ||||
| 26 | |||||
| 27 | or from the replacement side of an s///e. Technically, interpolations | ||||
| 28 | are also code, but they parse differently and therefore end up in a | ||||
| 29 | different token. | ||||
| 30 | |||||
| 31 | This token may not appear inside a regex set (i.e. C<(?[ ... ])>. If | ||||
| 32 | found, it will become a C<PPIx::Regexp::Token::Unknown>. | ||||
| 33 | |||||
| 34 | =head1 METHODS | ||||
| 35 | |||||
| 36 | This class provides the following public methods. Methods not documented | ||||
| 37 | here are private, and unsupported in the sense that the author reserves | ||||
| 38 | the right to change or remove them without notice. | ||||
| 39 | |||||
| 40 | =cut | ||||
| 41 | |||||
| 42 | package PPIx::Regexp::Token::Code; | ||||
| 43 | |||||
| 44 | 2 | 20µs | 2 | 39µs | # spent 26µs (14+12) within PPIx::Regexp::Token::Code::BEGIN@44 which was called:
# once (14µs+12µs) by PPIx::Regexp::Tokenizer::BEGIN@20 at line 44 # spent 26µs making 1 call to PPIx::Regexp::Token::Code::BEGIN@44
# spent 12µs making 1 call to strict::import |
| 45 | 2 | 21µs | 2 | 17µs | # spent 12µs (8+5) within PPIx::Regexp::Token::Code::BEGIN@45 which was called:
# once (8µs+5µs) by PPIx::Regexp::Tokenizer::BEGIN@20 at line 45 # spent 12µs making 1 call to PPIx::Regexp::Token::Code::BEGIN@45
# spent 5µs making 1 call to warnings::import |
| 46 | |||||
| 47 | 2 | 20µs | 2 | 104µs | # spent 56µs (7+49) within PPIx::Regexp::Token::Code::BEGIN@47 which was called:
# once (7µs+49µs) by PPIx::Regexp::Tokenizer::BEGIN@20 at line 47 # spent 56µs making 1 call to PPIx::Regexp::Token::Code::BEGIN@47
# spent 49µs making 1 call to base::import |
| 48 | |||||
| 49 | 2 | 19µs | 1 | 4µs | # spent 4µs within PPIx::Regexp::Token::Code::BEGIN@49 which was called:
# once (4µs+0s) by PPIx::Regexp::Tokenizer::BEGIN@20 at line 49 # spent 4µs making 1 call to PPIx::Regexp::Token::Code::BEGIN@49 |
| 50 | 2 | 24µs | 2 | 45µs | # spent 26µs (6+19) within PPIx::Regexp::Token::Code::BEGIN@50 which was called:
# once (6µs+19µs) by PPIx::Regexp::Tokenizer::BEGIN@20 at line 50 # spent 26µs making 1 call to PPIx::Regexp::Token::Code::BEGIN@50
# spent 19µs making 1 call to Exporter::import |
| 51 | 2 | 287µs | 2 | 44µs | # spent 25µs (6+19) within PPIx::Regexp::Token::Code::BEGIN@51 which was called:
# once (6µs+19µs) by PPIx::Regexp::Tokenizer::BEGIN@20 at line 51 # spent 25µs making 1 call to PPIx::Regexp::Token::Code::BEGIN@51
# spent 19µs making 1 call to Exporter::import |
| 52 | |||||
| 53 | 1 | 600ns | our $VERSION = '0.036'; | ||
| 54 | |||||
| 55 | sub _new { | ||||
| 56 | my ( $class, $content ) = @_; | ||||
| 57 | ref $class and $class = ref $class; | ||||
| 58 | |||||
| 59 | my $self = {}; | ||||
| 60 | if ( __instance( $content, 'PPI::Document' ) ) { | ||||
| 61 | $self->{ppi} = $content; | ||||
| 62 | } elsif ( ref $content ) { | ||||
| 63 | return; | ||||
| 64 | } else { | ||||
| 65 | $self->{content} = $content; | ||||
| 66 | } | ||||
| 67 | bless $self, $class; | ||||
| 68 | return $self; | ||||
| 69 | } | ||||
| 70 | |||||
| 71 | sub content { | ||||
| 72 | my ( $self ) = @_; | ||||
| 73 | if ( exists $self->{content} ) { | ||||
| 74 | return $self->{content}; | ||||
| 75 | } elsif ( exists $self->{ppi} ) { | ||||
| 76 | return ( $self->{content} = $self->{ppi}->content() ); | ||||
| 77 | } else { | ||||
| 78 | return; | ||||
| 79 | } | ||||
| 80 | } | ||||
| 81 | |||||
| 82 | sub perl_version_introduced { | ||||
| 83 | my ( $self ) = @_; | ||||
| 84 | return $self->{perl_version_introduced}; | ||||
| 85 | } | ||||
| 86 | |||||
| 87 | =head2 ppi | ||||
| 88 | |||||
| 89 | This convenience method returns the L<PPI::Document|PPI::Document> | ||||
| 90 | representing the content. This document should be considered read only. | ||||
| 91 | |||||
| 92 | =cut | ||||
| 93 | |||||
| 94 | sub ppi { | ||||
| 95 | my ( $self ) = @_; | ||||
| 96 | if ( exists $self->{ppi} ) { | ||||
| 97 | return $self->{ppi}; | ||||
| 98 | } elsif ( exists $self->{content} ) { | ||||
| 99 | return ( $self->{ppi} = PPI::Document->new( | ||||
| 100 | \($self->{content}), readonly => 1 ) ); | ||||
| 101 | } else { | ||||
| 102 | return; | ||||
| 103 | } | ||||
| 104 | } | ||||
| 105 | |||||
| 106 | # Return true if the token can be quantified, and false otherwise | ||||
| 107 | # sub can_be_quantified { return }; | ||||
| 108 | |||||
| 109 | { | ||||
| 110 | |||||
| 111 | 2 | 2µs | my %default = ( | ||
| 112 | perl_version_introduced => '5.005', # When (?{...}) introduced. | ||||
| 113 | ); | ||||
| 114 | |||||
| 115 | sub __PPIX_TOKEN__post_make { | ||||
| 116 | my ( $self, $tokenizer, $arg ) = @_; | ||||
| 117 | |||||
| 118 | $self->__impose_defaults( $arg, \%default ); | ||||
| 119 | |||||
| 120 | # If we're manufacturing objects directly (which is UNSUPPORTED, | ||||
| 121 | # but used in t/version.t) we may not have a $tokenizer. | ||||
| 122 | $tokenizer | ||||
| 123 | and $tokenizer->cookie( COOKIE_REGEX_SET ) | ||||
| 124 | and $self->__error( 'Code token not valid in Regex set' ); | ||||
| 125 | |||||
| 126 | return; | ||||
| 127 | } | ||||
| 128 | |||||
| 129 | } | ||||
| 130 | |||||
| 131 | sub __PPIX_TOKENIZER__regexp { | ||||
| 132 | my ( $class, $tokenizer, $character ) = @_; | ||||
| 133 | |||||
| 134 | $character eq '{' or return; | ||||
| 135 | |||||
| 136 | my $offset = $tokenizer->find_matching_delimiter() | ||||
| 137 | or return; | ||||
| 138 | |||||
| 139 | return $offset + 1; # to include the closing delimiter. | ||||
| 140 | } | ||||
| 141 | |||||
| 142 | 1 | 3µs | 1; | ||
| 143 | |||||
| 144 | __END__ |